glitch-javascript-sdk 0.7.8 → 0.7.9

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 CHANGED
@@ -18634,6 +18634,67 @@ var Requests = /** @class */ (function () {
18634
18634
  }
18635
18635
  return Requests.request('POST', url, data, formData);
18636
18636
  };
18637
+ // Method adapted for browser environments
18638
+ Requests.uploadFileInChunks = function (file, uploadUrl, onProgress, data, chunkSize) {
18639
+ return __awaiter(this, void 0, void 0, function () {
18640
+ var fileSize, totalChunks, currentChunkIndex, totalUploaded, array, identifier, start, end, chunk, formData, key, fullUploadUrl, headers;
18641
+ return __generator(this, function (_a) {
18642
+ switch (_a.label) {
18643
+ case 0:
18644
+ if (!chunkSize) {
18645
+ chunkSize = 1024 * 1024;
18646
+ }
18647
+ fileSize = file.size;
18648
+ totalChunks = Math.ceil(fileSize / chunkSize);
18649
+ currentChunkIndex = 0;
18650
+ totalUploaded = 0;
18651
+ array = new Uint32Array(4);
18652
+ window.crypto.getRandomValues(array);
18653
+ identifier = Array.from(array, function (dec) { return ('0' + dec.toString(16)).substr(-2); }).join('');
18654
+ _a.label = 1;
18655
+ case 1:
18656
+ if (!(currentChunkIndex < totalChunks)) return [3 /*break*/, 3];
18657
+ start = currentChunkIndex * chunkSize;
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
+ })];
18688
+ case 2:
18689
+ // Perform the upload
18690
+ _a.sent();
18691
+ currentChunkIndex++;
18692
+ return [3 /*break*/, 1];
18693
+ case 3: return [2 /*return*/];
18694
+ }
18695
+ });
18696
+ });
18697
+ };
18637
18698
  Requests.processRoute = function (route, data, routeReplace, params) {
18638
18699
  var url = route.url;
18639
18700
  if (routeReplace) {
@@ -21296,6 +21357,7 @@ var SocialRoute = /** @class */ (function () {
21296
21357
  SocialRoute.routes = {
21297
21358
  postVideoToTikTok: { url: '/social/postVideoToTikTok', method: HTTP_METHODS.POST },
21298
21359
  postVideoToFacebookGroup: { url: '/social/postVideoToFacebookGroup', method: HTTP_METHODS.POST },
21360
+ postVideoToTwitter: { url: '/social/postVideoToTwitter', method: HTTP_METHODS.POST },
21299
21361
  };
21300
21362
  return SocialRoute;
21301
21363
  }());
@@ -21326,6 +21388,10 @@ var Social = /** @class */ (function () {
21326
21388
  var url = SocialRoute.routes.postVideoToFacebookGroup.url;
21327
21389
  return Requests.uploadBlob(url, 'video', blob, data);
21328
21390
  };
21391
+ Social.postVideoToTwitter = function (file, data, onProgress, params) {
21392
+ var url = SocialRoute.routes.postVideoToTwitter.url;
21393
+ return Requests.uploadFileInChunks(file, url, onProgress, data);
21394
+ };
21329
21395
  return Social;
21330
21396
  }());
21331
21397