@spacelr/sdk 0.19.2 → 0.19.3
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 +21 -7
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +21 -7
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -2664,6 +2664,19 @@ var AuthModule = class _AuthModule {
|
|
|
2664
2664
|
};
|
|
2665
2665
|
|
|
2666
2666
|
// libs/sdk/src/modules/storage.module.ts
|
|
2667
|
+
var THROTTLE_RETRY_MS = 6e4;
|
|
2668
|
+
var THROTTLE_MAX_RETRIES = 2;
|
|
2669
|
+
async function retryThrottled(call) {
|
|
2670
|
+
for (let attempt = 0; ; attempt++) {
|
|
2671
|
+
try {
|
|
2672
|
+
return await call();
|
|
2673
|
+
} catch (error) {
|
|
2674
|
+
const throttled = error instanceof SpacelrError && error.statusCode === 429;
|
|
2675
|
+
if (!throttled || attempt >= THROTTLE_MAX_RETRIES) throw error;
|
|
2676
|
+
await new Promise((resolve) => setTimeout(resolve, THROTTLE_RETRY_MS));
|
|
2677
|
+
}
|
|
2678
|
+
}
|
|
2679
|
+
}
|
|
2667
2680
|
var StorageModule = class {
|
|
2668
2681
|
constructor(http, tokenManager, config) {
|
|
2669
2682
|
this.http = http;
|
|
@@ -2733,10 +2746,12 @@ var StorageModule = class {
|
|
|
2733
2746
|
percentage: fileSize > 0 ? Math.min(100, Math.round(totalLoaded / fileSize * 100)) : 0
|
|
2734
2747
|
});
|
|
2735
2748
|
} : void 0;
|
|
2736
|
-
const result = await
|
|
2737
|
-
|
|
2738
|
-
|
|
2739
|
-
|
|
2749
|
+
const result = await retryThrottled(
|
|
2750
|
+
() => this.http.uploadForm(
|
|
2751
|
+
`/storage/files/${fileId}/multipart/upload-part`,
|
|
2752
|
+
formData,
|
|
2753
|
+
partProgress
|
|
2754
|
+
)
|
|
2740
2755
|
);
|
|
2741
2756
|
partProgressMap.delete(partNumber);
|
|
2742
2757
|
completedBytes += chunkSize;
|
|
@@ -2756,11 +2771,10 @@ var StorageModule = class {
|
|
|
2756
2771
|
partProgressMap.clear();
|
|
2757
2772
|
}
|
|
2758
2773
|
completedParts.sort((a, b) => a.partNumber - b.partNumber);
|
|
2759
|
-
await this.completeMultipartUpload(fileId, completedParts);
|
|
2760
|
-
return this.getFileInfo(fileId);
|
|
2774
|
+
return await retryThrottled(() => this.completeMultipartUpload(fileId, completedParts));
|
|
2761
2775
|
} catch (error) {
|
|
2762
2776
|
try {
|
|
2763
|
-
await this.abortMultipartUpload(fileId);
|
|
2777
|
+
await retryThrottled(() => this.abortMultipartUpload(fileId));
|
|
2764
2778
|
} catch {
|
|
2765
2779
|
}
|
|
2766
2780
|
throw error;
|