@@ -4,6 +4,7 @@ import { URL } from "url";
44import { Readable } from "stream" ;
55import { formatHost , getOrCreateSSLCerts } from "../utils" ;
66import NodeCache from "node-cache" ;
7+ import { Udi } from "../utils" ;
78
89const hasRootHashCache = new NodeCache ( { stdTTL : 86400 } ) ;
910const 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