Skip to content

Commit 614bd46

Browse files
Merge pull request #184 from DIG-Network/release/v0.0.1-alpha.195
Release/v0.0.1 alpha.195
2 parents 24543ff + b297c18 commit 614bd46

File tree

4 files changed

+25
-24
lines changed

4 files changed

+25
-24
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@
22

33
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.
44

5+
### [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)
6+
7+
8+
### Bug Fixes
9+
10+
* use udi in content server class ([2afc04a](https://github.com/DIG-Network/dig-chia-sdk/commit/2afc04afce52d13cd69d80dc0d5e668ef10ea180))
11+
512
### [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)
613

714

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@dignetwork/dig-sdk",
3-
"version": "0.0.1-alpha.194",
3+
"version": "0.0.1-alpha.195",
44
"description": "",
55
"type": "commonjs",
66
"main": "./dist/index.js",

src/DigNetwork/ContentServer.ts

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { URL } from "url";
44
import { Readable } from "stream";
55
import { formatHost, getOrCreateSSLCerts } from "../utils";
66
import NodeCache from "node-cache";
7+
import { Udi } from "../utils";
78

89
const hasRootHashCache = new NodeCache({ stdTTL: 86400 });
910
const wellKnownCache = new NodeCache({ stdTTL: 86400 });
@@ -32,10 +33,12 @@ export class ContentServer {
3233
rootHash: string,
3334
challengeHex?: string
3435
): Promise<string> {
36+
const udi = new Udi("chia", this.storeId, rootHash, key);
37+
3538
// Construct the base URL
3639
let url = `https://${formatHost(this.ipAddress)}:${
3740
ContentServer.port
38-
}/chia.${this.storeId}.${rootHash}/${key}`;
41+
}/${udi.toString()}`;
3942

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

4851
// New method to get only the first chunk of the content
4952
public async getKeyChunk(key: string, rootHash: string): Promise<Buffer> {
53+
const udi = new Udi("chia", this.storeId, rootHash, key);
54+
5055
// Construct the base URL
5156
let url = `https://${formatHost(this.ipAddress)}:${
5257
ContentServer.port
53-
}/chia.${this.storeId}.${rootHash}/${key}`;
58+
}/${udi.toString()}`;
5459
return this.fetchFirstChunk(url);
5560
}
5661

@@ -119,15 +124,11 @@ export class ContentServer {
119124
// Method to get the index of keys in a store
120125
public async getKeysIndex(rootHash?: string): Promise<any> {
121126
try {
122-
let udi = `chia.${this.storeId}`;
123-
124-
if (rootHash) {
125-
udi += `.${rootHash}`;
126-
}
127+
const udi = new Udi("chia", this.storeId, rootHash);
127128

128129
const url = `https://${formatHost(this.ipAddress)}:${
129130
ContentServer.port
130-
}/${udi}`;
131+
}/${udi.toString()}`;
131132
return this.fetchJson(url);
132133
} catch (error: any) {
133134
if (rootHash) {
@@ -143,15 +144,11 @@ export class ContentServer {
143144
rootHash?: string
144145
): Promise<{ success: boolean; headers?: http.IncomingHttpHeaders }> {
145146
try {
146-
let udi = `chia.${this.storeId}`;
147-
148-
if (rootHash) {
149-
udi += `.${rootHash}`;
150-
}
147+
const udi = new Udi("chia", this.storeId, rootHash, key);
151148

152149
const url = `https://${formatHost(this.ipAddress)}:${
153150
ContentServer.port
154-
}/${udi}/${key}`;
151+
}/${udi.toString()}`;
155152
return this.head(url);
156153
} catch (error: any) {
157154
if (rootHash) {
@@ -166,10 +163,11 @@ export class ContentServer {
166163
success: boolean;
167164
headers?: http.IncomingHttpHeaders;
168165
}> {
166+
const udi = new Udi("chia", this.storeId);
169167
try {
170168
let url = `https://${formatHost(this.ipAddress)}:${
171169
ContentServer.port
172-
}/chia.${this.storeId}`;
170+
}/${udi.toString()}`;
173171

174172
if (options?.hasRootHash) {
175173
url += `?hasRootHash=${options.hasRootHash}`;
@@ -218,16 +216,12 @@ export class ContentServer {
218216
}
219217

220218
public streamKey(key: string, rootHash?: string): Promise<Readable> {
221-
let udi = `chia.${this.storeId}`;
222-
223-
if (rootHash) {
224-
udi += `.${rootHash}`;
225-
}
219+
const udi = new Udi("chia", this.storeId, rootHash, key);
226220

227221
return new Promise((resolve, reject) => {
228222
const url = `https://${formatHost(this.ipAddress)}:${
229223
ContentServer.port
230-
}/${udi}/${key}`;
224+
}/${udi.toString()}`;
231225
const urlObj = new URL(url);
232226

233227
const requestOptions = {

0 commit comments

Comments
 (0)