glitch-javascript-sdk 0.8.2 → 0.8.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/cjs/index.js +44 -35
- package/dist/cjs/index.js.map +1 -1
- package/dist/esm/index.js +44 -35
- package/dist/esm/index.js.map +1 -1
- package/package.json +1 -1
- package/src/util/Requests.ts +1 -1
package/dist/cjs/index.js
CHANGED
|
@@ -18637,7 +18637,7 @@ var Requests = /** @class */ (function () {
|
|
|
18637
18637
|
// Method adapted for browser environments
|
|
18638
18638
|
Requests.uploadFileInChunks = function (file, uploadUrl, onProgress, data, chunkSize) {
|
|
18639
18639
|
return __awaiter(this, void 0, void 0, function () {
|
|
18640
|
-
var fileSize, totalChunks, currentChunkIndex,
|
|
18640
|
+
var fileSize, totalChunks, currentChunkIndex, array, identifier, _loop_1;
|
|
18641
18641
|
return __generator(this, function (_a) {
|
|
18642
18642
|
switch (_a.label) {
|
|
18643
18643
|
case 0:
|
|
@@ -18647,48 +18647,57 @@ var Requests = /** @class */ (function () {
|
|
|
18647
18647
|
fileSize = file.size;
|
|
18648
18648
|
totalChunks = Math.ceil(fileSize / chunkSize);
|
|
18649
18649
|
currentChunkIndex = 0;
|
|
18650
|
-
totalUploaded = 0;
|
|
18651
18650
|
array = new Uint32Array(4);
|
|
18652
18651
|
window.crypto.getRandomValues(array);
|
|
18653
18652
|
identifier = Array.from(array, function (dec) { return ('0' + dec.toString(16)).substr(-2); }).join('');
|
|
18653
|
+
_loop_1 = function () {
|
|
18654
|
+
var start, end, chunk, formData, key, fullUploadUrl, headers;
|
|
18655
|
+
return __generator(this, function (_b) {
|
|
18656
|
+
switch (_b.label) {
|
|
18657
|
+
case 0:
|
|
18658
|
+
start = currentChunkIndex * chunkSize;
|
|
18659
|
+
end = Math.min(start + chunkSize, fileSize);
|
|
18660
|
+
chunk = file.slice(start, end);
|
|
18661
|
+
formData = new FormData();
|
|
18662
|
+
formData.append('video', chunk, file.name);
|
|
18663
|
+
formData.append('chunkIndex', currentChunkIndex.toString());
|
|
18664
|
+
formData.append('totalChunks', totalChunks.toString());
|
|
18665
|
+
formData.append('identifier', identifier);
|
|
18666
|
+
// If there's additional data, append each key-value pair to the formData
|
|
18667
|
+
if (data) {
|
|
18668
|
+
for (key in data) {
|
|
18669
|
+
formData.append(key, data[key]);
|
|
18670
|
+
}
|
|
18671
|
+
}
|
|
18672
|
+
fullUploadUrl = "".concat(Requests.baseUrl).concat(uploadUrl);
|
|
18673
|
+
headers = {};
|
|
18674
|
+
if (Requests.authToken) {
|
|
18675
|
+
headers['Authorization'] = "Bearer ".concat(Requests.authToken);
|
|
18676
|
+
}
|
|
18677
|
+
// Perform the upload
|
|
18678
|
+
return [4 /*yield*/, axios$1.post(fullUploadUrl, formData, {
|
|
18679
|
+
headers: headers,
|
|
18680
|
+
onUploadProgress: function (progressEvent) {
|
|
18681
|
+
progressEvent.loaded; // Bytes uploaded of the current chunk
|
|
18682
|
+
if (onProgress) {
|
|
18683
|
+
onProgress(fileSize, end);
|
|
18684
|
+
}
|
|
18685
|
+
}
|
|
18686
|
+
})];
|
|
18687
|
+
case 1:
|
|
18688
|
+
// Perform the upload
|
|
18689
|
+
_b.sent();
|
|
18690
|
+
currentChunkIndex++;
|
|
18691
|
+
return [2 /*return*/];
|
|
18692
|
+
}
|
|
18693
|
+
});
|
|
18694
|
+
};
|
|
18654
18695
|
_a.label = 1;
|
|
18655
18696
|
case 1:
|
|
18656
18697
|
if (!(currentChunkIndex <= totalChunks)) return [3 /*break*/, 3];
|
|
18657
|
-
|
|
18658
|
-
end = Math.min(start + chunkSize, fileSize);
|
|
18659
|
-
chunk = file.slice(start, end);
|
|
18660
|
-
formData = new FormData();
|
|
18661
|
-
formData.append('video', chunk, file.name);
|
|
18662
|
-
formData.append('chunkIndex', currentChunkIndex.toString());
|
|
18663
|
-
formData.append('totalChunks', totalChunks.toString());
|
|
18664
|
-
formData.append('identifier', identifier);
|
|
18665
|
-
// If there's additional data, append each key-value pair to the formData
|
|
18666
|
-
if (data) {
|
|
18667
|
-
for (key in data) {
|
|
18668
|
-
formData.append(key, data[key]);
|
|
18669
|
-
}
|
|
18670
|
-
}
|
|
18671
|
-
fullUploadUrl = "".concat(Requests.baseUrl).concat(uploadUrl);
|
|
18672
|
-
headers = {};
|
|
18673
|
-
if (Requests.authToken) {
|
|
18674
|
-
headers['Authorization'] = "Bearer ".concat(Requests.authToken);
|
|
18675
|
-
}
|
|
18676
|
-
// Perform the upload
|
|
18677
|
-
return [4 /*yield*/, axios$1.post(fullUploadUrl, formData, {
|
|
18678
|
-
headers: headers,
|
|
18679
|
-
onUploadProgress: function (progressEvent) {
|
|
18680
|
-
var currentChunkProgress = progressEvent.loaded; // Bytes uploaded of the current chunk
|
|
18681
|
-
// Calculate the total uploaded size including previous chunks and the current chunk's progress
|
|
18682
|
-
var totalProgress = totalUploaded + currentChunkProgress;
|
|
18683
|
-
if (onProgress) {
|
|
18684
|
-
onProgress(fileSize, totalProgress);
|
|
18685
|
-
}
|
|
18686
|
-
}
|
|
18687
|
-
})];
|
|
18698
|
+
return [5 /*yield**/, _loop_1()];
|
|
18688
18699
|
case 2:
|
|
18689
|
-
// Perform the upload
|
|
18690
18700
|
_a.sent();
|
|
18691
|
-
currentChunkIndex++;
|
|
18692
18701
|
return [3 /*break*/, 1];
|
|
18693
18702
|
case 3: return [2 /*return*/];
|
|
18694
18703
|
}
|