pinata 2.4.3 → 2.4.4
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/index.js +41 -24
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +42 -25
- package/dist/index.mjs.map +1 -1
- package/package.json +61 -67
package/dist/index.js
CHANGED
|
@@ -2567,33 +2567,50 @@ var uploadFile = async (config, file, network, options) => {
|
|
|
2567
2567
|
let uploadReq;
|
|
2568
2568
|
for (let i = 0; i < totalChunks; i++) {
|
|
2569
2569
|
const chunk = file.slice(offset, offset + chunkSize);
|
|
2570
|
-
|
|
2571
|
-
|
|
2572
|
-
|
|
2573
|
-
|
|
2574
|
-
|
|
2575
|
-
|
|
2576
|
-
|
|
2577
|
-
|
|
2578
|
-
|
|
2579
|
-
|
|
2580
|
-
|
|
2581
|
-
|
|
2582
|
-
|
|
2583
|
-
uploadReq.
|
|
2584
|
-
|
|
2585
|
-
|
|
2586
|
-
|
|
2587
|
-
|
|
2588
|
-
requestUrl: uploadReq.url
|
|
2589
|
-
}
|
|
2570
|
+
let retryCount = 0;
|
|
2571
|
+
const maxRetries = 5;
|
|
2572
|
+
while (retryCount <= maxRetries) {
|
|
2573
|
+
try {
|
|
2574
|
+
uploadReq = await fetch(url, {
|
|
2575
|
+
method: "PATCH",
|
|
2576
|
+
headers: {
|
|
2577
|
+
"Content-Type": "application/offset+octet-stream",
|
|
2578
|
+
"Upload-Offset": offset.toString(),
|
|
2579
|
+
...headers2
|
|
2580
|
+
},
|
|
2581
|
+
body: chunk
|
|
2582
|
+
});
|
|
2583
|
+
if (uploadReq.ok) {
|
|
2584
|
+
break;
|
|
2585
|
+
} else {
|
|
2586
|
+
const errorData = await uploadReq.text();
|
|
2587
|
+
throw new Error(`HTTP ${uploadReq.status}: ${errorData}`);
|
|
2590
2588
|
}
|
|
2591
|
-
)
|
|
2589
|
+
} catch (error) {
|
|
2590
|
+
retryCount++;
|
|
2591
|
+
if (retryCount > maxRetries) {
|
|
2592
|
+
const errorData = uploadReq ? await uploadReq.text().catch(() => "Unknown error") : error instanceof Error ? error.message : String(error);
|
|
2593
|
+
throw new chunkP556VRQU_js.NetworkError(
|
|
2594
|
+
`HTTP error during chunk upload after ${maxRetries} retries: ${errorData}`,
|
|
2595
|
+
uploadReq?.status || 0,
|
|
2596
|
+
{
|
|
2597
|
+
error: errorData,
|
|
2598
|
+
code: "HTTP_ERROR",
|
|
2599
|
+
metadata: {
|
|
2600
|
+
requestUrl: uploadReq?.url || url,
|
|
2601
|
+
retriesAttempted: maxRetries
|
|
2602
|
+
}
|
|
2603
|
+
}
|
|
2604
|
+
);
|
|
2605
|
+
}
|
|
2606
|
+
const delay = Math.min(1e3 * Math.pow(2, retryCount - 1), 1e4);
|
|
2607
|
+
await new Promise((resolve) => setTimeout(resolve, delay));
|
|
2608
|
+
}
|
|
2592
2609
|
}
|
|
2593
2610
|
offset += chunk.size;
|
|
2594
2611
|
}
|
|
2595
2612
|
if (uploadReq.status === 204) {
|
|
2596
|
-
const
|
|
2613
|
+
const cid = uploadReq.headers.get("upload-cid");
|
|
2597
2614
|
let dataEndpoint;
|
|
2598
2615
|
if (config.endpointUrl) {
|
|
2599
2616
|
dataEndpoint = config.endpointUrl;
|
|
@@ -2601,7 +2618,7 @@ var uploadFile = async (config, file, network, options) => {
|
|
|
2601
2618
|
dataEndpoint = "https://api.pinata.cloud/v3";
|
|
2602
2619
|
}
|
|
2603
2620
|
const fileInfoReq = await fetch(
|
|
2604
|
-
`${dataEndpoint}/files/${network}
|
|
2621
|
+
`${dataEndpoint}/files/${network}?cid=${cid}`,
|
|
2605
2622
|
{
|
|
2606
2623
|
method: "GET",
|
|
2607
2624
|
headers: {
|
|
@@ -2610,7 +2627,7 @@ var uploadFile = async (config, file, network, options) => {
|
|
|
2610
2627
|
}
|
|
2611
2628
|
);
|
|
2612
2629
|
const fileInfo = await fileInfoReq.json();
|
|
2613
|
-
const data2 = fileInfo.data;
|
|
2630
|
+
const data2 = fileInfo.data.files[0];
|
|
2614
2631
|
if (options?.vectorize) {
|
|
2615
2632
|
const vectorReq = await fetch(
|
|
2616
2633
|
`${endpoint}/vectorize/files/${data2.id}`,
|