@@ -4,6 +4,7 @@ import { URL } from "url";
4
4
import { Readable } from "stream" ;
5
5
import { formatHost , getOrCreateSSLCerts } from "../utils" ;
6
6
import NodeCache from "node-cache" ;
7
+ import { Udi } from "../utils" ;
7
8
8
9
const hasRootHashCache = new NodeCache ( { stdTTL : 86400 } ) ;
9
10
const wellKnownCache = new NodeCache ( { stdTTL : 86400 } ) ;
@@ -32,10 +33,12 @@ export class ContentServer {
32
33
rootHash : string ,
33
34
challengeHex ?: string
34
35
) : Promise < string > {
36
+ const udi = new Udi ( "chia" , this . storeId , rootHash , key ) ;
37
+
35
38
// Construct the base URL
36
39
let url = `https://${ formatHost ( this . ipAddress ) } :${
37
40
ContentServer . port
38
- } /chia. ${ this . storeId } . ${ rootHash } / ${ key } `;
41
+ } /${ udi . toString ( ) } `;
39
42
40
43
// If a challenge is provided, append it as a query parameter
41
44
if ( challengeHex ) {
@@ -47,10 +50,12 @@ export class ContentServer {
47
50
48
51
// New method to get only the first chunk of the content
49
52
public async getKeyChunk ( key : string , rootHash : string ) : Promise < Buffer > {
53
+ const udi = new Udi ( "chia" , this . storeId , rootHash , key ) ;
54
+
50
55
// Construct the base URL
51
56
let url = `https://${ formatHost ( this . ipAddress ) } :${
52
57
ContentServer . port
53
- } /chia. ${ this . storeId } . ${ rootHash } / ${ key } `;
58
+ } /${ udi . toString ( ) } `;
54
59
return this . fetchFirstChunk ( url ) ;
55
60
}
56
61
@@ -119,15 +124,11 @@ export class ContentServer {
119
124
// Method to get the index of keys in a store
120
125
public async getKeysIndex ( rootHash ?: string ) : Promise < any > {
121
126
try {
122
- let udi = `chia.${ this . storeId } ` ;
123
-
124
- if ( rootHash ) {
125
- udi += `.${ rootHash } ` ;
126
- }
127
+ const udi = new Udi ( "chia" , this . storeId , rootHash ) ;
127
128
128
129
const url = `https://${ formatHost ( this . ipAddress ) } :${
129
130
ContentServer . port
130
- } /${ udi } `;
131
+ } /${ udi . toString ( ) } `;
131
132
return this . fetchJson ( url ) ;
132
133
} catch ( error : any ) {
133
134
if ( rootHash ) {
@@ -143,15 +144,11 @@ export class ContentServer {
143
144
rootHash ?: string
144
145
) : Promise < { success : boolean ; headers ?: http . IncomingHttpHeaders } > {
145
146
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 ) ;
151
148
152
149
const url = `https://${ formatHost ( this . ipAddress ) } :${
153
150
ContentServer . port
154
- } /${ udi } / ${ key } `;
151
+ } /${ udi . toString ( ) } `;
155
152
return this . head ( url ) ;
156
153
} catch ( error : any ) {
157
154
if ( rootHash ) {
@@ -166,10 +163,11 @@ export class ContentServer {
166
163
success : boolean ;
167
164
headers ?: http . IncomingHttpHeaders ;
168
165
} > {
166
+ const udi = new Udi ( "chia" , this . storeId ) ;
169
167
try {
170
168
let url = `https://${ formatHost ( this . ipAddress ) } :${
171
169
ContentServer . port
172
- } /chia. ${ this . storeId } `;
170
+ } /${ udi . toString ( ) } `;
173
171
174
172
if ( options ?. hasRootHash ) {
175
173
url += `?hasRootHash=${ options . hasRootHash } ` ;
@@ -218,16 +216,12 @@ export class ContentServer {
218
216
}
219
217
220
218
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 ) ;
226
220
227
221
return new Promise ( ( resolve , reject ) => {
228
222
const url = `https://${ formatHost ( this . ipAddress ) } :${
229
223
ContentServer . port
230
- } /${ udi } / ${ key } `;
224
+ } /${ udi . toString ( ) } `;
231
225
const urlObj = new URL ( url ) ;
232
226
233
227
const requestOptions = {
0 commit comments