omnispace 0.2.0 → 0.2.1
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/pull.js +33 -5
- package/package.json +1 -1
package/dist/pull.js
CHANGED
|
@@ -63,11 +63,39 @@ async function cachedObjects(tmpDir) {
|
|
|
63
63
|
}
|
|
64
64
|
return ok;
|
|
65
65
|
}
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
66
|
+
class RetryableError extends Error {
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* A 5xx, a 429 or a dropped connection is usually the Storage having a bad second: the first real
|
|
70
|
+
* clone (Novo Dash, 2026-09-23) stopped at 995/1020 on a single 504. Those are retried with a short
|
|
71
|
+
* backoff before giving up; a 4xx or a wrong hash is not, since trying again cannot fix it.
|
|
72
|
+
*/
|
|
73
|
+
async function fetchBytes(url, hash, retryDelaysMs) {
|
|
74
|
+
for (let attempt = 0;; attempt++) {
|
|
75
|
+
try {
|
|
76
|
+
let response;
|
|
77
|
+
try {
|
|
78
|
+
response = await fetch(url);
|
|
79
|
+
}
|
|
80
|
+
catch (err) {
|
|
81
|
+
throw new RetryableError(`conexão caiu ao baixar ${hash.slice(0, 12)} (${err.message})`);
|
|
82
|
+
}
|
|
83
|
+
if (response.status >= 500 || response.status === 429) {
|
|
84
|
+
throw new RetryableError(`HTTP ${response.status} ao baixar ${hash.slice(0, 12)}`);
|
|
85
|
+
}
|
|
86
|
+
if (!response.ok)
|
|
87
|
+
throw new Error(`HTTP ${response.status} ao baixar ${hash.slice(0, 12)}`);
|
|
88
|
+
return new Uint8Array(await response.arrayBuffer());
|
|
89
|
+
}
|
|
90
|
+
catch (err) {
|
|
91
|
+
if (!(err instanceof RetryableError) || attempt >= retryDelaysMs.length)
|
|
92
|
+
throw err;
|
|
93
|
+
await new Promise((r) => setTimeout(r, retryDelaysMs[attempt]));
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
export async function download(url, hash, tmpDir, retryDelaysMs = [1000, 3000, 8000]) {
|
|
98
|
+
const bytes = await fetchBytes(url, hash, retryDelaysMs);
|
|
71
99
|
if (sha256(bytes) !== hash)
|
|
72
100
|
throw new Error(`conteúdo baixado não confere com o hash ${hash.slice(0, 12)}`);
|
|
73
101
|
// Written under a temporary name and renamed: a kill in the middle never leaves a file that
|