@gethashd/bytecave-browser 1.0.61 → 1.0.63
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{chunk-IIXRZSDW.js → chunk-RA6YSZXC.js} +41 -18
- package/dist/index.cjs +41 -18
- package/dist/index.js +1 -1
- package/dist/react/index.cjs +35 -17
- package/dist/react/index.js +1 -1
- package/package.json +1 -1
- package/src/react/useHashdUrl.ts +42 -19
- package/src/storage-websocket.ts +10 -3
|
@@ -6181,10 +6181,15 @@ var StorageWebSocketClient = class {
|
|
|
6181
6181
|
if (!this.ws || this.ws.readyState !== WebSocket.OPEN) {
|
|
6182
6182
|
await this.connect();
|
|
6183
6183
|
}
|
|
6184
|
+
const connectionTimeout = 5e3;
|
|
6185
|
+
const startTime = Date.now();
|
|
6186
|
+
while ((!this.ws || this.ws.readyState !== WebSocket.OPEN) && Date.now() - startTime < connectionTimeout) {
|
|
6187
|
+
await new Promise((resolve) => setTimeout(resolve, 50));
|
|
6188
|
+
}
|
|
6184
6189
|
if (!this.ws || this.ws.readyState !== WebSocket.OPEN) {
|
|
6185
6190
|
return {
|
|
6186
6191
|
success: false,
|
|
6187
|
-
error: "WebSocket
|
|
6192
|
+
error: "WebSocket connection timeout"
|
|
6188
6193
|
};
|
|
6189
6194
|
}
|
|
6190
6195
|
const requestId = Math.random().toString(36).substring(2, 15) + Math.random().toString(36).substring(2, 15);
|
|
@@ -7366,25 +7371,43 @@ function useHashdUrl(hashdUrl) {
|
|
|
7366
7371
|
}
|
|
7367
7372
|
const cid = hashdUrl.replace("hashd://", "").split("?")[0];
|
|
7368
7373
|
let mounted = true;
|
|
7374
|
+
let retryCount = 0;
|
|
7375
|
+
const maxRetries = 3;
|
|
7376
|
+
const retryDelay = 1e3;
|
|
7369
7377
|
setLoading(true);
|
|
7370
7378
|
setError(null);
|
|
7371
|
-
|
|
7372
|
-
|
|
7373
|
-
|
|
7374
|
-
|
|
7375
|
-
|
|
7376
|
-
|
|
7377
|
-
|
|
7378
|
-
|
|
7379
|
-
|
|
7380
|
-
|
|
7381
|
-
|
|
7382
|
-
|
|
7383
|
-
|
|
7384
|
-
|
|
7385
|
-
|
|
7386
|
-
|
|
7387
|
-
|
|
7379
|
+
const attemptRetrieve = () => {
|
|
7380
|
+
retrieve(cid).then((result) => {
|
|
7381
|
+
if (!mounted) return;
|
|
7382
|
+
if (result.success && result.data) {
|
|
7383
|
+
const dataCopy = new Uint8Array(result.data);
|
|
7384
|
+
const blob = new Blob([dataCopy]);
|
|
7385
|
+
const url = URL.createObjectURL(blob);
|
|
7386
|
+
setBlobUrl(url);
|
|
7387
|
+
setLoading(false);
|
|
7388
|
+
} else {
|
|
7389
|
+
if (retryCount < maxRetries && result.error?.includes("not connected")) {
|
|
7390
|
+
retryCount++;
|
|
7391
|
+
console.log(`[useHashdUrl] Retry ${retryCount}/${maxRetries} for CID:`, cid.slice(0, 12));
|
|
7392
|
+
setTimeout(attemptRetrieve, retryDelay);
|
|
7393
|
+
} else {
|
|
7394
|
+
setError(result.error || "Failed to retrieve content");
|
|
7395
|
+
setLoading(false);
|
|
7396
|
+
}
|
|
7397
|
+
}
|
|
7398
|
+
}).catch((err) => {
|
|
7399
|
+
if (!mounted) return;
|
|
7400
|
+
if (retryCount < maxRetries && err.message?.includes("not connected")) {
|
|
7401
|
+
retryCount++;
|
|
7402
|
+
console.log(`[useHashdUrl] Retry ${retryCount}/${maxRetries} for CID:`, cid.slice(0, 12));
|
|
7403
|
+
setTimeout(attemptRetrieve, retryDelay);
|
|
7404
|
+
} else {
|
|
7405
|
+
setError(err.message || "Failed to retrieve content");
|
|
7406
|
+
setLoading(false);
|
|
7407
|
+
}
|
|
7408
|
+
});
|
|
7409
|
+
};
|
|
7410
|
+
attemptRetrieve();
|
|
7388
7411
|
return () => {
|
|
7389
7412
|
mounted = false;
|
|
7390
7413
|
if (blobUrl) {
|
package/dist/index.cjs
CHANGED
|
@@ -6234,10 +6234,15 @@ var StorageWebSocketClient = class {
|
|
|
6234
6234
|
if (!this.ws || this.ws.readyState !== WebSocket.OPEN) {
|
|
6235
6235
|
await this.connect();
|
|
6236
6236
|
}
|
|
6237
|
+
const connectionTimeout = 5e3;
|
|
6238
|
+
const startTime = Date.now();
|
|
6239
|
+
while ((!this.ws || this.ws.readyState !== WebSocket.OPEN) && Date.now() - startTime < connectionTimeout) {
|
|
6240
|
+
await new Promise((resolve) => setTimeout(resolve, 50));
|
|
6241
|
+
}
|
|
6237
6242
|
if (!this.ws || this.ws.readyState !== WebSocket.OPEN) {
|
|
6238
6243
|
return {
|
|
6239
6244
|
success: false,
|
|
6240
|
-
error: "WebSocket
|
|
6245
|
+
error: "WebSocket connection timeout"
|
|
6241
6246
|
};
|
|
6242
6247
|
}
|
|
6243
6248
|
const requestId = Math.random().toString(36).substring(2, 15) + Math.random().toString(36).substring(2, 15);
|
|
@@ -7561,25 +7566,43 @@ function useHashdUrl(hashdUrl) {
|
|
|
7561
7566
|
}
|
|
7562
7567
|
const cid = hashdUrl.replace("hashd://", "").split("?")[0];
|
|
7563
7568
|
let mounted = true;
|
|
7569
|
+
let retryCount = 0;
|
|
7570
|
+
const maxRetries = 3;
|
|
7571
|
+
const retryDelay = 1e3;
|
|
7564
7572
|
setLoading(true);
|
|
7565
7573
|
setError(null);
|
|
7566
|
-
|
|
7567
|
-
|
|
7568
|
-
|
|
7569
|
-
|
|
7570
|
-
|
|
7571
|
-
|
|
7572
|
-
|
|
7573
|
-
|
|
7574
|
-
|
|
7575
|
-
|
|
7576
|
-
|
|
7577
|
-
|
|
7578
|
-
|
|
7579
|
-
|
|
7580
|
-
|
|
7581
|
-
|
|
7582
|
-
|
|
7574
|
+
const attemptRetrieve = () => {
|
|
7575
|
+
retrieve(cid).then((result) => {
|
|
7576
|
+
if (!mounted) return;
|
|
7577
|
+
if (result.success && result.data) {
|
|
7578
|
+
const dataCopy = new Uint8Array(result.data);
|
|
7579
|
+
const blob = new Blob([dataCopy]);
|
|
7580
|
+
const url = URL.createObjectURL(blob);
|
|
7581
|
+
setBlobUrl(url);
|
|
7582
|
+
setLoading(false);
|
|
7583
|
+
} else {
|
|
7584
|
+
if (retryCount < maxRetries && result.error?.includes("not connected")) {
|
|
7585
|
+
retryCount++;
|
|
7586
|
+
console.log(`[useHashdUrl] Retry ${retryCount}/${maxRetries} for CID:`, cid.slice(0, 12));
|
|
7587
|
+
setTimeout(attemptRetrieve, retryDelay);
|
|
7588
|
+
} else {
|
|
7589
|
+
setError(result.error || "Failed to retrieve content");
|
|
7590
|
+
setLoading(false);
|
|
7591
|
+
}
|
|
7592
|
+
}
|
|
7593
|
+
}).catch((err) => {
|
|
7594
|
+
if (!mounted) return;
|
|
7595
|
+
if (retryCount < maxRetries && err.message?.includes("not connected")) {
|
|
7596
|
+
retryCount++;
|
|
7597
|
+
console.log(`[useHashdUrl] Retry ${retryCount}/${maxRetries} for CID:`, cid.slice(0, 12));
|
|
7598
|
+
setTimeout(attemptRetrieve, retryDelay);
|
|
7599
|
+
} else {
|
|
7600
|
+
setError(err.message || "Failed to retrieve content");
|
|
7601
|
+
setLoading(false);
|
|
7602
|
+
}
|
|
7603
|
+
});
|
|
7604
|
+
};
|
|
7605
|
+
attemptRetrieve();
|
|
7583
7606
|
return () => {
|
|
7584
7607
|
mounted = false;
|
|
7585
7608
|
if (blobUrl) {
|
package/dist/index.js
CHANGED
package/dist/react/index.cjs
CHANGED
|
@@ -6383,25 +6383,43 @@ function useHashdUrl(hashdUrl) {
|
|
|
6383
6383
|
}
|
|
6384
6384
|
const cid = hashdUrl.replace("hashd://", "").split("?")[0];
|
|
6385
6385
|
let mounted = true;
|
|
6386
|
+
let retryCount = 0;
|
|
6387
|
+
const maxRetries = 3;
|
|
6388
|
+
const retryDelay = 1e3;
|
|
6386
6389
|
setLoading(true);
|
|
6387
6390
|
setError(null);
|
|
6388
|
-
|
|
6389
|
-
|
|
6390
|
-
|
|
6391
|
-
|
|
6392
|
-
|
|
6393
|
-
|
|
6394
|
-
|
|
6395
|
-
|
|
6396
|
-
|
|
6397
|
-
|
|
6398
|
-
|
|
6399
|
-
|
|
6400
|
-
|
|
6401
|
-
|
|
6402
|
-
|
|
6403
|
-
|
|
6404
|
-
|
|
6391
|
+
const attemptRetrieve = () => {
|
|
6392
|
+
retrieve(cid).then((result) => {
|
|
6393
|
+
if (!mounted) return;
|
|
6394
|
+
if (result.success && result.data) {
|
|
6395
|
+
const dataCopy = new Uint8Array(result.data);
|
|
6396
|
+
const blob = new Blob([dataCopy]);
|
|
6397
|
+
const url = URL.createObjectURL(blob);
|
|
6398
|
+
setBlobUrl(url);
|
|
6399
|
+
setLoading(false);
|
|
6400
|
+
} else {
|
|
6401
|
+
if (retryCount < maxRetries && result.error?.includes("not connected")) {
|
|
6402
|
+
retryCount++;
|
|
6403
|
+
console.log(`[useHashdUrl] Retry ${retryCount}/${maxRetries} for CID:`, cid.slice(0, 12));
|
|
6404
|
+
setTimeout(attemptRetrieve, retryDelay);
|
|
6405
|
+
} else {
|
|
6406
|
+
setError(result.error || "Failed to retrieve content");
|
|
6407
|
+
setLoading(false);
|
|
6408
|
+
}
|
|
6409
|
+
}
|
|
6410
|
+
}).catch((err) => {
|
|
6411
|
+
if (!mounted) return;
|
|
6412
|
+
if (retryCount < maxRetries && err.message?.includes("not connected")) {
|
|
6413
|
+
retryCount++;
|
|
6414
|
+
console.log(`[useHashdUrl] Retry ${retryCount}/${maxRetries} for CID:`, cid.slice(0, 12));
|
|
6415
|
+
setTimeout(attemptRetrieve, retryDelay);
|
|
6416
|
+
} else {
|
|
6417
|
+
setError(err.message || "Failed to retrieve content");
|
|
6418
|
+
setLoading(false);
|
|
6419
|
+
}
|
|
6420
|
+
});
|
|
6421
|
+
};
|
|
6422
|
+
attemptRetrieve();
|
|
6405
6423
|
return () => {
|
|
6406
6424
|
mounted = false;
|
|
6407
6425
|
if (blobUrl) {
|
package/dist/react/index.js
CHANGED
package/package.json
CHANGED
package/src/react/useHashdUrl.ts
CHANGED
|
@@ -32,29 +32,52 @@ export function useHashdUrl(hashdUrl: string | null | undefined): UseHashdUrlRes
|
|
|
32
32
|
const cid = hashdUrl.replace('hashd://', '').split('?')[0];
|
|
33
33
|
|
|
34
34
|
let mounted = true;
|
|
35
|
+
let retryCount = 0;
|
|
36
|
+
const maxRetries = 3;
|
|
37
|
+
const retryDelay = 1000; // 1 second between retries
|
|
38
|
+
|
|
35
39
|
setLoading(true);
|
|
36
40
|
setError(null);
|
|
37
41
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
42
|
+
const attemptRetrieve = () => {
|
|
43
|
+
retrieve(cid)
|
|
44
|
+
.then(result => {
|
|
45
|
+
if (!mounted) return;
|
|
46
|
+
|
|
47
|
+
if (result.success && result.data) {
|
|
48
|
+
const dataCopy = new Uint8Array(result.data);
|
|
49
|
+
const blob = new Blob([dataCopy]);
|
|
50
|
+
const url = URL.createObjectURL(blob);
|
|
51
|
+
setBlobUrl(url);
|
|
52
|
+
setLoading(false);
|
|
53
|
+
} else {
|
|
54
|
+
// Retry on failure if we haven't exceeded max retries
|
|
55
|
+
if (retryCount < maxRetries && result.error?.includes('not connected')) {
|
|
56
|
+
retryCount++;
|
|
57
|
+
console.log(`[useHashdUrl] Retry ${retryCount}/${maxRetries} for CID:`, cid.slice(0, 12));
|
|
58
|
+
setTimeout(attemptRetrieve, retryDelay);
|
|
59
|
+
} else {
|
|
60
|
+
setError(result.error || 'Failed to retrieve content');
|
|
61
|
+
setLoading(false);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
})
|
|
65
|
+
.catch(err => {
|
|
66
|
+
if (!mounted) return;
|
|
67
|
+
|
|
68
|
+
// Retry on connection errors
|
|
69
|
+
if (retryCount < maxRetries && err.message?.includes('not connected')) {
|
|
70
|
+
retryCount++;
|
|
71
|
+
console.log(`[useHashdUrl] Retry ${retryCount}/${maxRetries} for CID:`, cid.slice(0, 12));
|
|
72
|
+
setTimeout(attemptRetrieve, retryDelay);
|
|
73
|
+
} else {
|
|
74
|
+
setError(err.message || 'Failed to retrieve content');
|
|
75
|
+
setLoading(false);
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
};
|
|
41
79
|
|
|
42
|
-
|
|
43
|
-
const dataCopy = new Uint8Array(result.data);
|
|
44
|
-
const blob = new Blob([dataCopy]);
|
|
45
|
-
const url = URL.createObjectURL(blob);
|
|
46
|
-
setBlobUrl(url);
|
|
47
|
-
setLoading(false);
|
|
48
|
-
} else {
|
|
49
|
-
setError(result.error || 'Failed to retrieve content');
|
|
50
|
-
setLoading(false);
|
|
51
|
-
}
|
|
52
|
-
})
|
|
53
|
-
.catch(err => {
|
|
54
|
-
if (!mounted) return;
|
|
55
|
-
setError(err.message || 'Failed to retrieve content');
|
|
56
|
-
setLoading(false);
|
|
57
|
-
});
|
|
80
|
+
attemptRetrieve();
|
|
58
81
|
|
|
59
82
|
return () => {
|
|
60
83
|
mounted = false;
|
package/src/storage-websocket.ts
CHANGED
|
@@ -215,15 +215,22 @@ export class StorageWebSocketClient {
|
|
|
215
215
|
}
|
|
216
216
|
|
|
217
217
|
async retrieve(cid: string, timeout: number = 30000): Promise<{ success: boolean; data?: Uint8Array; mimeType?: string; error?: string }> {
|
|
218
|
+
// Ensure connection is established
|
|
218
219
|
if (!this.ws || this.ws.readyState !== WebSocket.OPEN) {
|
|
219
220
|
await this.connect();
|
|
220
221
|
}
|
|
221
|
-
|
|
222
|
-
//
|
|
222
|
+
|
|
223
|
+
// Wait for WebSocket to be in OPEN state (with timeout)
|
|
224
|
+
const connectionTimeout = 5000; // 5 seconds max wait
|
|
225
|
+
const startTime = Date.now();
|
|
226
|
+
while ((!this.ws || this.ws.readyState !== WebSocket.OPEN) && (Date.now() - startTime < connectionTimeout)) {
|
|
227
|
+
await new Promise(resolve => setTimeout(resolve, 50));
|
|
228
|
+
}
|
|
229
|
+
|
|
223
230
|
if (!this.ws || this.ws.readyState !== WebSocket.OPEN) {
|
|
224
231
|
return {
|
|
225
232
|
success: false,
|
|
226
|
-
error: 'WebSocket
|
|
233
|
+
error: 'WebSocket connection timeout'
|
|
227
234
|
};
|
|
228
235
|
}
|
|
229
236
|
|