Skip to content

Commit

Permalink
Merge pull request #184 from DIG-Network/release/v0.0.1-alpha.195
Browse files Browse the repository at this point in the history
Release/v0.0.1 alpha.195
  • Loading branch information
MichaelTaylor3D authored Nov 16, 2024
2 parents 24543ff + b297c18 commit 614bd46
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 24 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@

All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.

### [0.0.1-alpha.195](https://github.com/DIG-Network/dig-chia-sdk/compare/v0.0.1-alpha.194...v0.0.1-alpha.195) (2024-11-16)


### Bug Fixes

* use udi in content server class ([2afc04a](https://github.com/DIG-Network/dig-chia-sdk/commit/2afc04afce52d13cd69d80dc0d5e668ef10ea180))

### [0.0.1-alpha.194](https://github.com/DIG-Network/dig-chia-sdk/compare/v0.0.1-alpha.193...v0.0.1-alpha.194) (2024-11-16)


Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@dignetwork/dig-sdk",
"version": "0.0.1-alpha.194",
"version": "0.0.1-alpha.195",
"description": "",
"type": "commonjs",
"main": "./dist/index.js",
Expand Down
36 changes: 15 additions & 21 deletions src/DigNetwork/ContentServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { URL } from "url";
import { Readable } from "stream";
import { formatHost, getOrCreateSSLCerts } from "../utils";
import NodeCache from "node-cache";
import { Udi } from "../utils";

const hasRootHashCache = new NodeCache({ stdTTL: 86400 });
const wellKnownCache = new NodeCache({ stdTTL: 86400 });
Expand Down Expand Up @@ -32,10 +33,12 @@ export class ContentServer {
rootHash: string,
challengeHex?: string
): Promise<string> {
const udi = new Udi("chia", this.storeId, rootHash, key);

// Construct the base URL
let url = `https://${formatHost(this.ipAddress)}:${
ContentServer.port
}/chia.${this.storeId}.${rootHash}/${key}`;
}/${udi.toString()}`;

// If a challenge is provided, append it as a query parameter
if (challengeHex) {
Expand All @@ -47,10 +50,12 @@ export class ContentServer {

// New method to get only the first chunk of the content
public async getKeyChunk(key: string, rootHash: string): Promise<Buffer> {
const udi = new Udi("chia", this.storeId, rootHash, key);

// Construct the base URL
let url = `https://${formatHost(this.ipAddress)}:${
ContentServer.port
}/chia.${this.storeId}.${rootHash}/${key}`;
}/${udi.toString()}`;
return this.fetchFirstChunk(url);
}

Expand Down Expand Up @@ -119,15 +124,11 @@ export class ContentServer {
// Method to get the index of keys in a store
public async getKeysIndex(rootHash?: string): Promise<any> {
try {
let udi = `chia.${this.storeId}`;

if (rootHash) {
udi += `.${rootHash}`;
}
const udi = new Udi("chia", this.storeId, rootHash);

const url = `https://${formatHost(this.ipAddress)}:${
ContentServer.port
}/${udi}`;
}/${udi.toString()}`;
return this.fetchJson(url);
} catch (error: any) {
if (rootHash) {
Expand All @@ -143,15 +144,11 @@ export class ContentServer {
rootHash?: string
): Promise<{ success: boolean; headers?: http.IncomingHttpHeaders }> {
try {
let udi = `chia.${this.storeId}`;

if (rootHash) {
udi += `.${rootHash}`;
}
const udi = new Udi("chia", this.storeId, rootHash, key);

const url = `https://${formatHost(this.ipAddress)}:${
ContentServer.port
}/${udi}/${key}`;
}/${udi.toString()}`;
return this.head(url);
} catch (error: any) {
if (rootHash) {
Expand All @@ -166,10 +163,11 @@ export class ContentServer {
success: boolean;
headers?: http.IncomingHttpHeaders;
}> {
const udi = new Udi("chia", this.storeId);
try {
let url = `https://${formatHost(this.ipAddress)}:${
ContentServer.port
}/chia.${this.storeId}`;
}/${udi.toString()}`;

if (options?.hasRootHash) {
url += `?hasRootHash=${options.hasRootHash}`;
Expand Down Expand Up @@ -218,16 +216,12 @@ export class ContentServer {
}

public streamKey(key: string, rootHash?: string): Promise<Readable> {
let udi = `chia.${this.storeId}`;

if (rootHash) {
udi += `.${rootHash}`;
}
const udi = new Udi("chia", this.storeId, rootHash, key);

return new Promise((resolve, reject) => {
const url = `https://${formatHost(this.ipAddress)}:${
ContentServer.port
}/${udi}/${key}`;
}/${udi.toString()}`;
const urlObj = new URL(url);

const requestOptions = {
Expand Down

0 comments on commit 614bd46

Please sign in to comment.