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/esm/index.js
CHANGED
|
@@ -5453,7 +5453,7 @@ var Requests = /** @class */ (function () {
|
|
|
5453
5453
|
// Method adapted for browser environments
|
|
5454
5454
|
Requests.uploadFileInChunks = function (file, uploadUrl, onProgress, data, chunkSize) {
|
|
5455
5455
|
return __awaiter(this, void 0, void 0, function () {
|
|
5456
|
-
var fileSize, totalChunks, currentChunkIndex,
|
|
5456
|
+
var fileSize, totalChunks, currentChunkIndex, array, identifier, _loop_1;
|
|
5457
5457
|
return __generator(this, function (_a) {
|
|
5458
5458
|
switch (_a.label) {
|
|
5459
5459
|
case 0:
|
|
@@ -5463,48 +5463,57 @@ var Requests = /** @class */ (function () {
|
|
|
5463
5463
|
fileSize = file.size;
|
|
5464
5464
|
totalChunks = Math.ceil(fileSize / chunkSize);
|
|
5465
5465
|
currentChunkIndex = 0;
|
|
5466
|
-
totalUploaded = 0;
|
|
5467
5466
|
array = new Uint32Array(4);
|
|
5468
5467
|
window.crypto.getRandomValues(array);
|
|
5469
5468
|
identifier = Array.from(array, function (dec) { return ('0' + dec.toString(16)).substr(-2); }).join('');
|
|
5469
|
+
_loop_1 = function () {
|
|
5470
|
+
var start, end, chunk, formData, key, fullUploadUrl, headers;
|
|
5471
|
+
return __generator(this, function (_b) {
|
|
5472
|
+
switch (_b.label) {
|
|
5473
|
+
case 0:
|
|
5474
|
+
start = currentChunkIndex * chunkSize;
|
|
5475
|
+
end = Math.min(start + chunkSize, fileSize);
|
|
5476
|
+
chunk = file.slice(start, end);
|
|
5477
|
+
formData = new FormData();
|
|
5478
|
+
formData.append('video', chunk, file.name);
|
|
5479
|
+
formData.append('chunkIndex', currentChunkIndex.toString());
|
|
5480
|
+
formData.append('totalChunks', totalChunks.toString());
|
|
5481
|
+
formData.append('identifier', identifier);
|
|
5482
|
+
// If there's additional data, append each key-value pair to the formData
|
|
5483
|
+
if (data) {
|
|
5484
|
+
for (key in data) {
|
|
5485
|
+
formData.append(key, data[key]);
|
|
5486
|
+
}
|
|
5487
|
+
}
|
|
5488
|
+
fullUploadUrl = "".concat(Requests.baseUrl).concat(uploadUrl);
|
|
5489
|
+
headers = {};
|
|
5490
|
+
if (Requests.authToken) {
|
|
5491
|
+
headers['Authorization'] = "Bearer ".concat(Requests.authToken);
|
|
5492
|
+
}
|
|
5493
|
+
// Perform the upload
|
|
5494
|
+
return [4 /*yield*/, axios$1.post(fullUploadUrl, formData, {
|
|
5495
|
+
headers: headers,
|
|
5496
|
+
onUploadProgress: function (progressEvent) {
|
|
5497
|
+
progressEvent.loaded; // Bytes uploaded of the current chunk
|
|
5498
|
+
if (onProgress) {
|
|
5499
|
+
onProgress(fileSize, end);
|
|
5500
|
+
}
|
|
5501
|
+
}
|
|
5502
|
+
})];
|
|
5503
|
+
case 1:
|
|
5504
|
+
// Perform the upload
|
|
5505
|
+
_b.sent();
|
|
5506
|
+
currentChunkIndex++;
|
|
5507
|
+
return [2 /*return*/];
|
|
5508
|
+
}
|
|
5509
|
+
});
|
|
5510
|
+
};
|
|
5470
5511
|
_a.label = 1;
|
|
5471
5512
|
case 1:
|
|
5472
5513
|
if (!(currentChunkIndex <= totalChunks)) return [3 /*break*/, 3];
|
|
5473
|
-
|
|
5474
|
-
end = Math.min(start + chunkSize, fileSize);
|
|
5475
|
-
chunk = file.slice(start, end);
|
|
5476
|
-
formData = new FormData();
|
|
5477
|
-
formData.append('video', chunk, file.name);
|
|
5478
|
-
formData.append('chunkIndex', currentChunkIndex.toString());
|
|
5479
|
-
formData.append('totalChunks', totalChunks.toString());
|
|
5480
|
-
formData.append('identifier', identifier);
|
|
5481
|
-
// If there's additional data, append each key-value pair to the formData
|
|
5482
|
-
if (data) {
|
|
5483
|
-
for (key in data) {
|
|
5484
|
-
formData.append(key, data[key]);
|
|
5485
|
-
}
|
|
5486
|
-
}
|
|
5487
|
-
fullUploadUrl = "".concat(Requests.baseUrl).concat(uploadUrl);
|
|
5488
|
-
headers = {};
|
|
5489
|
-
if (Requests.authToken) {
|
|
5490
|
-
headers['Authorization'] = "Bearer ".concat(Requests.authToken);
|
|
5491
|
-
}
|
|
5492
|
-
// Perform the upload
|
|
5493
|
-
return [4 /*yield*/, axios$1.post(fullUploadUrl, formData, {
|
|
5494
|
-
headers: headers,
|
|
5495
|
-
onUploadProgress: function (progressEvent) {
|
|
5496
|
-
var currentChunkProgress = progressEvent.loaded; // Bytes uploaded of the current chunk
|
|
5497
|
-
// Calculate the total uploaded size including previous chunks and the current chunk's progress
|
|
5498
|
-
var totalProgress = totalUploaded + currentChunkProgress;
|
|
5499
|
-
if (onProgress) {
|
|
5500
|
-
onProgress(fileSize, totalProgress);
|
|
5501
|
-
}
|
|
5502
|
-
}
|
|
5503
|
-
})];
|
|
5514
|
+
return [5 /*yield**/, _loop_1()];
|
|
5504
5515
|
case 2:
|
|
5505
|
-
// Perform the upload
|
|
5506
5516
|
_a.sent();
|
|
5507
|
-
currentChunkIndex++;
|
|
5508
5517
|
return [3 /*break*/, 1];
|
|
5509
5518
|
case 3: return [2 /*return*/];
|
|
5510
5519
|
}
|