glitch-javascript-sdk 0.7.7 → 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 +144 -2
- package/dist/cjs/index.js.map +1 -1
- package/dist/esm/api/Feedback.d.ts +51 -0
- package/dist/esm/api/Social.d.ts +1 -0
- package/dist/esm/api/index.d.ts +2 -0
- package/dist/esm/index.d.ts +2 -0
- package/dist/esm/index.js +144 -2
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/routes/FeedbackRoute.d.ts +7 -0
- package/dist/esm/util/Requests.d.ts +1 -0
- package/dist/index.d.ts +52 -0
- package/package.json +2 -1
- package/src/api/Feedback.ts +80 -0
- package/src/api/Social.ts +9 -0
- package/src/api/index.ts +3 -1
- package/src/index.ts +2 -0
- package/src/routes/FeedbackRoute.ts +14 -0
- package/src/routes/MessagesRoute.ts +2 -2
- package/src/routes/SocialRoute.ts +1 -0
- package/src/util/Requests.ts +72 -0
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
|
|
|
@@ -22274,8 +22340,8 @@ var MessagesRoute = /** @class */ (function () {
|
|
|
22274
22340
|
}
|
|
22275
22341
|
MessagesRoute.routes = {
|
|
22276
22342
|
listMessageThreads: { url: '/messages', method: HTTP_METHODS.GET },
|
|
22277
|
-
sendMessage: { url: '/
|
|
22278
|
-
deleteMessage: { url: '/
|
|
22343
|
+
sendMessage: { url: '/messages', method: HTTP_METHODS.POST },
|
|
22344
|
+
deleteMessage: { url: '/messages/{message_id}', method: HTTP_METHODS.DELETE },
|
|
22279
22345
|
createOrGetThread: { url: '/messages/makeThread', method: HTTP_METHODS.POST },
|
|
22280
22346
|
};
|
|
22281
22347
|
return MessagesRoute;
|
|
@@ -22328,6 +22394,81 @@ var Messages = /** @class */ (function () {
|
|
|
22328
22394
|
return Messages;
|
|
22329
22395
|
}());
|
|
22330
22396
|
|
|
22397
|
+
var FeedbackRoute = /** @class */ (function () {
|
|
22398
|
+
function FeedbackRoute() {
|
|
22399
|
+
}
|
|
22400
|
+
FeedbackRoute.routes = {
|
|
22401
|
+
listFeedback: { url: '/feedback', method: HTTP_METHODS.GET },
|
|
22402
|
+
sendFeedback: { url: '/feedback', method: HTTP_METHODS.POST },
|
|
22403
|
+
viewFeedback: { url: '/feedback/{feedback_id}', method: HTTP_METHODS.GET },
|
|
22404
|
+
};
|
|
22405
|
+
return FeedbackRoute;
|
|
22406
|
+
}());
|
|
22407
|
+
|
|
22408
|
+
var Feedback = /** @class */ (function () {
|
|
22409
|
+
function Feedback() {
|
|
22410
|
+
}
|
|
22411
|
+
/**
|
|
22412
|
+
* List all the feedback that been left by users.
|
|
22413
|
+
*
|
|
22414
|
+
* @see https://api.glitch.fun/api/documentation#/Feedback/listFeedback
|
|
22415
|
+
*
|
|
22416
|
+
* @returns promise
|
|
22417
|
+
*/
|
|
22418
|
+
Feedback.listFeedback = function (params) {
|
|
22419
|
+
return Requests.processRoute(FeedbackRoute.routes.listFeedback, undefined, undefined, params);
|
|
22420
|
+
};
|
|
22421
|
+
/**
|
|
22422
|
+
* View a particular item of feedback.
|
|
22423
|
+
*
|
|
22424
|
+
* @see https://api.glitch.fun/api/documentation#/Feedback/getFeedbackById
|
|
22425
|
+
*
|
|
22426
|
+
* @returns promise
|
|
22427
|
+
*/
|
|
22428
|
+
Feedback.viewFeedback = function (feedback_id, params) {
|
|
22429
|
+
return Requests.processRoute(FeedbackRoute.routes.viewFeedback, undefined, { feedback_id: feedback_id }, params);
|
|
22430
|
+
};
|
|
22431
|
+
/**
|
|
22432
|
+
* Submit feedback.
|
|
22433
|
+
*
|
|
22434
|
+
* @see https://api.glitch.fun/api/documentation#/Feedback/a64fe3d6f90ed1af5bbd5311a795c134
|
|
22435
|
+
*
|
|
22436
|
+
* @returns A promise
|
|
22437
|
+
*/
|
|
22438
|
+
Feedback.sendFeedback = function (data, params) {
|
|
22439
|
+
return Requests.processRoute(FeedbackRoute.routes.sendFeedback, data, {}, params);
|
|
22440
|
+
};
|
|
22441
|
+
/**
|
|
22442
|
+
* Submit feedback with the log file as a file.
|
|
22443
|
+
*
|
|
22444
|
+
* @see https://api.glitch.fun/api/documentation#/Feedback/a64fe3d6f90ed1af5bbd5311a795c134
|
|
22445
|
+
*
|
|
22446
|
+
* @param file The file object to upload.
|
|
22447
|
+
* @param data Any additional data to pass along to the upload.
|
|
22448
|
+
*
|
|
22449
|
+
* @returns promise
|
|
22450
|
+
*/
|
|
22451
|
+
Feedback.sendFeedbackWithFile = function (file, data, params) {
|
|
22452
|
+
var url = FeedbackRoute.routes.sendFeedback.url;
|
|
22453
|
+
return Requests.uploadFile(url, 'image', file, data);
|
|
22454
|
+
};
|
|
22455
|
+
/**
|
|
22456
|
+
* Submit feedback with the log file as a blob.
|
|
22457
|
+
*
|
|
22458
|
+
* @see hhttps://api.glitch.fun/api/documentation#/Feedback/a64fe3d6f90ed1af5bbd5311a795c134
|
|
22459
|
+
*
|
|
22460
|
+
* @param blob The blob to upload.
|
|
22461
|
+
* @param data Any additional data to pass along to the upload
|
|
22462
|
+
*
|
|
22463
|
+
* @returns promise
|
|
22464
|
+
*/
|
|
22465
|
+
Feedback.sendFeedbackWithBlob = function (blob, data, params) {
|
|
22466
|
+
var url = FeedbackRoute.routes.sendFeedback.url;
|
|
22467
|
+
return Requests.uploadBlob(url, 'image', blob, data);
|
|
22468
|
+
};
|
|
22469
|
+
return Feedback;
|
|
22470
|
+
}());
|
|
22471
|
+
|
|
22331
22472
|
var Parser = /** @class */ (function () {
|
|
22332
22473
|
function Parser() {
|
|
22333
22474
|
}
|
|
@@ -22731,6 +22872,7 @@ var Glitch = /** @class */ (function () {
|
|
|
22731
22872
|
Communities: Communities,
|
|
22732
22873
|
Users: Users,
|
|
22733
22874
|
Events: Events,
|
|
22875
|
+
Feedback: Feedback,
|
|
22734
22876
|
Teams: Teams,
|
|
22735
22877
|
Posts: Posts,
|
|
22736
22878
|
Messages: Messages,
|