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.
@@ -12,5 +12,6 @@ declare class Social {
12
12
  static postVideoToTikTokBlob<T>(blob: Blob, data?: object, params?: Record<string, any>): AxiosPromise<Response<T>>;
13
13
  static postVideoToFacebookGroupFile<T>(file: File, data?: object, params?: Record<string, any>): AxiosPromise<Response<T>>;
14
14
  static postVideoToFacebookGroupBlob<T>(blob: Blob, data?: object, params?: Record<string, any>): AxiosPromise<Response<T>>;
15
+ static postVideoToTwitter<T>(file: File, data?: object, onProgress?: (totalSize: number, amountUploaded: number) => void, params?: Record<string, any>): Promise<void>;
15
16
  }
16
17
  export default Social;
package/dist/esm/index.js CHANGED
@@ -5450,6 +5450,67 @@ var Requests = /** @class */ (function () {
5450
5450
  }
5451
5451
  return Requests.request('POST', url, data, formData);
5452
5452
  };
5453
+ // Method adapted for browser environments
5454
+ Requests.uploadFileInChunks = function (file, uploadUrl, onProgress, data, chunkSize) {
5455
+ return __awaiter(this, void 0, void 0, function () {
5456
+ var fileSize, totalChunks, currentChunkIndex, totalUploaded, array, identifier, start, end, chunk, formData, key, fullUploadUrl, headers;
5457
+ return __generator(this, function (_a) {
5458
+ switch (_a.label) {
5459
+ case 0:
5460
+ if (!chunkSize) {
5461
+ chunkSize = 1024 * 1024;
5462
+ }
5463
+ fileSize = file.size;
5464
+ totalChunks = Math.ceil(fileSize / chunkSize);
5465
+ currentChunkIndex = 0;
5466
+ totalUploaded = 0;
5467
+ array = new Uint32Array(4);
5468
+ window.crypto.getRandomValues(array);
5469
+ identifier = Array.from(array, function (dec) { return ('0' + dec.toString(16)).substr(-2); }).join('');
5470
+ _a.label = 1;
5471
+ case 1:
5472
+ if (!(currentChunkIndex < totalChunks)) return [3 /*break*/, 3];
5473
+ start = currentChunkIndex * chunkSize;
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
+ })];
5504
+ case 2:
5505
+ // Perform the upload
5506
+ _a.sent();
5507
+ currentChunkIndex++;
5508
+ return [3 /*break*/, 1];
5509
+ case 3: return [2 /*return*/];
5510
+ }
5511
+ });
5512
+ });
5513
+ };
5453
5514
  Requests.processRoute = function (route, data, routeReplace, params) {
5454
5515
  var url = route.url;
5455
5516
  if (routeReplace) {
@@ -8112,6 +8173,7 @@ var SocialRoute = /** @class */ (function () {
8112
8173
  SocialRoute.routes = {
8113
8174
  postVideoToTikTok: { url: '/social/postVideoToTikTok', method: HTTP_METHODS.POST },
8114
8175
  postVideoToFacebookGroup: { url: '/social/postVideoToFacebookGroup', method: HTTP_METHODS.POST },
8176
+ postVideoToTwitter: { url: '/social/postVideoToTwitter', method: HTTP_METHODS.POST },
8115
8177
  };
8116
8178
  return SocialRoute;
8117
8179
  }());
@@ -8142,6 +8204,10 @@ var Social = /** @class */ (function () {
8142
8204
  var url = SocialRoute.routes.postVideoToFacebookGroup.url;
8143
8205
  return Requests.uploadBlob(url, 'video', blob, data);
8144
8206
  };
8207
+ Social.postVideoToTwitter = function (file, data, onProgress, params) {
8208
+ var url = SocialRoute.routes.postVideoToTwitter.url;
8209
+ return Requests.uploadFileInChunks(file, url, onProgress, data);
8210
+ };
8145
8211
  return Social;
8146
8212
  }());
8147
8213