glitch-javascript-sdk 0.6.1 → 0.6.2
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 +100 -0
- package/dist/cjs/index.js.map +1 -1
- package/dist/esm/api/Posts.d.ts +21 -0
- package/dist/esm/api/SocialPosts.d.ts +31 -0
- package/dist/esm/api/index.d.ts +2 -0
- package/dist/esm/index.js +100 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/routes/SocialPostsRoute.d.ts +7 -0
- package/dist/esm/util/Requests.d.ts +1 -1
- package/dist/index.d.ts +22 -1
- package/package.json +1 -1
- package/src/api/Posts.ts +77 -22
- package/src/api/SocialPosts.ts +46 -0
- package/src/api/index.ts +3 -1
- package/src/index.ts +2 -0
- package/src/routes/SocialPostsRoute.ts +14 -0
- package/src/util/Requests.ts +1 -1
package/dist/cjs/index.js
CHANGED
|
@@ -67,6 +67,44 @@ var __assign = function() {
|
|
|
67
67
|
return __assign.apply(this, arguments);
|
|
68
68
|
};
|
|
69
69
|
|
|
70
|
+
function __awaiter(thisArg, _arguments, P, generator) {
|
|
71
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
72
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
73
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
74
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
75
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
76
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function __generator(thisArg, body) {
|
|
81
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
82
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
83
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
84
|
+
function step(op) {
|
|
85
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
86
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
87
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
88
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
89
|
+
switch (op[0]) {
|
|
90
|
+
case 0: case 1: t = op; break;
|
|
91
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
92
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
93
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
94
|
+
default:
|
|
95
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
96
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
97
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
98
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
99
|
+
if (t[2]) _.ops.pop();
|
|
100
|
+
_.trys.pop(); continue;
|
|
101
|
+
}
|
|
102
|
+
op = body.call(thisArg, _);
|
|
103
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
104
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
70
108
|
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
71
109
|
var e = new Error(message);
|
|
72
110
|
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
@@ -19880,6 +19918,68 @@ var Posts = /** @class */ (function () {
|
|
|
19880
19918
|
Posts.createWithBlob = function (blob, data) {
|
|
19881
19919
|
return Requests.uploadBlob(PostsRoute.routes.create.url, 'file', blob, data);
|
|
19882
19920
|
};
|
|
19921
|
+
/**
|
|
19922
|
+
* Create a new post with a file divided into chunks.
|
|
19923
|
+
*
|
|
19924
|
+
* @param file The file object to upload.
|
|
19925
|
+
* @param chunkSize Size of each chunk in bytes. Default is 1MB.
|
|
19926
|
+
* @param data Any additional data to pass along to the upload.
|
|
19927
|
+
*
|
|
19928
|
+
* @returns Promise
|
|
19929
|
+
*/
|
|
19930
|
+
/**
|
|
19931
|
+
* Create a new post with a file divided into chunks.
|
|
19932
|
+
*
|
|
19933
|
+
* @param file The file object to upload.
|
|
19934
|
+
* @param chunkSize Size of each chunk in bytes. Default is 1MB.
|
|
19935
|
+
* @param data Any additional data to pass along to the upload.
|
|
19936
|
+
*
|
|
19937
|
+
* @returns Promise
|
|
19938
|
+
*/
|
|
19939
|
+
Posts.createWithFileInChunks = function (file, chunkSize, data) {
|
|
19940
|
+
if (chunkSize === void 0) { chunkSize = 1 * 1024 * 1024; }
|
|
19941
|
+
if (data === void 0) { data = {}; }
|
|
19942
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
19943
|
+
var totalChunks, i, start, end, chunk, formData, key;
|
|
19944
|
+
return __generator(this, function (_a) {
|
|
19945
|
+
switch (_a.label) {
|
|
19946
|
+
case 0:
|
|
19947
|
+
totalChunks = Math.ceil(file.size / chunkSize);
|
|
19948
|
+
i = 0;
|
|
19949
|
+
_a.label = 1;
|
|
19950
|
+
case 1:
|
|
19951
|
+
if (!(i < totalChunks)) return [3 /*break*/, 6];
|
|
19952
|
+
start = i * chunkSize;
|
|
19953
|
+
end = start + chunkSize;
|
|
19954
|
+
chunk = file.slice(start, end);
|
|
19955
|
+
formData = new FormData();
|
|
19956
|
+
formData.append('file', chunk, "".concat(i, "-").concat(file.name)); // Naming chunks as index-filename for identification
|
|
19957
|
+
formData.append('totalChunks', totalChunks.toString());
|
|
19958
|
+
formData.append('currentChunk', i.toString());
|
|
19959
|
+
// merge any other data if provided
|
|
19960
|
+
for (key in data) {
|
|
19961
|
+
formData.append(key, data[key]);
|
|
19962
|
+
}
|
|
19963
|
+
if (!(i === totalChunks - 1)) return [3 /*break*/, 3];
|
|
19964
|
+
return [4 /*yield*/, Requests.uploadFile(PostsRoute.routes.create.url, 'file', chunk, formData)];
|
|
19965
|
+
case 2:
|
|
19966
|
+
_a.sent();
|
|
19967
|
+
return [3 /*break*/, 5];
|
|
19968
|
+
case 3: return [4 /*yield*/, Requests.uploadFile(PostsRoute.routes.create.url, 'file', chunk, formData)];
|
|
19969
|
+
case 4:
|
|
19970
|
+
_a.sent();
|
|
19971
|
+
_a.label = 5;
|
|
19972
|
+
case 5:
|
|
19973
|
+
i++;
|
|
19974
|
+
return [3 /*break*/, 1];
|
|
19975
|
+
case 6:
|
|
19976
|
+
{
|
|
19977
|
+
throw new Error("No response from the last chunk upload");
|
|
19978
|
+
}
|
|
19979
|
+
}
|
|
19980
|
+
});
|
|
19981
|
+
});
|
|
19982
|
+
};
|
|
19883
19983
|
/**
|
|
19884
19984
|
* Update a post.
|
|
19885
19985
|
*
|