@eluvio/elv-client-js 4.0.10 → 4.0.11
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/ElvClient-min.js +10 -11
- package/dist/ElvClient-node-min.js +10 -11
- package/dist/ElvFrameClient-min.js +10 -11
- package/dist/ElvPermissionsClient-min.js +9 -10
- package/dist/ElvWalletClient-min.js +9 -10
- package/dist/ElvWalletClient-node-min.js +9 -10
- package/dist/src/AuthorizationClient.js +2070 -1550
- package/dist/src/ContentObjectVerification.js +185 -134
- package/dist/src/Crypto.js +319 -224
- package/dist/src/ElvClient.js +1114 -822
- package/dist/src/ElvWallet.js +106 -64
- package/dist/src/EthClient.js +974 -719
- package/dist/src/FrameClient.js +318 -222
- package/dist/src/HttpClient.js +154 -112
- package/dist/src/Id.js +6 -1
- package/dist/src/LogMessage.js +8 -4
- package/dist/src/PermissionsClient.js +1271 -973
- package/dist/src/RemoteSigner.js +232 -161
- package/dist/src/UserProfileClient.js +1038 -781
- package/dist/src/Utils.js +299 -159
- package/dist/src/Validation.js +17 -2
- package/dist/src/client/ABRPublishing.js +942 -772
- package/dist/src/client/AccessGroups.js +1095 -849
- package/dist/src/client/ContentAccess.js +4196 -3323
- package/dist/src/client/ContentManagement.js +2288 -1814
- package/dist/src/client/Contracts.js +614 -468
- package/dist/src/client/Files.js +1831 -1490
- package/dist/src/client/NFT.js +116 -94
- package/dist/src/client/NTP.js +425 -326
- package/dist/src/index.js +5 -2
- package/dist/src/walletClient/ClientMethods.js +1763 -1368
- package/dist/src/walletClient/Configuration.js +2 -4
- package/dist/src/walletClient/Notifications.js +127 -98
- package/dist/src/walletClient/Profile.js +246 -184
- package/dist/src/walletClient/Utils.js +122 -76
- package/dist/src/walletClient/index.js +1496 -1171
- package/package.json +1 -1
- package/src/AuthorizationClient.js +5 -5
- package/src/client/Files.js +1 -1
- package/testScripts/CreateMezMonolithic.js +0 -779
package/dist/src/client/Files.js
CHANGED
|
@@ -1,29 +1,36 @@
|
|
|
1
1
|
var _defineProperty = require("@babel/runtime/helpers/defineProperty");
|
|
2
|
+
|
|
2
3
|
var _regeneratorRuntime = require("@babel/runtime/regenerator");
|
|
4
|
+
|
|
3
5
|
var _asyncToGenerator = require("@babel/runtime/helpers/asyncToGenerator");
|
|
6
|
+
|
|
4
7
|
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
8
|
+
|
|
5
9
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
10
|
+
|
|
6
11
|
/**
|
|
7
12
|
* Methods for accessing and managing access groups
|
|
8
13
|
*
|
|
9
14
|
* @module ElvClient/Files+Parts
|
|
10
15
|
*/
|
|
11
|
-
|
|
12
16
|
var Utils = require("../Utils");
|
|
17
|
+
|
|
13
18
|
var fs;
|
|
19
|
+
|
|
14
20
|
if (Utils.Platform() === Utils.PLATFORM_NODE) {
|
|
15
21
|
// Define Response in node
|
|
16
22
|
// eslint-disable-next-line no-global-assign
|
|
17
23
|
globalThis.Response = require("node-fetch").Response;
|
|
18
24
|
fs = require("fs");
|
|
19
25
|
}
|
|
26
|
+
|
|
20
27
|
var UrlJoin = require("url-join");
|
|
21
|
-
var _require = require("../Validation"),
|
|
22
|
-
ValidatePresence = _require.ValidatePresence,
|
|
23
|
-
ValidateWriteToken = _require.ValidateWriteToken,
|
|
24
|
-
ValidatePartHash = _require.ValidatePartHash,
|
|
25
|
-
ValidateParameters = _require.ValidateParameters;
|
|
26
28
|
|
|
29
|
+
var _require = require("../Validation"),
|
|
30
|
+
ValidatePresence = _require.ValidatePresence,
|
|
31
|
+
ValidateWriteToken = _require.ValidateWriteToken,
|
|
32
|
+
ValidatePartHash = _require.ValidatePartHash,
|
|
33
|
+
ValidateParameters = _require.ValidateParameters;
|
|
27
34
|
/* Files */
|
|
28
35
|
|
|
29
36
|
/**
|
|
@@ -36,51 +43,59 @@ var _require = require("../Validation"),
|
|
|
36
43
|
* @param {string=} objectId - ID of the object
|
|
37
44
|
* @param {string=} versionHash - Hash of the object version - if not specified, most recent version will be used
|
|
38
45
|
*/
|
|
46
|
+
|
|
47
|
+
|
|
39
48
|
exports.ListFiles = /*#__PURE__*/function () {
|
|
40
49
|
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(_ref) {
|
|
41
50
|
var libraryId, objectId, versionHash, path;
|
|
42
51
|
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
43
|
-
while (1)
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
52
|
+
while (1) {
|
|
53
|
+
switch (_context.prev = _context.next) {
|
|
54
|
+
case 0:
|
|
55
|
+
libraryId = _ref.libraryId, objectId = _ref.objectId, versionHash = _ref.versionHash;
|
|
56
|
+
ValidateParameters({
|
|
57
|
+
libraryId: libraryId,
|
|
58
|
+
objectId: objectId,
|
|
59
|
+
versionHash: versionHash
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
if (versionHash) {
|
|
63
|
+
objectId = this.utils.DecodeVersionHash(versionHash).objectId;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
path = UrlJoin("q", versionHash || objectId, "meta", "files");
|
|
67
|
+
_context.t0 = this.utils;
|
|
68
|
+
_context.t1 = this.HttpClient;
|
|
69
|
+
_context.next = 8;
|
|
70
|
+
return this.authClient.AuthorizationHeader({
|
|
71
|
+
libraryId: libraryId,
|
|
72
|
+
objectId: objectId,
|
|
73
|
+
versionHash: versionHash
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
case 8:
|
|
77
|
+
_context.t2 = _context.sent;
|
|
78
|
+
_context.t3 = path;
|
|
79
|
+
_context.t4 = {
|
|
80
|
+
headers: _context.t2,
|
|
81
|
+
method: "GET",
|
|
82
|
+
path: _context.t3
|
|
83
|
+
};
|
|
84
|
+
_context.t5 = _context.t1.Request.call(_context.t1, _context.t4);
|
|
85
|
+
return _context.abrupt("return", _context.t0.ResponseToJson.call(_context.t0, _context.t5));
|
|
86
|
+
|
|
87
|
+
case 13:
|
|
88
|
+
case "end":
|
|
89
|
+
return _context.stop();
|
|
90
|
+
}
|
|
76
91
|
}
|
|
77
92
|
}, _callee, this);
|
|
78
93
|
}));
|
|
94
|
+
|
|
79
95
|
return function (_x) {
|
|
80
96
|
return _ref2.apply(this, arguments);
|
|
81
97
|
};
|
|
82
98
|
}();
|
|
83
|
-
|
|
84
99
|
/**
|
|
85
100
|
* Copy/reference files from S3 to a content object.
|
|
86
101
|
*
|
|
@@ -115,202 +130,243 @@ exports.ListFiles = /*#__PURE__*/function () {
|
|
|
115
130
|
* - Arguments (copy): { done: boolean, uploaded: number, total: number, uploadedFiles: number, totalFiles: number, fileStatus: Object }
|
|
116
131
|
* - Arguments (reference): { done: boolean, uploadedFiles: number, totalFiles: number }
|
|
117
132
|
*/
|
|
133
|
+
|
|
134
|
+
|
|
118
135
|
exports.UploadFilesFromS3 = /*#__PURE__*/function () {
|
|
119
136
|
var _ref4 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(_ref3) {
|
|
120
137
|
var libraryId, objectId, writeToken, region, bucket, fileInfo, accessKey, secret, signedUrl, _ref3$encryption, encryption, _ref3$copy, copy, callback, s3prefixRegex, i, fileSourcePath, s3prefixMatch, bucketName, encryption_key, conk, cloudCredentials, defaults, ops, _yield$this$CreateFil, id, status, done, progress, _progress;
|
|
138
|
+
|
|
121
139
|
return _regeneratorRuntime.wrap(function _callee2$(_context2) {
|
|
122
|
-
while (1)
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
140
|
+
while (1) {
|
|
141
|
+
switch (_context2.prev = _context2.next) {
|
|
142
|
+
case 0:
|
|
143
|
+
libraryId = _ref3.libraryId, objectId = _ref3.objectId, writeToken = _ref3.writeToken, region = _ref3.region, bucket = _ref3.bucket, fileInfo = _ref3.fileInfo, accessKey = _ref3.accessKey, secret = _ref3.secret, signedUrl = _ref3.signedUrl, _ref3$encryption = _ref3.encryption, encryption = _ref3$encryption === void 0 ? "none" : _ref3$encryption, _ref3$copy = _ref3.copy, copy = _ref3$copy === void 0 ? false : _ref3$copy, callback = _ref3.callback;
|
|
144
|
+
ValidateParameters({
|
|
145
|
+
libraryId: libraryId,
|
|
146
|
+
objectId: objectId
|
|
147
|
+
});
|
|
148
|
+
ValidateWriteToken(writeToken);
|
|
149
|
+
s3prefixRegex = /^s3:\/\/([^/]+)\//i; // for matching and extracting bucket name when full s3:// path is specified
|
|
150
|
+
// if fileInfo source paths start with s3://bucketName/, check against bucket arg passed in, and strip
|
|
151
|
+
|
|
152
|
+
i = 0;
|
|
153
|
+
|
|
154
|
+
case 5:
|
|
155
|
+
if (!(i < fileInfo.length)) {
|
|
156
|
+
_context2.next = 18;
|
|
157
|
+
break;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
fileSourcePath = fileInfo[i].source;
|
|
161
|
+
s3prefixMatch = s3prefixRegex.exec(fileSourcePath);
|
|
162
|
+
|
|
163
|
+
if (!s3prefixMatch) {
|
|
164
|
+
_context2.next = 15;
|
|
165
|
+
break;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
bucketName = s3prefixMatch[1];
|
|
169
|
+
|
|
170
|
+
if (!(bucketName !== bucket)) {
|
|
171
|
+
_context2.next = 14;
|
|
172
|
+
break;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
throw Error("Full S3 file path \"" + fileSourcePath + "\" specified, but does not match provided bucket name '" + bucket + "'");
|
|
176
|
+
|
|
177
|
+
case 14:
|
|
178
|
+
// strip prefix
|
|
179
|
+
fileInfo[i].source = fileSourcePath.replace(s3prefixRegex, "");
|
|
180
|
+
|
|
181
|
+
case 15:
|
|
182
|
+
i++;
|
|
183
|
+
_context2.next = 5;
|
|
161
184
|
break;
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
185
|
+
|
|
186
|
+
case 18:
|
|
187
|
+
this.Log("Uploading files from S3: ".concat(libraryId, " ").concat(objectId, " ").concat(writeToken));
|
|
188
|
+
|
|
189
|
+
if (!(encryption === "cgck")) {
|
|
190
|
+
_context2.next = 25;
|
|
191
|
+
break;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
_context2.next = 22;
|
|
195
|
+
return this.EncryptionConk({
|
|
196
|
+
libraryId: libraryId,
|
|
197
|
+
objectId: objectId,
|
|
198
|
+
writeToken: writeToken
|
|
199
|
+
});
|
|
200
|
+
|
|
201
|
+
case 22:
|
|
202
|
+
conk = _context2.sent;
|
|
203
|
+
conk = _objectSpread(_objectSpread({}, conk), {}, {
|
|
204
|
+
secret_key: ""
|
|
205
|
+
});
|
|
206
|
+
encryption_key = "kp__".concat(this.utils.B58(Buffer.from(JSON.stringify(conk))));
|
|
207
|
+
|
|
208
|
+
case 25:
|
|
181
209
|
cloudCredentials = {
|
|
182
|
-
|
|
210
|
+
access_key_id: accessKey,
|
|
211
|
+
secret_access_key: secret
|
|
183
212
|
};
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
platform: "aws",
|
|
190
|
-
path: bucket,
|
|
191
|
-
storage_endpoint: {
|
|
192
|
-
region: region
|
|
193
|
-
},
|
|
194
|
-
cloud_credentials: cloudCredentials
|
|
213
|
+
|
|
214
|
+
if (signedUrl) {
|
|
215
|
+
cloudCredentials = {
|
|
216
|
+
signed_url: signedUrl
|
|
217
|
+
};
|
|
195
218
|
}
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
219
|
+
|
|
220
|
+
defaults = {
|
|
221
|
+
encryption_key: encryption_key,
|
|
222
|
+
access: {
|
|
223
|
+
protocol: "s3",
|
|
224
|
+
platform: "aws",
|
|
225
|
+
path: bucket,
|
|
226
|
+
storage_endpoint: {
|
|
227
|
+
region: region
|
|
204
228
|
},
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
229
|
+
cloud_credentials: cloudCredentials
|
|
230
|
+
}
|
|
231
|
+
};
|
|
232
|
+
ops = fileInfo.map(function (info) {
|
|
233
|
+
if (copy) {
|
|
234
|
+
return {
|
|
235
|
+
op: "ingest-copy",
|
|
236
|
+
path: info.path,
|
|
237
|
+
encryption: {
|
|
238
|
+
scheme: encryption === "cgck" ? "cgck" : "none"
|
|
239
|
+
},
|
|
240
|
+
ingest: {
|
|
241
|
+
type: "key",
|
|
242
|
+
path: info.source
|
|
243
|
+
}
|
|
244
|
+
};
|
|
245
|
+
} else {
|
|
246
|
+
return {
|
|
247
|
+
op: "add-reference",
|
|
248
|
+
path: info.path,
|
|
249
|
+
reference: {
|
|
250
|
+
type: "key",
|
|
251
|
+
path: info.source
|
|
252
|
+
}
|
|
253
|
+
};
|
|
254
|
+
}
|
|
255
|
+
}); // eslint-disable-next-line no-unused-vars
|
|
256
|
+
|
|
257
|
+
_context2.next = 31;
|
|
258
|
+
return this.CreateFileUploadJob({
|
|
259
|
+
libraryId: libraryId,
|
|
260
|
+
objectId: objectId,
|
|
261
|
+
writeToken: writeToken,
|
|
262
|
+
ops: ops,
|
|
263
|
+
defaults: defaults
|
|
264
|
+
});
|
|
265
|
+
|
|
266
|
+
case 31:
|
|
267
|
+
_yield$this$CreateFil = _context2.sent;
|
|
268
|
+
id = _yield$this$CreateFil.id;
|
|
269
|
+
|
|
270
|
+
case 33:
|
|
271
|
+
if (!true) {
|
|
272
|
+
_context2.next = 56;
|
|
273
|
+
break;
|
|
219
274
|
}
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
case 36:
|
|
242
|
-
_context2.next = 38;
|
|
243
|
-
return this.UploadStatus({
|
|
244
|
-
libraryId: libraryId,
|
|
245
|
-
objectId: objectId,
|
|
246
|
-
writeToken: writeToken,
|
|
247
|
-
uploadId: id
|
|
248
|
-
});
|
|
249
|
-
case 38:
|
|
250
|
-
status = _context2.sent;
|
|
251
|
-
if (!(status.errors && status.errors.length > 1)) {
|
|
252
|
-
_context2.next = 43;
|
|
253
|
-
break;
|
|
254
|
-
}
|
|
255
|
-
throw status.errors.join("\n");
|
|
256
|
-
case 43:
|
|
257
|
-
if (!status.error) {
|
|
258
|
-
_context2.next = 48;
|
|
259
|
-
break;
|
|
260
|
-
}
|
|
261
|
-
this.Log("S3 file upload failed:\n".concat(JSON.stringify(status, null, 2)));
|
|
262
|
-
throw status.error;
|
|
263
|
-
case 48:
|
|
264
|
-
if (!(status.status.toLowerCase() === "failed")) {
|
|
265
|
-
_context2.next = 50;
|
|
266
|
-
break;
|
|
267
|
-
}
|
|
268
|
-
throw "File upload failed";
|
|
269
|
-
case 50:
|
|
270
|
-
done = false;
|
|
271
|
-
if (copy) {
|
|
272
|
-
done = status.ingest_copy.done;
|
|
273
|
-
if (callback) {
|
|
274
|
-
progress = status.ingest_copy.progress;
|
|
275
|
-
callback({
|
|
276
|
-
done: done,
|
|
277
|
-
uploaded: progress.bytes.completed,
|
|
278
|
-
total: progress.bytes.total,
|
|
279
|
-
uploadedFiles: progress.files.completed,
|
|
280
|
-
totalFiles: progress.files.total,
|
|
281
|
-
fileStatus: progress.files.details
|
|
282
|
-
});
|
|
275
|
+
|
|
276
|
+
_context2.next = 36;
|
|
277
|
+
return new Promise(function (resolve) {
|
|
278
|
+
return setTimeout(resolve, 1000);
|
|
279
|
+
});
|
|
280
|
+
|
|
281
|
+
case 36:
|
|
282
|
+
_context2.next = 38;
|
|
283
|
+
return this.UploadStatus({
|
|
284
|
+
libraryId: libraryId,
|
|
285
|
+
objectId: objectId,
|
|
286
|
+
writeToken: writeToken,
|
|
287
|
+
uploadId: id
|
|
288
|
+
});
|
|
289
|
+
|
|
290
|
+
case 38:
|
|
291
|
+
status = _context2.sent;
|
|
292
|
+
|
|
293
|
+
if (!(status.errors && status.errors.length > 1)) {
|
|
294
|
+
_context2.next = 43;
|
|
295
|
+
break;
|
|
283
296
|
}
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
totalFiles: _progress.total
|
|
292
|
-
});
|
|
297
|
+
|
|
298
|
+
throw status.errors.join("\n");
|
|
299
|
+
|
|
300
|
+
case 43:
|
|
301
|
+
if (!status.error) {
|
|
302
|
+
_context2.next = 48;
|
|
303
|
+
break;
|
|
293
304
|
}
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
305
|
+
|
|
306
|
+
this.Log("S3 file upload failed:\n".concat(JSON.stringify(status, null, 2)));
|
|
307
|
+
throw status.error;
|
|
308
|
+
|
|
309
|
+
case 48:
|
|
310
|
+
if (!(status.status.toLowerCase() === "failed")) {
|
|
311
|
+
_context2.next = 50;
|
|
312
|
+
break;
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
throw "File upload failed";
|
|
316
|
+
|
|
317
|
+
case 50:
|
|
318
|
+
done = false;
|
|
319
|
+
|
|
320
|
+
if (copy) {
|
|
321
|
+
done = status.ingest_copy.done;
|
|
322
|
+
|
|
323
|
+
if (callback) {
|
|
324
|
+
progress = status.ingest_copy.progress;
|
|
325
|
+
callback({
|
|
326
|
+
done: done,
|
|
327
|
+
uploaded: progress.bytes.completed,
|
|
328
|
+
total: progress.bytes.total,
|
|
329
|
+
uploadedFiles: progress.files.completed,
|
|
330
|
+
totalFiles: progress.files.total,
|
|
331
|
+
fileStatus: progress.files.details
|
|
332
|
+
});
|
|
333
|
+
}
|
|
334
|
+
} else {
|
|
335
|
+
done = status.add_reference.done;
|
|
336
|
+
|
|
337
|
+
if (callback) {
|
|
338
|
+
_progress = status.add_reference.progress;
|
|
339
|
+
callback({
|
|
340
|
+
done: done,
|
|
341
|
+
uploadedFiles: _progress.completed,
|
|
342
|
+
totalFiles: _progress.total
|
|
343
|
+
});
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
if (!done) {
|
|
348
|
+
_context2.next = 54;
|
|
349
|
+
break;
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
return _context2.abrupt("break", 56);
|
|
353
|
+
|
|
354
|
+
case 54:
|
|
355
|
+
_context2.next = 33;
|
|
297
356
|
break;
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
case 56:
|
|
304
|
-
case "end":
|
|
305
|
-
return _context2.stop();
|
|
357
|
+
|
|
358
|
+
case 56:
|
|
359
|
+
case "end":
|
|
360
|
+
return _context2.stop();
|
|
361
|
+
}
|
|
306
362
|
}
|
|
307
363
|
}, _callee2, this);
|
|
308
364
|
}));
|
|
365
|
+
|
|
309
366
|
return function (_x2) {
|
|
310
367
|
return _ref4.apply(this, arguments);
|
|
311
368
|
};
|
|
312
369
|
}();
|
|
313
|
-
|
|
314
370
|
/**
|
|
315
371
|
* Upload files to a content object.
|
|
316
372
|
*
|
|
@@ -337,530 +393,629 @@ exports.UploadFilesFromS3 = /*#__PURE__*/function () {
|
|
|
337
393
|
* @param {function=} callback - If specified, will be called after each job segment is finished with the current upload progress
|
|
338
394
|
* - Format: {"filename1": {uploaded: number, total: number}, ...}
|
|
339
395
|
*/
|
|
396
|
+
|
|
397
|
+
|
|
340
398
|
exports.UploadFiles = /*#__PURE__*/function () {
|
|
341
399
|
var _ref6 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee6(_ref5) {
|
|
342
400
|
var _this = this;
|
|
401
|
+
|
|
343
402
|
var libraryId, objectId, writeToken, fileInfo, _ref5$encryption, encryption, callback, conk, progress, fileDataMap, i, entry, _yield$this$CreateFil2, id, jobs, bufferSize, jobSpecs, prepared, uploaded, PrepareJobs, UploadJob, rateTestJobs, rates, j, start, elapsed, size, averageRate, concurrentUploads;
|
|
403
|
+
|
|
344
404
|
return _regeneratorRuntime.wrap(function _callee6$(_context6) {
|
|
345
|
-
while (1)
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
ValidateWriteToken(writeToken);
|
|
353
|
-
this.Log("Uploading files: ".concat(libraryId, " ").concat(objectId, " ").concat(writeToken));
|
|
354
|
-
if (!(encryption === "cgck")) {
|
|
355
|
-
_context6.next = 8;
|
|
356
|
-
break;
|
|
357
|
-
}
|
|
358
|
-
_context6.next = 7;
|
|
359
|
-
return this.EncryptionConk({
|
|
360
|
-
libraryId: libraryId,
|
|
361
|
-
objectId: objectId,
|
|
362
|
-
writeToken: writeToken
|
|
363
|
-
});
|
|
364
|
-
case 7:
|
|
365
|
-
conk = _context6.sent;
|
|
366
|
-
case 8:
|
|
367
|
-
// Extract file data into easily accessible hash while removing the data from the fileinfo for upload job creation
|
|
368
|
-
progress = {};
|
|
369
|
-
fileDataMap = {};
|
|
370
|
-
for (i = 0; i < fileInfo.length; i++) {
|
|
371
|
-
entry = _objectSpread(_objectSpread({}, fileInfo[i]), {}, {
|
|
372
|
-
data: undefined
|
|
405
|
+
while (1) {
|
|
406
|
+
switch (_context6.prev = _context6.next) {
|
|
407
|
+
case 0:
|
|
408
|
+
libraryId = _ref5.libraryId, objectId = _ref5.objectId, writeToken = _ref5.writeToken, fileInfo = _ref5.fileInfo, _ref5$encryption = _ref5.encryption, encryption = _ref5$encryption === void 0 ? "none" : _ref5$encryption, callback = _ref5.callback;
|
|
409
|
+
ValidateParameters({
|
|
410
|
+
libraryId: libraryId,
|
|
411
|
+
objectId: objectId
|
|
373
412
|
});
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
413
|
+
ValidateWriteToken(writeToken);
|
|
414
|
+
this.Log("Uploading files: ".concat(libraryId, " ").concat(objectId, " ").concat(writeToken));
|
|
415
|
+
|
|
416
|
+
if (!(encryption === "cgck")) {
|
|
417
|
+
_context6.next = 8;
|
|
418
|
+
break;
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
_context6.next = 7;
|
|
422
|
+
return this.EncryptionConk({
|
|
423
|
+
libraryId: libraryId,
|
|
424
|
+
objectId: objectId,
|
|
425
|
+
writeToken: writeToken
|
|
426
|
+
});
|
|
427
|
+
|
|
428
|
+
case 7:
|
|
429
|
+
conk = _context6.sent;
|
|
430
|
+
|
|
431
|
+
case 8:
|
|
432
|
+
// Extract file data into easily accessible hash while removing the data from the fileinfo for upload job creation
|
|
433
|
+
progress = {};
|
|
434
|
+
fileDataMap = {};
|
|
435
|
+
|
|
436
|
+
for (i = 0; i < fileInfo.length; i++) {
|
|
437
|
+
entry = _objectSpread(_objectSpread({}, fileInfo[i]), {}, {
|
|
438
|
+
data: undefined
|
|
439
|
+
});
|
|
440
|
+
entry.path = entry.path.replace(/^\/+/, "");
|
|
441
|
+
|
|
442
|
+
if (encryption === "cgck") {
|
|
443
|
+
entry.encryption = {
|
|
444
|
+
scheme: "cgck"
|
|
445
|
+
};
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
fileDataMap[entry.path] = fileInfo[i].data;
|
|
449
|
+
delete entry.data;
|
|
450
|
+
entry.type = "file";
|
|
451
|
+
progress[entry.path] = {
|
|
452
|
+
uploaded: 0,
|
|
453
|
+
total: entry.size
|
|
378
454
|
};
|
|
455
|
+
fileInfo[i] = entry;
|
|
379
456
|
}
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
if (jobSpecs[j]) {
|
|
510
|
-
_context4.next = 5;
|
|
511
|
-
break;
|
|
512
|
-
}
|
|
513
|
-
_context4.next = 3;
|
|
514
|
-
return new Promise(function (resolve) {
|
|
515
|
-
return setTimeout(resolve, 500);
|
|
516
|
-
});
|
|
517
|
-
case 3:
|
|
518
|
-
_context4.next = 0;
|
|
519
|
-
break;
|
|
520
|
-
case 5:
|
|
521
|
-
jobSpec = jobSpecs[j];
|
|
522
|
-
files = jobSpec.files; // Upload each item
|
|
523
|
-
f = 0;
|
|
524
|
-
case 8:
|
|
525
|
-
if (!(f < files.length)) {
|
|
526
|
-
_context4.next = 18;
|
|
527
|
-
break;
|
|
457
|
+
|
|
458
|
+
this.Log(fileInfo);
|
|
459
|
+
|
|
460
|
+
if (callback) {
|
|
461
|
+
callback(progress);
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
_context6.next = 15;
|
|
465
|
+
return this.CreateFileUploadJob({
|
|
466
|
+
libraryId: libraryId,
|
|
467
|
+
objectId: objectId,
|
|
468
|
+
writeToken: writeToken,
|
|
469
|
+
ops: fileInfo,
|
|
470
|
+
encryption: encryption
|
|
471
|
+
});
|
|
472
|
+
|
|
473
|
+
case 15:
|
|
474
|
+
_yield$this$CreateFil2 = _context6.sent;
|
|
475
|
+
id = _yield$this$CreateFil2.id;
|
|
476
|
+
jobs = _yield$this$CreateFil2.jobs;
|
|
477
|
+
this.Log("Upload ID: ".concat(id));
|
|
478
|
+
this.Log(jobs); // How far encryption can get ahead of upload
|
|
479
|
+
|
|
480
|
+
bufferSize = 100 * 1024 * 1024;
|
|
481
|
+
jobSpecs = [];
|
|
482
|
+
prepared = 0;
|
|
483
|
+
uploaded = 0; // Insert the data to upload into the job spec, encrypting if necessary
|
|
484
|
+
|
|
485
|
+
PrepareJobs = /*#__PURE__*/function () {
|
|
486
|
+
var _ref7 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3() {
|
|
487
|
+
var j, jobId, job, f, _fileInfo, data;
|
|
488
|
+
|
|
489
|
+
return _regeneratorRuntime.wrap(function _callee3$(_context3) {
|
|
490
|
+
while (1) {
|
|
491
|
+
switch (_context3.prev = _context3.next) {
|
|
492
|
+
case 0:
|
|
493
|
+
j = 0;
|
|
494
|
+
|
|
495
|
+
case 1:
|
|
496
|
+
if (!(j < jobs.length)) {
|
|
497
|
+
_context3.next = 31;
|
|
498
|
+
break;
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
case 2:
|
|
502
|
+
if (!(prepared - uploaded > bufferSize)) {
|
|
503
|
+
_context3.next = 7;
|
|
504
|
+
break;
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
_context3.next = 5;
|
|
508
|
+
return new Promise(function (resolve) {
|
|
509
|
+
return setTimeout(resolve, 500);
|
|
510
|
+
});
|
|
511
|
+
|
|
512
|
+
case 5:
|
|
513
|
+
_context3.next = 2;
|
|
514
|
+
break;
|
|
515
|
+
|
|
516
|
+
case 7:
|
|
517
|
+
// Retrieve job info
|
|
518
|
+
jobId = jobs[j];
|
|
519
|
+
_context3.next = 10;
|
|
520
|
+
return _this.UploadJobStatus({
|
|
521
|
+
libraryId: libraryId,
|
|
522
|
+
objectId: objectId,
|
|
523
|
+
writeToken: writeToken,
|
|
524
|
+
uploadId: id,
|
|
525
|
+
jobId: jobId
|
|
526
|
+
});
|
|
527
|
+
|
|
528
|
+
case 10:
|
|
529
|
+
job = _context3.sent;
|
|
530
|
+
f = 0;
|
|
531
|
+
|
|
532
|
+
case 12:
|
|
533
|
+
if (!(f < job.files.length)) {
|
|
534
|
+
_context3.next = 25;
|
|
535
|
+
break;
|
|
536
|
+
}
|
|
537
|
+
|
|
538
|
+
_fileInfo = job.files[f];
|
|
539
|
+
data = void 0;
|
|
540
|
+
|
|
541
|
+
if (typeof fileDataMap[_fileInfo.path] === "number") {
|
|
542
|
+
// File descriptor - Read data from file
|
|
543
|
+
data = Buffer.alloc(_fileInfo.len);
|
|
544
|
+
fs.readSync(fileDataMap[_fileInfo.path], data, 0, _fileInfo.len, _fileInfo.off);
|
|
545
|
+
} else {
|
|
546
|
+
// Full data - Slice requested chunk
|
|
547
|
+
data = fileDataMap[_fileInfo.path].slice(_fileInfo.off, _fileInfo.off + _fileInfo.len);
|
|
548
|
+
}
|
|
549
|
+
|
|
550
|
+
if (!(encryption === "cgck")) {
|
|
551
|
+
_context3.next = 20;
|
|
552
|
+
break;
|
|
553
|
+
}
|
|
554
|
+
|
|
555
|
+
_context3.next = 19;
|
|
556
|
+
return _this.Crypto.Encrypt(conk, data);
|
|
557
|
+
|
|
558
|
+
case 19:
|
|
559
|
+
data = _context3.sent;
|
|
560
|
+
|
|
561
|
+
case 20:
|
|
562
|
+
job.files[f].data = data;
|
|
563
|
+
prepared += _fileInfo.len;
|
|
564
|
+
|
|
565
|
+
case 22:
|
|
566
|
+
f++;
|
|
567
|
+
_context3.next = 12;
|
|
568
|
+
break;
|
|
569
|
+
|
|
570
|
+
case 25:
|
|
571
|
+
jobSpecs[j] = job; // Wait for a bit to let upload start
|
|
572
|
+
|
|
573
|
+
_context3.next = 28;
|
|
574
|
+
return new Promise(function (resolve) {
|
|
575
|
+
return setTimeout(resolve, 50);
|
|
576
|
+
});
|
|
577
|
+
|
|
578
|
+
case 28:
|
|
579
|
+
j++;
|
|
580
|
+
_context3.next = 1;
|
|
581
|
+
break;
|
|
582
|
+
|
|
583
|
+
case 31:
|
|
584
|
+
case "end":
|
|
585
|
+
return _context3.stop();
|
|
528
586
|
}
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
587
|
+
}
|
|
588
|
+
}, _callee3);
|
|
589
|
+
}));
|
|
590
|
+
|
|
591
|
+
return function PrepareJobs() {
|
|
592
|
+
return _ref7.apply(this, arguments);
|
|
593
|
+
};
|
|
594
|
+
}();
|
|
595
|
+
|
|
596
|
+
UploadJob = /*#__PURE__*/function () {
|
|
597
|
+
var _ref8 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4(jobId, j) {
|
|
598
|
+
var jobSpec, files, f, _fileInfo2;
|
|
599
|
+
|
|
600
|
+
return _regeneratorRuntime.wrap(function _callee4$(_context4) {
|
|
601
|
+
while (1) {
|
|
602
|
+
switch (_context4.prev = _context4.next) {
|
|
603
|
+
case 0:
|
|
604
|
+
if (jobSpecs[j]) {
|
|
605
|
+
_context4.next = 5;
|
|
606
|
+
break;
|
|
607
|
+
}
|
|
608
|
+
|
|
609
|
+
_context4.next = 3;
|
|
610
|
+
return new Promise(function (resolve) {
|
|
611
|
+
return setTimeout(resolve, 500);
|
|
612
|
+
});
|
|
613
|
+
|
|
614
|
+
case 3:
|
|
615
|
+
_context4.next = 0;
|
|
616
|
+
break;
|
|
617
|
+
|
|
618
|
+
case 5:
|
|
619
|
+
jobSpec = jobSpecs[j];
|
|
620
|
+
files = jobSpec.files; // Upload each item
|
|
621
|
+
|
|
622
|
+
f = 0;
|
|
623
|
+
|
|
624
|
+
case 8:
|
|
625
|
+
if (!(f < files.length)) {
|
|
626
|
+
_context4.next = 18;
|
|
627
|
+
break;
|
|
628
|
+
}
|
|
629
|
+
|
|
630
|
+
_fileInfo2 = files[f];
|
|
631
|
+
_context4.next = 12;
|
|
632
|
+
return _this.UploadFileData({
|
|
633
|
+
libraryId: libraryId,
|
|
634
|
+
objectId: objectId,
|
|
635
|
+
writeToken: writeToken,
|
|
636
|
+
uploadId: id,
|
|
637
|
+
jobId: jobId,
|
|
638
|
+
fileData: _fileInfo2.data
|
|
639
|
+
});
|
|
640
|
+
|
|
641
|
+
case 12:
|
|
642
|
+
delete jobSpecs[j].files[f].data;
|
|
643
|
+
uploaded += _fileInfo2.len;
|
|
644
|
+
|
|
645
|
+
if (callback) {
|
|
646
|
+
progress[_fileInfo2.path] = _objectSpread(_objectSpread({}, progress[_fileInfo2.path]), {}, {
|
|
647
|
+
uploaded: progress[_fileInfo2.path].uploaded + _fileInfo2.len
|
|
648
|
+
});
|
|
649
|
+
callback(progress);
|
|
650
|
+
}
|
|
651
|
+
|
|
652
|
+
case 15:
|
|
653
|
+
f++;
|
|
654
|
+
_context4.next = 8;
|
|
655
|
+
break;
|
|
656
|
+
|
|
657
|
+
case 18:
|
|
658
|
+
case "end":
|
|
659
|
+
return _context4.stop();
|
|
547
660
|
}
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
661
|
+
}
|
|
662
|
+
}, _callee4);
|
|
663
|
+
}));
|
|
664
|
+
|
|
665
|
+
return function UploadJob(_x4, _x5) {
|
|
666
|
+
return _ref8.apply(this, arguments);
|
|
667
|
+
};
|
|
668
|
+
}(); // Preparing jobs is done asyncronously
|
|
669
|
+
|
|
670
|
+
|
|
671
|
+
PrepareJobs(); // Upload the first several chunks in sequence, to determine average upload rate
|
|
672
|
+
|
|
673
|
+
rateTestJobs = Math.min(3, jobs.length);
|
|
674
|
+
rates = [];
|
|
675
|
+
j = 0;
|
|
676
|
+
|
|
677
|
+
case 30:
|
|
678
|
+
if (!(j < rateTestJobs)) {
|
|
679
|
+
_context6.next = 40;
|
|
680
|
+
break;
|
|
681
|
+
}
|
|
682
|
+
|
|
683
|
+
start = new Date().getTime();
|
|
684
|
+
_context6.next = 34;
|
|
685
|
+
return UploadJob(jobs[j], j);
|
|
686
|
+
|
|
687
|
+
case 34:
|
|
688
|
+
elapsed = (new Date().getTime() - start) / 1000;
|
|
689
|
+
size = jobSpecs[j].files.map(function (file) {
|
|
690
|
+
return file.len;
|
|
691
|
+
}).reduce(function (length, total) {
|
|
692
|
+
return length + total;
|
|
693
|
+
}, 0);
|
|
694
|
+
rates.push(size / elapsed / (1024 * 1024));
|
|
695
|
+
|
|
696
|
+
case 37:
|
|
697
|
+
j++;
|
|
698
|
+
_context6.next = 30;
|
|
571
699
|
break;
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
_context5.next = 2;
|
|
601
|
-
break;
|
|
700
|
+
|
|
701
|
+
case 40:
|
|
702
|
+
averageRate = rates.reduce(function (mbps, total) {
|
|
703
|
+
return mbps + total;
|
|
704
|
+
}, 0) / rateTestJobs; // Upload remaining jobs in parallel
|
|
705
|
+
|
|
706
|
+
concurrentUploads = Math.min(5, Math.ceil(averageRate / 2));
|
|
707
|
+
_context6.next = 44;
|
|
708
|
+
return this.utils.LimitedMap(concurrentUploads, jobs, /*#__PURE__*/function () {
|
|
709
|
+
var _ref9 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee5(jobId, j) {
|
|
710
|
+
return _regeneratorRuntime.wrap(function _callee5$(_context5) {
|
|
711
|
+
while (1) {
|
|
712
|
+
switch (_context5.prev = _context5.next) {
|
|
713
|
+
case 0:
|
|
714
|
+
if (!(j < rateTestJobs)) {
|
|
715
|
+
_context5.next = 2;
|
|
716
|
+
break;
|
|
717
|
+
}
|
|
718
|
+
|
|
719
|
+
return _context5.abrupt("return");
|
|
720
|
+
|
|
721
|
+
case 2:
|
|
722
|
+
_context5.next = 4;
|
|
723
|
+
return UploadJob(jobId, j);
|
|
724
|
+
|
|
725
|
+
case 4:
|
|
726
|
+
case "end":
|
|
727
|
+
return _context5.stop();
|
|
602
728
|
}
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
}());
|
|
617
|
-
case 44:
|
|
618
|
-
case "end":
|
|
619
|
-
return _context6.stop();
|
|
729
|
+
}
|
|
730
|
+
}, _callee5);
|
|
731
|
+
}));
|
|
732
|
+
|
|
733
|
+
return function (_x6, _x7) {
|
|
734
|
+
return _ref9.apply(this, arguments);
|
|
735
|
+
};
|
|
736
|
+
}());
|
|
737
|
+
|
|
738
|
+
case 44:
|
|
739
|
+
case "end":
|
|
740
|
+
return _context6.stop();
|
|
741
|
+
}
|
|
620
742
|
}
|
|
621
743
|
}, _callee6, this);
|
|
622
744
|
}));
|
|
745
|
+
|
|
623
746
|
return function (_x3) {
|
|
624
747
|
return _ref6.apply(this, arguments);
|
|
625
748
|
};
|
|
626
749
|
}();
|
|
750
|
+
|
|
627
751
|
exports.CreateFileUploadJob = /*#__PURE__*/function () {
|
|
628
752
|
var _ref11 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee7(_ref10) {
|
|
629
753
|
var libraryId, objectId, writeToken, ops, _ref10$defaults, defaults, _ref10$encryption, encryption, body, path;
|
|
754
|
+
|
|
630
755
|
return _regeneratorRuntime.wrap(function _callee7$(_context7) {
|
|
631
|
-
while (1)
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
756
|
+
while (1) {
|
|
757
|
+
switch (_context7.prev = _context7.next) {
|
|
758
|
+
case 0:
|
|
759
|
+
libraryId = _ref10.libraryId, objectId = _ref10.objectId, writeToken = _ref10.writeToken, ops = _ref10.ops, _ref10$defaults = _ref10.defaults, defaults = _ref10$defaults === void 0 ? {} : _ref10$defaults, _ref10$encryption = _ref10.encryption, encryption = _ref10$encryption === void 0 ? "none" : _ref10$encryption;
|
|
760
|
+
ValidateParameters({
|
|
761
|
+
libraryId: libraryId,
|
|
762
|
+
objectId: objectId
|
|
763
|
+
});
|
|
764
|
+
ValidateWriteToken(writeToken);
|
|
765
|
+
this.Log("Creating file upload job: ".concat(libraryId, " ").concat(objectId, " ").concat(writeToken));
|
|
766
|
+
this.Log(ops);
|
|
767
|
+
|
|
768
|
+
if (encryption === "cgck") {
|
|
769
|
+
defaults.encryption = {
|
|
770
|
+
scheme: "cgck"
|
|
771
|
+
};
|
|
772
|
+
}
|
|
773
|
+
|
|
774
|
+
body = {
|
|
775
|
+
seq: 0,
|
|
776
|
+
seq_complete: true,
|
|
777
|
+
defaults: defaults,
|
|
778
|
+
ops: ops
|
|
644
779
|
};
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
return _context7.abrupt("return", _context7.t0.ResponseToJson.call(_context7.t0, _context7.t6));
|
|
675
|
-
case 18:
|
|
676
|
-
case "end":
|
|
677
|
-
return _context7.stop();
|
|
780
|
+
path = UrlJoin("q", writeToken, "file_jobs");
|
|
781
|
+
_context7.t0 = this.utils;
|
|
782
|
+
_context7.t1 = this.HttpClient;
|
|
783
|
+
_context7.next = 12;
|
|
784
|
+
return this.authClient.AuthorizationHeader({
|
|
785
|
+
libraryId: libraryId,
|
|
786
|
+
objectId: objectId,
|
|
787
|
+
update: true,
|
|
788
|
+
encryption: encryption
|
|
789
|
+
});
|
|
790
|
+
|
|
791
|
+
case 12:
|
|
792
|
+
_context7.t2 = _context7.sent;
|
|
793
|
+
_context7.t3 = path;
|
|
794
|
+
_context7.t4 = body;
|
|
795
|
+
_context7.t5 = {
|
|
796
|
+
headers: _context7.t2,
|
|
797
|
+
method: "POST",
|
|
798
|
+
path: _context7.t3,
|
|
799
|
+
body: _context7.t4,
|
|
800
|
+
failover: false
|
|
801
|
+
};
|
|
802
|
+
_context7.t6 = _context7.t1.Request.call(_context7.t1, _context7.t5);
|
|
803
|
+
return _context7.abrupt("return", _context7.t0.ResponseToJson.call(_context7.t0, _context7.t6));
|
|
804
|
+
|
|
805
|
+
case 18:
|
|
806
|
+
case "end":
|
|
807
|
+
return _context7.stop();
|
|
808
|
+
}
|
|
678
809
|
}
|
|
679
810
|
}, _callee7, this);
|
|
680
811
|
}));
|
|
812
|
+
|
|
681
813
|
return function (_x8) {
|
|
682
814
|
return _ref11.apply(this, arguments);
|
|
683
815
|
};
|
|
684
816
|
}();
|
|
817
|
+
|
|
685
818
|
exports.UploadStatus = /*#__PURE__*/function () {
|
|
686
819
|
var _ref13 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee8(_ref12) {
|
|
687
820
|
var libraryId, objectId, writeToken, uploadId, path;
|
|
688
821
|
return _regeneratorRuntime.wrap(function _callee8$(_context8) {
|
|
689
|
-
while (1)
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
822
|
+
while (1) {
|
|
823
|
+
switch (_context8.prev = _context8.next) {
|
|
824
|
+
case 0:
|
|
825
|
+
libraryId = _ref12.libraryId, objectId = _ref12.objectId, writeToken = _ref12.writeToken, uploadId = _ref12.uploadId;
|
|
826
|
+
ValidateParameters({
|
|
827
|
+
libraryId: libraryId,
|
|
828
|
+
objectId: objectId
|
|
829
|
+
});
|
|
830
|
+
ValidateWriteToken(writeToken);
|
|
831
|
+
path = UrlJoin("q", writeToken, "file_jobs", uploadId);
|
|
832
|
+
_context8.t0 = this.utils;
|
|
833
|
+
_context8.t1 = this.HttpClient;
|
|
834
|
+
_context8.next = 8;
|
|
835
|
+
return this.authClient.AuthorizationHeader({
|
|
836
|
+
libraryId: libraryId,
|
|
837
|
+
objectId: objectId,
|
|
838
|
+
update: true
|
|
839
|
+
});
|
|
840
|
+
|
|
841
|
+
case 8:
|
|
842
|
+
_context8.t2 = _context8.sent;
|
|
843
|
+
_context8.t3 = path;
|
|
844
|
+
_context8.t4 = {
|
|
845
|
+
headers: _context8.t2,
|
|
846
|
+
method: "GET",
|
|
847
|
+
path: _context8.t3,
|
|
848
|
+
failover: false
|
|
849
|
+
};
|
|
850
|
+
_context8.t5 = _context8.t1.Request.call(_context8.t1, _context8.t4);
|
|
851
|
+
return _context8.abrupt("return", _context8.t0.ResponseToJson.call(_context8.t0, _context8.t5));
|
|
852
|
+
|
|
853
|
+
case 13:
|
|
854
|
+
case "end":
|
|
855
|
+
return _context8.stop();
|
|
856
|
+
}
|
|
720
857
|
}
|
|
721
858
|
}, _callee8, this);
|
|
722
859
|
}));
|
|
860
|
+
|
|
723
861
|
return function (_x9) {
|
|
724
862
|
return _ref13.apply(this, arguments);
|
|
725
863
|
};
|
|
726
864
|
}();
|
|
865
|
+
|
|
727
866
|
exports.UploadJobStatus = /*#__PURE__*/function () {
|
|
728
867
|
var _ref15 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee9(_ref14) {
|
|
729
868
|
var libraryId, objectId, writeToken, uploadId, jobId, path;
|
|
730
869
|
return _regeneratorRuntime.wrap(function _callee9$(_context9) {
|
|
731
|
-
while (1)
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
870
|
+
while (1) {
|
|
871
|
+
switch (_context9.prev = _context9.next) {
|
|
872
|
+
case 0:
|
|
873
|
+
libraryId = _ref14.libraryId, objectId = _ref14.objectId, writeToken = _ref14.writeToken, uploadId = _ref14.uploadId, jobId = _ref14.jobId;
|
|
874
|
+
ValidateParameters({
|
|
875
|
+
libraryId: libraryId,
|
|
876
|
+
objectId: objectId
|
|
877
|
+
});
|
|
878
|
+
ValidateWriteToken(writeToken);
|
|
879
|
+
path = UrlJoin("q", writeToken, "file_jobs", uploadId, "uploads", jobId);
|
|
880
|
+
_context9.t0 = this.utils;
|
|
881
|
+
_context9.t1 = this.HttpClient;
|
|
882
|
+
_context9.next = 8;
|
|
883
|
+
return this.authClient.AuthorizationHeader({
|
|
884
|
+
libraryId: libraryId,
|
|
885
|
+
objectId: objectId,
|
|
886
|
+
update: true
|
|
887
|
+
});
|
|
888
|
+
|
|
889
|
+
case 8:
|
|
890
|
+
_context9.t2 = _context9.sent;
|
|
891
|
+
_context9.t3 = path;
|
|
892
|
+
_context9.t4 = {
|
|
893
|
+
headers: _context9.t2,
|
|
894
|
+
method: "GET",
|
|
895
|
+
path: _context9.t3,
|
|
896
|
+
failover: false
|
|
897
|
+
};
|
|
898
|
+
_context9.t5 = _context9.t1.Request.call(_context9.t1, _context9.t4);
|
|
899
|
+
return _context9.abrupt("return", _context9.t0.ResponseToJson.call(_context9.t0, _context9.t5));
|
|
900
|
+
|
|
901
|
+
case 13:
|
|
902
|
+
case "end":
|
|
903
|
+
return _context9.stop();
|
|
904
|
+
}
|
|
762
905
|
}
|
|
763
906
|
}, _callee9, this);
|
|
764
907
|
}));
|
|
908
|
+
|
|
765
909
|
return function (_x10) {
|
|
766
910
|
return _ref15.apply(this, arguments);
|
|
767
911
|
};
|
|
768
912
|
}();
|
|
913
|
+
|
|
769
914
|
exports.UploadFileData = /*#__PURE__*/function () {
|
|
770
915
|
var _ref17 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee10(_ref16) {
|
|
771
916
|
var libraryId, objectId, writeToken, uploadId, jobId, fileData, path;
|
|
772
917
|
return _regeneratorRuntime.wrap(function _callee10$(_context10) {
|
|
773
|
-
while (1)
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
918
|
+
while (1) {
|
|
919
|
+
switch (_context10.prev = _context10.next) {
|
|
920
|
+
case 0:
|
|
921
|
+
libraryId = _ref16.libraryId, objectId = _ref16.objectId, writeToken = _ref16.writeToken, uploadId = _ref16.uploadId, jobId = _ref16.jobId, fileData = _ref16.fileData;
|
|
922
|
+
ValidateParameters({
|
|
923
|
+
libraryId: libraryId,
|
|
924
|
+
objectId: objectId
|
|
925
|
+
});
|
|
926
|
+
ValidateWriteToken(writeToken);
|
|
927
|
+
path = UrlJoin("q", writeToken, "file_jobs", uploadId, jobId);
|
|
928
|
+
_context10.t0 = this.utils;
|
|
929
|
+
_context10.t1 = this.HttpClient;
|
|
930
|
+
_context10.t2 = path;
|
|
931
|
+
_context10.t3 = fileData;
|
|
932
|
+
_context10.t4 = _objectSpread;
|
|
933
|
+
_context10.t5 = {
|
|
934
|
+
"Content-type": "application/octet-stream"
|
|
935
|
+
};
|
|
936
|
+
_context10.next = 12;
|
|
937
|
+
return this.authClient.AuthorizationHeader({
|
|
938
|
+
libraryId: libraryId,
|
|
939
|
+
objectId: objectId,
|
|
940
|
+
update: true
|
|
941
|
+
});
|
|
942
|
+
|
|
943
|
+
case 12:
|
|
944
|
+
_context10.t6 = _context10.sent;
|
|
945
|
+
_context10.t7 = (0, _context10.t4)(_context10.t5, _context10.t6);
|
|
946
|
+
_context10.t8 = {
|
|
947
|
+
method: "POST",
|
|
948
|
+
path: _context10.t2,
|
|
949
|
+
body: _context10.t3,
|
|
950
|
+
bodyType: "BINARY",
|
|
951
|
+
headers: _context10.t7,
|
|
952
|
+
failover: false
|
|
953
|
+
};
|
|
954
|
+
_context10.t9 = _context10.t1.Request.call(_context10.t1, _context10.t8);
|
|
955
|
+
_context10.next = 18;
|
|
956
|
+
return _context10.t0.ResponseToJson.call(_context10.t0, _context10.t9);
|
|
957
|
+
|
|
958
|
+
case 18:
|
|
959
|
+
case "end":
|
|
960
|
+
return _context10.stop();
|
|
961
|
+
}
|
|
813
962
|
}
|
|
814
963
|
}, _callee10, this);
|
|
815
964
|
}));
|
|
965
|
+
|
|
816
966
|
return function (_x11) {
|
|
817
967
|
return _ref17.apply(this, arguments);
|
|
818
968
|
};
|
|
819
969
|
}();
|
|
970
|
+
|
|
820
971
|
exports.FinalizeUploadJob = /*#__PURE__*/function () {
|
|
821
972
|
var _ref19 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee11(_ref18) {
|
|
822
973
|
var libraryId, objectId, writeToken, path;
|
|
823
974
|
return _regeneratorRuntime.wrap(function _callee11$(_context11) {
|
|
824
|
-
while (1)
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
975
|
+
while (1) {
|
|
976
|
+
switch (_context11.prev = _context11.next) {
|
|
977
|
+
case 0:
|
|
978
|
+
libraryId = _ref18.libraryId, objectId = _ref18.objectId, writeToken = _ref18.writeToken;
|
|
979
|
+
ValidateParameters({
|
|
980
|
+
libraryId: libraryId,
|
|
981
|
+
objectId: objectId
|
|
982
|
+
});
|
|
983
|
+
ValidateWriteToken(writeToken);
|
|
984
|
+
this.Log("Finalizing upload job: ".concat(libraryId, " ").concat(objectId, " ").concat(writeToken));
|
|
985
|
+
path = UrlJoin("q", writeToken, "files");
|
|
986
|
+
_context11.t0 = this.HttpClient;
|
|
987
|
+
_context11.t1 = path;
|
|
988
|
+
_context11.next = 9;
|
|
989
|
+
return this.authClient.AuthorizationHeader({
|
|
990
|
+
libraryId: libraryId,
|
|
991
|
+
objectId: objectId,
|
|
992
|
+
update: true
|
|
993
|
+
});
|
|
994
|
+
|
|
995
|
+
case 9:
|
|
996
|
+
_context11.t2 = _context11.sent;
|
|
997
|
+
_context11.t3 = {
|
|
998
|
+
method: "POST",
|
|
999
|
+
path: _context11.t1,
|
|
1000
|
+
bodyType: "BINARY",
|
|
1001
|
+
headers: _context11.t2,
|
|
1002
|
+
failover: false
|
|
1003
|
+
};
|
|
1004
|
+
_context11.next = 13;
|
|
1005
|
+
return _context11.t0.Request.call(_context11.t0, _context11.t3);
|
|
1006
|
+
|
|
1007
|
+
case 13:
|
|
1008
|
+
case "end":
|
|
1009
|
+
return _context11.stop();
|
|
1010
|
+
}
|
|
856
1011
|
}
|
|
857
1012
|
}, _callee11, this);
|
|
858
1013
|
}));
|
|
1014
|
+
|
|
859
1015
|
return function (_x12) {
|
|
860
1016
|
return _ref19.apply(this, arguments);
|
|
861
1017
|
};
|
|
862
1018
|
}();
|
|
863
|
-
|
|
864
1019
|
/**
|
|
865
1020
|
* Create the specified directories on the specified object
|
|
866
1021
|
*
|
|
@@ -872,45 +1027,50 @@ exports.FinalizeUploadJob = /*#__PURE__*/function () {
|
|
|
872
1027
|
* @param {string} writeToken - Write token of the draft
|
|
873
1028
|
* @param {Array<string>} filePaths - List of file paths to create
|
|
874
1029
|
*/
|
|
1030
|
+
|
|
1031
|
+
|
|
875
1032
|
exports.CreateFileDirectories = /*#__PURE__*/function () {
|
|
876
1033
|
var _ref21 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee12(_ref20) {
|
|
877
1034
|
var libraryId, objectId, writeToken, filePaths, ops;
|
|
878
1035
|
return _regeneratorRuntime.wrap(function _callee12$(_context12) {
|
|
879
|
-
while (1)
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
1036
|
+
while (1) {
|
|
1037
|
+
switch (_context12.prev = _context12.next) {
|
|
1038
|
+
case 0:
|
|
1039
|
+
libraryId = _ref20.libraryId, objectId = _ref20.objectId, writeToken = _ref20.writeToken, filePaths = _ref20.filePaths;
|
|
1040
|
+
ValidateParameters({
|
|
1041
|
+
libraryId: libraryId,
|
|
1042
|
+
objectId: objectId
|
|
1043
|
+
});
|
|
1044
|
+
ValidateWriteToken(writeToken);
|
|
1045
|
+
this.Log("Creating Directories: ".concat(libraryId, " ").concat(objectId, " ").concat(writeToken));
|
|
1046
|
+
this.Log(filePaths);
|
|
1047
|
+
ops = filePaths.map(function (path) {
|
|
1048
|
+
return {
|
|
1049
|
+
op: "add",
|
|
1050
|
+
type: "directory",
|
|
1051
|
+
path: path
|
|
1052
|
+
};
|
|
1053
|
+
});
|
|
1054
|
+
_context12.next = 8;
|
|
1055
|
+
return this.CreateFileUploadJob({
|
|
1056
|
+
libraryId: libraryId,
|
|
1057
|
+
objectId: objectId,
|
|
1058
|
+
writeToken: writeToken,
|
|
1059
|
+
ops: ops
|
|
1060
|
+
});
|
|
1061
|
+
|
|
1062
|
+
case 8:
|
|
1063
|
+
case "end":
|
|
1064
|
+
return _context12.stop();
|
|
1065
|
+
}
|
|
906
1066
|
}
|
|
907
1067
|
}, _callee12, this);
|
|
908
1068
|
}));
|
|
1069
|
+
|
|
909
1070
|
return function (_x13) {
|
|
910
1071
|
return _ref21.apply(this, arguments);
|
|
911
1072
|
};
|
|
912
1073
|
}();
|
|
913
|
-
|
|
914
1074
|
/**
|
|
915
1075
|
* Delete the specified list of files/directories
|
|
916
1076
|
*
|
|
@@ -922,44 +1082,49 @@ exports.CreateFileDirectories = /*#__PURE__*/function () {
|
|
|
922
1082
|
* @param {string} writeToken - Write token of the draft
|
|
923
1083
|
* @param {Array<string>} filePaths - List of file paths to delete
|
|
924
1084
|
*/
|
|
1085
|
+
|
|
1086
|
+
|
|
925
1087
|
exports.DeleteFiles = /*#__PURE__*/function () {
|
|
926
1088
|
var _ref23 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee13(_ref22) {
|
|
927
1089
|
var libraryId, objectId, writeToken, filePaths, ops;
|
|
928
1090
|
return _regeneratorRuntime.wrap(function _callee13$(_context13) {
|
|
929
|
-
while (1)
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
1091
|
+
while (1) {
|
|
1092
|
+
switch (_context13.prev = _context13.next) {
|
|
1093
|
+
case 0:
|
|
1094
|
+
libraryId = _ref22.libraryId, objectId = _ref22.objectId, writeToken = _ref22.writeToken, filePaths = _ref22.filePaths;
|
|
1095
|
+
ValidateParameters({
|
|
1096
|
+
libraryId: libraryId,
|
|
1097
|
+
objectId: objectId
|
|
1098
|
+
});
|
|
1099
|
+
ValidateWriteToken(writeToken);
|
|
1100
|
+
this.Log("Deleting Files: ".concat(libraryId, " ").concat(objectId, " ").concat(writeToken));
|
|
1101
|
+
this.Log(filePaths);
|
|
1102
|
+
ops = filePaths.map(function (path) {
|
|
1103
|
+
return {
|
|
1104
|
+
op: "del",
|
|
1105
|
+
path: path
|
|
1106
|
+
};
|
|
1107
|
+
});
|
|
1108
|
+
_context13.next = 8;
|
|
1109
|
+
return this.CreateFileUploadJob({
|
|
1110
|
+
libraryId: libraryId,
|
|
1111
|
+
objectId: objectId,
|
|
1112
|
+
writeToken: writeToken,
|
|
1113
|
+
ops: ops
|
|
1114
|
+
});
|
|
1115
|
+
|
|
1116
|
+
case 8:
|
|
1117
|
+
case "end":
|
|
1118
|
+
return _context13.stop();
|
|
1119
|
+
}
|
|
955
1120
|
}
|
|
956
1121
|
}, _callee13, this);
|
|
957
1122
|
}));
|
|
1123
|
+
|
|
958
1124
|
return function (_x14) {
|
|
959
1125
|
return _ref23.apply(this, arguments);
|
|
960
1126
|
};
|
|
961
1127
|
}();
|
|
962
|
-
|
|
963
1128
|
/**
|
|
964
1129
|
* Download a file from a content object
|
|
965
1130
|
*
|
|
@@ -984,187 +1149,218 @@ exports.DeleteFiles = /*#__PURE__*/function () {
|
|
|
984
1149
|
*
|
|
985
1150
|
* @returns {Promise<ArrayBuffer> | undefined} - No return if chunked is specified, file data in the requested format otherwise
|
|
986
1151
|
*/
|
|
1152
|
+
|
|
1153
|
+
|
|
987
1154
|
exports.DownloadFile = /*#__PURE__*/function () {
|
|
988
1155
|
var _ref25 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee14(_ref24) {
|
|
989
1156
|
var libraryId,
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1157
|
+
objectId,
|
|
1158
|
+
versionHash,
|
|
1159
|
+
writeToken,
|
|
1160
|
+
filePath,
|
|
1161
|
+
_ref24$format,
|
|
1162
|
+
format,
|
|
1163
|
+
_ref24$chunked,
|
|
1164
|
+
chunked,
|
|
1165
|
+
chunkSize,
|
|
1166
|
+
_ref24$clientSideDecr,
|
|
1167
|
+
clientSideDecryption,
|
|
1168
|
+
callback,
|
|
1169
|
+
fileInfo,
|
|
1170
|
+
encrypted,
|
|
1171
|
+
encryption,
|
|
1172
|
+
path,
|
|
1173
|
+
headers,
|
|
1174
|
+
ownerCapKey,
|
|
1175
|
+
ownerCap,
|
|
1176
|
+
bytesTotal,
|
|
1177
|
+
_args14 = arguments;
|
|
1178
|
+
|
|
1011
1179
|
return _regeneratorRuntime.wrap(function _callee14$(_context14) {
|
|
1012
|
-
while (1)
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
objectId: objectId,
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1180
|
+
while (1) {
|
|
1181
|
+
switch (_context14.prev = _context14.next) {
|
|
1182
|
+
case 0:
|
|
1183
|
+
libraryId = _ref24.libraryId, objectId = _ref24.objectId, versionHash = _ref24.versionHash, writeToken = _ref24.writeToken, filePath = _ref24.filePath, _ref24$format = _ref24.format, format = _ref24$format === void 0 ? "arrayBuffer" : _ref24$format, _ref24$chunked = _ref24.chunked, chunked = _ref24$chunked === void 0 ? false : _ref24$chunked, chunkSize = _ref24.chunkSize, _ref24$clientSideDecr = _ref24.clientSideDecryption, clientSideDecryption = _ref24$clientSideDecr === void 0 ? false : _ref24$clientSideDecr, callback = _ref24.callback;
|
|
1184
|
+
ValidateParameters({
|
|
1185
|
+
libraryId: libraryId,
|
|
1186
|
+
objectId: objectId,
|
|
1187
|
+
versionHash: versionHash
|
|
1188
|
+
});
|
|
1189
|
+
ValidatePresence("filePath", filePath);
|
|
1190
|
+
|
|
1191
|
+
if (versionHash) {
|
|
1192
|
+
objectId = this.utils.DecodeVersionHash(versionHash).objectId;
|
|
1193
|
+
}
|
|
1194
|
+
|
|
1195
|
+
_context14.next = 6;
|
|
1196
|
+
return this.ContentObjectMetadata({
|
|
1197
|
+
libraryId: libraryId,
|
|
1198
|
+
objectId: objectId,
|
|
1199
|
+
versionHash: versionHash,
|
|
1200
|
+
writeToken: writeToken,
|
|
1201
|
+
metadataSubtree: UrlJoin("files", filePath)
|
|
1202
|
+
});
|
|
1203
|
+
|
|
1204
|
+
case 6:
|
|
1205
|
+
fileInfo = _context14.sent;
|
|
1206
|
+
encrypted = fileInfo && fileInfo["."].encryption && fileInfo["."].encryption.scheme === "cgck";
|
|
1207
|
+
encryption = encrypted ? "cgck" : undefined;
|
|
1208
|
+
path = encrypted && !clientSideDecryption ? UrlJoin("q", writeToken || versionHash || objectId, "rep", "files_download", filePath) : UrlJoin("q", writeToken || versionHash || objectId, "files", filePath);
|
|
1209
|
+
_context14.next = 12;
|
|
1210
|
+
return this.authClient.AuthorizationHeader({
|
|
1211
|
+
libraryId: libraryId,
|
|
1212
|
+
objectId: objectId,
|
|
1213
|
+
versionHash: versionHash,
|
|
1214
|
+
encryption: encryption
|
|
1215
|
+
});
|
|
1216
|
+
|
|
1217
|
+
case 12:
|
|
1218
|
+
headers = _context14.sent;
|
|
1219
|
+
headers.Accept = "*/*"; // If not owner, indicate re-encryption
|
|
1220
|
+
|
|
1221
|
+
ownerCapKey = "eluv.caps.iusr".concat(this.utils.AddressToHash(this.signer.address));
|
|
1222
|
+
_context14.next = 17;
|
|
1223
|
+
return this.ContentObjectMetadata({
|
|
1224
|
+
libraryId: libraryId,
|
|
1225
|
+
objectId: objectId,
|
|
1226
|
+
metadataSubtree: ownerCapKey
|
|
1227
|
+
});
|
|
1228
|
+
|
|
1229
|
+
case 17:
|
|
1230
|
+
ownerCap = _context14.sent;
|
|
1231
|
+
_context14.t1 = encrypted;
|
|
1232
|
+
|
|
1233
|
+
if (!_context14.t1) {
|
|
1234
|
+
_context14.next = 26;
|
|
1235
|
+
break;
|
|
1236
|
+
}
|
|
1237
|
+
|
|
1238
|
+
_context14.t2 = this.utils;
|
|
1239
|
+
_context14.t3 = this.signer.address;
|
|
1240
|
+
_context14.next = 24;
|
|
1241
|
+
return this.ContentObjectOwner({
|
|
1242
|
+
objectId: objectId
|
|
1243
|
+
});
|
|
1244
|
+
|
|
1245
|
+
case 24:
|
|
1246
|
+
_context14.t4 = _context14.sent;
|
|
1247
|
+
_context14.t1 = !_context14.t2.EqualAddress.call(_context14.t2, _context14.t3, _context14.t4);
|
|
1248
|
+
|
|
1249
|
+
case 26:
|
|
1250
|
+
_context14.t0 = _context14.t1;
|
|
1251
|
+
|
|
1252
|
+
if (!_context14.t0) {
|
|
1253
|
+
_context14.next = 29;
|
|
1254
|
+
break;
|
|
1255
|
+
}
|
|
1256
|
+
|
|
1257
|
+
_context14.t0 = !ownerCap;
|
|
1258
|
+
|
|
1259
|
+
case 29:
|
|
1260
|
+
if (!_context14.t0) {
|
|
1261
|
+
_context14.next = 31;
|
|
1262
|
+
break;
|
|
1263
|
+
}
|
|
1264
|
+
|
|
1265
|
+
headers["X-Content-Fabric-Decryption-Mode"] = "reencrypt";
|
|
1266
|
+
|
|
1267
|
+
case 31:
|
|
1268
|
+
// If using server side decryption, specify in header
|
|
1269
|
+
if (encrypted && !clientSideDecryption) {
|
|
1270
|
+
headers["X-Content-Fabric-Decryption-Mode"] = "decrypt"; // rep/files_download endpoint doesn't currently support Range header
|
|
1271
|
+
|
|
1272
|
+
chunkSize = Number.MAX_SAFE_INTEGER;
|
|
1273
|
+
}
|
|
1274
|
+
|
|
1275
|
+
bytesTotal = fileInfo["."].size;
|
|
1276
|
+
|
|
1277
|
+
if (!(encrypted && clientSideDecryption)) {
|
|
1278
|
+
_context14.next = 51;
|
|
1279
|
+
break;
|
|
1280
|
+
}
|
|
1281
|
+
|
|
1282
|
+
_context14.t5 = this;
|
|
1283
|
+
_context14.next = 37;
|
|
1284
|
+
return this.EncryptionConk({
|
|
1285
|
+
libraryId: libraryId,
|
|
1286
|
+
objectId: objectId,
|
|
1287
|
+
versionHash: versionHash,
|
|
1288
|
+
download: true
|
|
1289
|
+
});
|
|
1290
|
+
|
|
1291
|
+
case 37:
|
|
1292
|
+
_context14.t6 = _context14.sent;
|
|
1293
|
+
_context14.t7 = path;
|
|
1294
|
+
_context14.t8 = bytesTotal;
|
|
1295
|
+
_context14.t9 = headers;
|
|
1296
|
+
_context14.t10 = callback;
|
|
1297
|
+
_context14.t11 = format;
|
|
1298
|
+
_context14.t12 = clientSideDecryption;
|
|
1299
|
+
_context14.t13 = chunked;
|
|
1300
|
+
_context14.t14 = {
|
|
1301
|
+
conk: _context14.t6,
|
|
1302
|
+
downloadPath: _context14.t7,
|
|
1303
|
+
bytesTotal: _context14.t8,
|
|
1304
|
+
headers: _context14.t9,
|
|
1305
|
+
callback: _context14.t10,
|
|
1306
|
+
format: _context14.t11,
|
|
1307
|
+
clientSideDecryption: _context14.t12,
|
|
1308
|
+
chunked: _context14.t13
|
|
1309
|
+
};
|
|
1310
|
+
_context14.next = 48;
|
|
1311
|
+
return _context14.t5.DownloadEncrypted.call(_context14.t5, _context14.t14);
|
|
1312
|
+
|
|
1313
|
+
case 48:
|
|
1314
|
+
return _context14.abrupt("return", _context14.sent);
|
|
1315
|
+
|
|
1316
|
+
case 51:
|
|
1317
|
+
if (!chunkSize) {
|
|
1318
|
+
chunkSize = 10000000;
|
|
1319
|
+
}
|
|
1320
|
+
|
|
1321
|
+
_context14.prev = 52;
|
|
1322
|
+
_context14.next = 55;
|
|
1323
|
+
return this.Download({
|
|
1324
|
+
downloadPath: path,
|
|
1325
|
+
bytesTotal: bytesTotal,
|
|
1326
|
+
headers: headers,
|
|
1327
|
+
callback: callback,
|
|
1328
|
+
format: format,
|
|
1329
|
+
chunked: chunked,
|
|
1330
|
+
chunkSize: chunkSize
|
|
1331
|
+
});
|
|
1332
|
+
|
|
1333
|
+
case 55:
|
|
1334
|
+
return _context14.abrupt("return", _context14.sent);
|
|
1335
|
+
|
|
1336
|
+
case 58:
|
|
1337
|
+
_context14.prev = 58;
|
|
1338
|
+
_context14.t15 = _context14["catch"](52);
|
|
1339
|
+
|
|
1340
|
+
if (!(encrypted && !clientSideDecryption)) {
|
|
1341
|
+
_context14.next = 62;
|
|
1342
|
+
break;
|
|
1343
|
+
}
|
|
1344
|
+
|
|
1345
|
+
return _context14.abrupt("return", this.DownloadFile(_objectSpread(_objectSpread({}, _args14[0]), {}, {
|
|
1346
|
+
clientSideDecryption: true
|
|
1347
|
+
})));
|
|
1348
|
+
|
|
1349
|
+
case 62:
|
|
1350
|
+
throw _context14.t15;
|
|
1351
|
+
|
|
1352
|
+
case 63:
|
|
1353
|
+
case "end":
|
|
1354
|
+
return _context14.stop();
|
|
1355
|
+
}
|
|
1160
1356
|
}
|
|
1161
1357
|
}, _callee14, this, [[52, 58]]);
|
|
1162
1358
|
}));
|
|
1359
|
+
|
|
1163
1360
|
return function (_x15) {
|
|
1164
1361
|
return _ref25.apply(this, arguments);
|
|
1165
1362
|
};
|
|
1166
1363
|
}();
|
|
1167
|
-
|
|
1168
1364
|
/* Parts */
|
|
1169
1365
|
|
|
1170
1366
|
/**
|
|
@@ -1179,56 +1375,65 @@ exports.DownloadFile = /*#__PURE__*/function () {
|
|
|
1179
1375
|
*
|
|
1180
1376
|
* @returns {Promise<Object>} - Response containing list of parts of the object
|
|
1181
1377
|
*/
|
|
1378
|
+
|
|
1379
|
+
|
|
1182
1380
|
exports.ContentParts = /*#__PURE__*/function () {
|
|
1183
1381
|
var _ref27 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee15(_ref26) {
|
|
1184
1382
|
var libraryId, objectId, versionHash, path, response;
|
|
1185
1383
|
return _regeneratorRuntime.wrap(function _callee15$(_context15) {
|
|
1186
|
-
while (1)
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1384
|
+
while (1) {
|
|
1385
|
+
switch (_context15.prev = _context15.next) {
|
|
1386
|
+
case 0:
|
|
1387
|
+
libraryId = _ref26.libraryId, objectId = _ref26.objectId, versionHash = _ref26.versionHash;
|
|
1388
|
+
ValidateParameters({
|
|
1389
|
+
libraryId: libraryId,
|
|
1390
|
+
objectId: objectId,
|
|
1391
|
+
versionHash: versionHash
|
|
1392
|
+
});
|
|
1393
|
+
this.Log("Retrieving parts: ".concat(libraryId, " ").concat(objectId || versionHash));
|
|
1394
|
+
|
|
1395
|
+
if (versionHash) {
|
|
1396
|
+
objectId = this.utils.DecodeVersionHash(versionHash).objectId;
|
|
1397
|
+
}
|
|
1398
|
+
|
|
1399
|
+
path = UrlJoin("q", versionHash || objectId, "parts");
|
|
1400
|
+
_context15.t0 = this.utils;
|
|
1401
|
+
_context15.t1 = this.HttpClient;
|
|
1402
|
+
_context15.next = 9;
|
|
1403
|
+
return this.authClient.AuthorizationHeader({
|
|
1404
|
+
libraryId: libraryId,
|
|
1405
|
+
objectId: objectId,
|
|
1406
|
+
versionHash: versionHash
|
|
1407
|
+
});
|
|
1408
|
+
|
|
1409
|
+
case 9:
|
|
1410
|
+
_context15.t2 = _context15.sent;
|
|
1411
|
+
_context15.t3 = path;
|
|
1412
|
+
_context15.t4 = {
|
|
1413
|
+
headers: _context15.t2,
|
|
1414
|
+
method: "GET",
|
|
1415
|
+
path: _context15.t3
|
|
1416
|
+
};
|
|
1417
|
+
_context15.t5 = _context15.t1.Request.call(_context15.t1, _context15.t4);
|
|
1418
|
+
_context15.next = 15;
|
|
1419
|
+
return _context15.t0.ResponseToJson.call(_context15.t0, _context15.t5);
|
|
1420
|
+
|
|
1421
|
+
case 15:
|
|
1422
|
+
response = _context15.sent;
|
|
1423
|
+
return _context15.abrupt("return", response.parts);
|
|
1424
|
+
|
|
1425
|
+
case 17:
|
|
1426
|
+
case "end":
|
|
1427
|
+
return _context15.stop();
|
|
1428
|
+
}
|
|
1224
1429
|
}
|
|
1225
1430
|
}, _callee15, this);
|
|
1226
1431
|
}));
|
|
1432
|
+
|
|
1227
1433
|
return function (_x16) {
|
|
1228
1434
|
return _ref27.apply(this, arguments);
|
|
1229
1435
|
};
|
|
1230
1436
|
}();
|
|
1231
|
-
|
|
1232
1437
|
/**
|
|
1233
1438
|
* Get information on a specific part
|
|
1234
1439
|
*
|
|
@@ -1242,56 +1447,65 @@ exports.ContentParts = /*#__PURE__*/function () {
|
|
|
1242
1447
|
*
|
|
1243
1448
|
* @returns {Promise<Object>} - Response containing information about the specified part
|
|
1244
1449
|
*/
|
|
1450
|
+
|
|
1451
|
+
|
|
1245
1452
|
exports.ContentPart = /*#__PURE__*/function () {
|
|
1246
1453
|
var _ref29 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee16(_ref28) {
|
|
1247
1454
|
var libraryId, objectId, versionHash, partHash, path;
|
|
1248
1455
|
return _regeneratorRuntime.wrap(function _callee16$(_context16) {
|
|
1249
|
-
while (1)
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1456
|
+
while (1) {
|
|
1457
|
+
switch (_context16.prev = _context16.next) {
|
|
1458
|
+
case 0:
|
|
1459
|
+
libraryId = _ref28.libraryId, objectId = _ref28.objectId, versionHash = _ref28.versionHash, partHash = _ref28.partHash;
|
|
1460
|
+
ValidateParameters({
|
|
1461
|
+
libraryId: libraryId,
|
|
1462
|
+
objectId: objectId,
|
|
1463
|
+
versionHash: versionHash
|
|
1464
|
+
});
|
|
1465
|
+
ValidatePartHash(partHash);
|
|
1466
|
+
this.Log("Retrieving part: ".concat(libraryId, " ").concat(objectId || versionHash, " ").concat(partHash));
|
|
1467
|
+
|
|
1468
|
+
if (versionHash) {
|
|
1469
|
+
objectId = this.utils.DecodeVersionHash(versionHash).objectId;
|
|
1470
|
+
}
|
|
1471
|
+
|
|
1472
|
+
path = UrlJoin("q", versionHash || objectId, "parts", partHash);
|
|
1473
|
+
_context16.t0 = this.utils;
|
|
1474
|
+
_context16.t1 = this.HttpClient;
|
|
1475
|
+
_context16.next = 10;
|
|
1476
|
+
return this.authClient.AuthorizationHeader({
|
|
1477
|
+
libraryId: libraryId,
|
|
1478
|
+
objectId: objectId,
|
|
1479
|
+
versionHash: versionHash
|
|
1480
|
+
});
|
|
1481
|
+
|
|
1482
|
+
case 10:
|
|
1483
|
+
_context16.t2 = _context16.sent;
|
|
1484
|
+
_context16.t3 = path;
|
|
1485
|
+
_context16.t4 = {
|
|
1486
|
+
headers: _context16.t2,
|
|
1487
|
+
method: "GET",
|
|
1488
|
+
path: _context16.t3
|
|
1489
|
+
};
|
|
1490
|
+
_context16.t5 = _context16.t1.Request.call(_context16.t1, _context16.t4);
|
|
1491
|
+
_context16.next = 16;
|
|
1492
|
+
return _context16.t0.ResponseToJson.call(_context16.t0, _context16.t5);
|
|
1493
|
+
|
|
1494
|
+
case 16:
|
|
1495
|
+
return _context16.abrupt("return", _context16.sent);
|
|
1496
|
+
|
|
1497
|
+
case 17:
|
|
1498
|
+
case "end":
|
|
1499
|
+
return _context16.stop();
|
|
1500
|
+
}
|
|
1287
1501
|
}
|
|
1288
1502
|
}, _callee16, this);
|
|
1289
1503
|
}));
|
|
1504
|
+
|
|
1290
1505
|
return function (_x17) {
|
|
1291
1506
|
return _ref29.apply(this, arguments);
|
|
1292
1507
|
};
|
|
1293
1508
|
}();
|
|
1294
|
-
|
|
1295
1509
|
/**
|
|
1296
1510
|
* Download a part from a content object. The fromByte and range parameters can be used to specify a
|
|
1297
1511
|
* specific section of the part to download.
|
|
@@ -1316,340 +1530,419 @@ exports.ContentPart = /*#__PURE__*/function () {
|
|
|
1316
1530
|
*
|
|
1317
1531
|
* @returns {Promise<ArrayBuffer> | undefined} - No return if chunked is specified, part data in the requested format otherwise
|
|
1318
1532
|
*/
|
|
1533
|
+
|
|
1534
|
+
|
|
1319
1535
|
exports.DownloadPart = /*#__PURE__*/function () {
|
|
1320
1536
|
var _ref31 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee17(_ref30) {
|
|
1321
1537
|
var libraryId, objectId, versionHash, writeToken, partHash, _ref30$format, format, _ref30$chunked, chunked, _ref30$chunkSize, chunkSize, callback, encrypted, encryption, path, headers, bytesTotal;
|
|
1538
|
+
|
|
1322
1539
|
return _regeneratorRuntime.wrap(function _callee17$(_context17) {
|
|
1323
|
-
while (1)
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
_context17.
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1540
|
+
while (1) {
|
|
1541
|
+
switch (_context17.prev = _context17.next) {
|
|
1542
|
+
case 0:
|
|
1543
|
+
libraryId = _ref30.libraryId, objectId = _ref30.objectId, versionHash = _ref30.versionHash, writeToken = _ref30.writeToken, partHash = _ref30.partHash, _ref30$format = _ref30.format, format = _ref30$format === void 0 ? "arrayBuffer" : _ref30$format, _ref30$chunked = _ref30.chunked, chunked = _ref30$chunked === void 0 ? false : _ref30$chunked, _ref30$chunkSize = _ref30.chunkSize, chunkSize = _ref30$chunkSize === void 0 ? 10000000 : _ref30$chunkSize, callback = _ref30.callback;
|
|
1544
|
+
ValidateParameters({
|
|
1545
|
+
libraryId: libraryId,
|
|
1546
|
+
objectId: objectId,
|
|
1547
|
+
versionHash: versionHash
|
|
1548
|
+
});
|
|
1549
|
+
ValidatePartHash(partHash);
|
|
1550
|
+
|
|
1551
|
+
if (versionHash) {
|
|
1552
|
+
objectId = this.utils.DecodeVersionHash(versionHash).objectId;
|
|
1553
|
+
}
|
|
1554
|
+
|
|
1555
|
+
encrypted = partHash.startsWith("hqpe");
|
|
1556
|
+
encryption = encrypted ? "cgck" : undefined;
|
|
1557
|
+
path = UrlJoin("q", writeToken || versionHash || objectId, "data", partHash);
|
|
1558
|
+
_context17.next = 9;
|
|
1559
|
+
return this.authClient.AuthorizationHeader({
|
|
1560
|
+
libraryId: libraryId,
|
|
1561
|
+
objectId: objectId,
|
|
1562
|
+
versionHash: versionHash,
|
|
1563
|
+
encryption: encryption,
|
|
1564
|
+
makeAccessRequest: true
|
|
1565
|
+
});
|
|
1566
|
+
|
|
1567
|
+
case 9:
|
|
1568
|
+
headers = _context17.sent;
|
|
1569
|
+
_context17.next = 12;
|
|
1570
|
+
return this.ContentPart({
|
|
1571
|
+
libraryId: libraryId,
|
|
1572
|
+
objectId: objectId,
|
|
1573
|
+
versionHash: versionHash,
|
|
1574
|
+
partHash: partHash
|
|
1575
|
+
});
|
|
1576
|
+
|
|
1577
|
+
case 12:
|
|
1578
|
+
bytesTotal = _context17.sent.part.size;
|
|
1579
|
+
|
|
1580
|
+
if (!encrypted) {
|
|
1581
|
+
_context17.next = 37;
|
|
1582
|
+
break;
|
|
1583
|
+
}
|
|
1584
|
+
|
|
1585
|
+
_context17.t0 = this.utils;
|
|
1586
|
+
_context17.t1 = this.signer.address;
|
|
1587
|
+
_context17.next = 18;
|
|
1588
|
+
return this.ContentObjectOwner({
|
|
1589
|
+
objectId: objectId
|
|
1590
|
+
});
|
|
1591
|
+
|
|
1592
|
+
case 18:
|
|
1593
|
+
_context17.t2 = _context17.sent;
|
|
1594
|
+
|
|
1595
|
+
if (_context17.t0.EqualAddress.call(_context17.t0, _context17.t1, _context17.t2)) {
|
|
1596
|
+
_context17.next = 21;
|
|
1597
|
+
break;
|
|
1598
|
+
}
|
|
1599
|
+
|
|
1600
|
+
headers["X-Content-Fabric-Decryption-Mode"] = "reencrypt";
|
|
1601
|
+
|
|
1602
|
+
case 21:
|
|
1603
|
+
_context17.t3 = this;
|
|
1604
|
+
_context17.next = 24;
|
|
1605
|
+
return this.EncryptionConk({
|
|
1606
|
+
libraryId: libraryId,
|
|
1607
|
+
objectId: objectId,
|
|
1608
|
+
download: true
|
|
1609
|
+
});
|
|
1610
|
+
|
|
1611
|
+
case 24:
|
|
1612
|
+
_context17.t4 = _context17.sent;
|
|
1613
|
+
_context17.t5 = path;
|
|
1614
|
+
_context17.t6 = bytesTotal;
|
|
1615
|
+
_context17.t7 = headers;
|
|
1616
|
+
_context17.t8 = callback;
|
|
1617
|
+
_context17.t9 = format;
|
|
1618
|
+
_context17.t10 = chunked;
|
|
1619
|
+
_context17.t11 = {
|
|
1620
|
+
conk: _context17.t4,
|
|
1621
|
+
downloadPath: _context17.t5,
|
|
1622
|
+
bytesTotal: _context17.t6,
|
|
1623
|
+
headers: _context17.t7,
|
|
1624
|
+
callback: _context17.t8,
|
|
1625
|
+
format: _context17.t9,
|
|
1626
|
+
chunked: _context17.t10
|
|
1627
|
+
};
|
|
1628
|
+
_context17.next = 34;
|
|
1629
|
+
return _context17.t3.DownloadEncrypted.call(_context17.t3, _context17.t11);
|
|
1630
|
+
|
|
1631
|
+
case 34:
|
|
1632
|
+
return _context17.abrupt("return", _context17.sent);
|
|
1633
|
+
|
|
1634
|
+
case 37:
|
|
1635
|
+
_context17.next = 39;
|
|
1636
|
+
return this.Download({
|
|
1637
|
+
downloadPath: path,
|
|
1638
|
+
bytesTotal: bytesTotal,
|
|
1639
|
+
headers: headers,
|
|
1640
|
+
callback: callback,
|
|
1641
|
+
format: format,
|
|
1642
|
+
chunked: chunked,
|
|
1643
|
+
chunkSize: chunkSize
|
|
1644
|
+
});
|
|
1645
|
+
|
|
1646
|
+
case 39:
|
|
1647
|
+
return _context17.abrupt("return", _context17.sent);
|
|
1648
|
+
|
|
1649
|
+
case 40:
|
|
1650
|
+
case "end":
|
|
1651
|
+
return _context17.stop();
|
|
1652
|
+
}
|
|
1418
1653
|
}
|
|
1419
1654
|
}, _callee17, this);
|
|
1420
1655
|
}));
|
|
1656
|
+
|
|
1421
1657
|
return function (_x18) {
|
|
1422
1658
|
return _ref31.apply(this, arguments);
|
|
1423
1659
|
};
|
|
1424
1660
|
}();
|
|
1661
|
+
|
|
1425
1662
|
exports.Download = /*#__PURE__*/function () {
|
|
1426
1663
|
var _ref33 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee18(_ref32) {
|
|
1427
1664
|
var downloadPath, headers, bytesTotal, _ref32$chunked, chunked, _ref32$chunkSize, chunkSize, callback, _ref32$format, format, outputChunks, bytesFinished, totalChunks, i, response;
|
|
1665
|
+
|
|
1428
1666
|
return _regeneratorRuntime.wrap(function _callee18$(_context18) {
|
|
1429
|
-
while (1)
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
_context18.next = 3;
|
|
1434
|
-
break;
|
|
1435
|
-
}
|
|
1436
|
-
throw Error("No callback specified for chunked download");
|
|
1437
|
-
case 3:
|
|
1438
|
-
if (!chunked) {
|
|
1439
|
-
outputChunks = [];
|
|
1440
|
-
}
|
|
1667
|
+
while (1) {
|
|
1668
|
+
switch (_context18.prev = _context18.next) {
|
|
1669
|
+
case 0:
|
|
1670
|
+
downloadPath = _ref32.downloadPath, headers = _ref32.headers, bytesTotal = _ref32.bytesTotal, _ref32$chunked = _ref32.chunked, chunked = _ref32$chunked === void 0 ? false : _ref32$chunked, _ref32$chunkSize = _ref32.chunkSize, chunkSize = _ref32$chunkSize === void 0 ? 2000000 : _ref32$chunkSize, callback = _ref32.callback, _ref32$format = _ref32.format, format = _ref32$format === void 0 ? "arrayBuffer" : _ref32$format;
|
|
1441
1671
|
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
_context18.t3 = _context18.sent;
|
|
1472
|
-
_context18.t4 = {
|
|
1473
|
-
bytesFinished: _context18.t1,
|
|
1474
|
-
bytesTotal: _context18.t2,
|
|
1475
|
-
chunk: _context18.t3
|
|
1476
|
-
};
|
|
1477
|
-
(0, _context18.t0)(_context18.t4);
|
|
1478
|
-
_context18.next = 32;
|
|
1479
|
-
break;
|
|
1480
|
-
case 24:
|
|
1481
|
-
_context18.t5 = outputChunks;
|
|
1482
|
-
_context18.t6 = Buffer;
|
|
1483
|
-
_context18.next = 28;
|
|
1484
|
-
return response.arrayBuffer();
|
|
1485
|
-
case 28:
|
|
1486
|
-
_context18.t7 = _context18.sent;
|
|
1487
|
-
_context18.t8 = _context18.t6.from.call(_context18.t6, _context18.t7);
|
|
1488
|
-
_context18.t5.push.call(_context18.t5, _context18.t8);
|
|
1489
|
-
if (callback) {
|
|
1490
|
-
callback({
|
|
1491
|
-
bytesFinished: bytesFinished,
|
|
1492
|
-
bytesTotal: bytesTotal
|
|
1672
|
+
if (!(chunked && !callback)) {
|
|
1673
|
+
_context18.next = 3;
|
|
1674
|
+
break;
|
|
1675
|
+
}
|
|
1676
|
+
|
|
1677
|
+
throw Error("No callback specified for chunked download");
|
|
1678
|
+
|
|
1679
|
+
case 3:
|
|
1680
|
+
if (!chunked) {
|
|
1681
|
+
outputChunks = [];
|
|
1682
|
+
} // Download file in chunks
|
|
1683
|
+
|
|
1684
|
+
|
|
1685
|
+
bytesFinished = 0;
|
|
1686
|
+
totalChunks = Math.ceil(bytesTotal / chunkSize);
|
|
1687
|
+
i = 0;
|
|
1688
|
+
|
|
1689
|
+
case 7:
|
|
1690
|
+
if (!(i < totalChunks)) {
|
|
1691
|
+
_context18.next = 35;
|
|
1692
|
+
break;
|
|
1693
|
+
}
|
|
1694
|
+
|
|
1695
|
+
headers["Range"] = "bytes=".concat(bytesFinished, "-").concat(bytesFinished + chunkSize - 1);
|
|
1696
|
+
_context18.next = 11;
|
|
1697
|
+
return this.HttpClient.Request({
|
|
1698
|
+
path: downloadPath,
|
|
1699
|
+
headers: headers,
|
|
1700
|
+
method: "GET"
|
|
1493
1701
|
});
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1702
|
+
|
|
1703
|
+
case 11:
|
|
1704
|
+
response = _context18.sent;
|
|
1705
|
+
bytesFinished = Math.min(bytesFinished + chunkSize, bytesTotal);
|
|
1706
|
+
|
|
1707
|
+
if (!chunked) {
|
|
1708
|
+
_context18.next = 24;
|
|
1709
|
+
break;
|
|
1710
|
+
}
|
|
1711
|
+
|
|
1712
|
+
_context18.t0 = callback;
|
|
1713
|
+
_context18.t1 = bytesFinished;
|
|
1714
|
+
_context18.t2 = bytesTotal;
|
|
1715
|
+
_context18.next = 19;
|
|
1716
|
+
return this.utils.ResponseToFormat(format, response);
|
|
1717
|
+
|
|
1718
|
+
case 19:
|
|
1719
|
+
_context18.t3 = _context18.sent;
|
|
1720
|
+
_context18.t4 = {
|
|
1721
|
+
bytesFinished: _context18.t1,
|
|
1722
|
+
bytesTotal: _context18.t2,
|
|
1723
|
+
chunk: _context18.t3
|
|
1724
|
+
};
|
|
1725
|
+
(0, _context18.t0)(_context18.t4);
|
|
1726
|
+
_context18.next = 32;
|
|
1502
1727
|
break;
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1728
|
+
|
|
1729
|
+
case 24:
|
|
1730
|
+
_context18.t5 = outputChunks;
|
|
1731
|
+
_context18.t6 = Buffer;
|
|
1732
|
+
_context18.next = 28;
|
|
1733
|
+
return response.arrayBuffer();
|
|
1734
|
+
|
|
1735
|
+
case 28:
|
|
1736
|
+
_context18.t7 = _context18.sent;
|
|
1737
|
+
_context18.t8 = _context18.t6.from.call(_context18.t6, _context18.t7);
|
|
1738
|
+
|
|
1739
|
+
_context18.t5.push.call(_context18.t5, _context18.t8);
|
|
1740
|
+
|
|
1741
|
+
if (callback) {
|
|
1742
|
+
callback({
|
|
1743
|
+
bytesFinished: bytesFinished,
|
|
1744
|
+
bytesTotal: bytesTotal
|
|
1745
|
+
});
|
|
1746
|
+
}
|
|
1747
|
+
|
|
1748
|
+
case 32:
|
|
1749
|
+
i++;
|
|
1750
|
+
_context18.next = 7;
|
|
1751
|
+
break;
|
|
1752
|
+
|
|
1753
|
+
case 35:
|
|
1754
|
+
if (chunked) {
|
|
1755
|
+
_context18.next = 39;
|
|
1756
|
+
break;
|
|
1757
|
+
}
|
|
1758
|
+
|
|
1759
|
+
_context18.next = 38;
|
|
1760
|
+
return this.utils.ResponseToFormat(format, new Response(Buffer.concat(outputChunks)));
|
|
1761
|
+
|
|
1762
|
+
case 38:
|
|
1763
|
+
return _context18.abrupt("return", _context18.sent);
|
|
1764
|
+
|
|
1765
|
+
case 39:
|
|
1766
|
+
case "end":
|
|
1767
|
+
return _context18.stop();
|
|
1768
|
+
}
|
|
1511
1769
|
}
|
|
1512
1770
|
}, _callee18, this);
|
|
1513
1771
|
}));
|
|
1772
|
+
|
|
1514
1773
|
return function (_x19) {
|
|
1515
1774
|
return _ref33.apply(this, arguments);
|
|
1516
1775
|
};
|
|
1517
1776
|
}();
|
|
1777
|
+
|
|
1518
1778
|
exports.DownloadEncrypted = /*#__PURE__*/function () {
|
|
1519
1779
|
var _ref35 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee20(_ref34) {
|
|
1520
1780
|
var _this2 = this;
|
|
1781
|
+
|
|
1521
1782
|
var conk, downloadPath, bytesTotal, headers, callback, _ref34$format, format, _ref34$chunked, chunked, isReencryption, chunkSize, bytesFinished, outputChunks, stream, totalChunks, i, response;
|
|
1783
|
+
|
|
1522
1784
|
return _regeneratorRuntime.wrap(function _callee20$(_context20) {
|
|
1523
|
-
while (1)
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
|
|
1564
|
-
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
|
|
1572
|
-
|
|
1573
|
-
|
|
1574
|
-
|
|
1575
|
-
|
|
1576
|
-
|
|
1577
|
-
|
|
1578
|
-
|
|
1579
|
-
|
|
1580
|
-
|
|
1581
|
-
|
|
1582
|
-
|
|
1785
|
+
while (1) {
|
|
1786
|
+
switch (_context20.prev = _context20.next) {
|
|
1787
|
+
case 0:
|
|
1788
|
+
conk = _ref34.conk, downloadPath = _ref34.downloadPath, bytesTotal = _ref34.bytesTotal, headers = _ref34.headers, callback = _ref34.callback, _ref34$format = _ref34.format, format = _ref34$format === void 0 ? "arrayBuffer" : _ref34$format, _ref34$chunked = _ref34.chunked, chunked = _ref34$chunked === void 0 ? false : _ref34$chunked;
|
|
1789
|
+
|
|
1790
|
+
if (!(chunked && !callback)) {
|
|
1791
|
+
_context20.next = 3;
|
|
1792
|
+
break;
|
|
1793
|
+
}
|
|
1794
|
+
|
|
1795
|
+
throw Error("No callback specified for chunked download");
|
|
1796
|
+
|
|
1797
|
+
case 3:
|
|
1798
|
+
// Must align chunk size with encryption block size
|
|
1799
|
+
isReencryption = conk.public_key.startsWith("ktpk");
|
|
1800
|
+
chunkSize = this.Crypto.EncryptedBlockSize(1000000, isReencryption);
|
|
1801
|
+
bytesFinished = 0;
|
|
1802
|
+
format = format.toLowerCase();
|
|
1803
|
+
outputChunks = []; // Set up decryption stream
|
|
1804
|
+
|
|
1805
|
+
_context20.next = 10;
|
|
1806
|
+
return this.Crypto.OpenDecryptionStream(conk);
|
|
1807
|
+
|
|
1808
|
+
case 10:
|
|
1809
|
+
stream = _context20.sent;
|
|
1810
|
+
stream.on("data", /*#__PURE__*/function () {
|
|
1811
|
+
var _ref36 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee19(chunk) {
|
|
1812
|
+
var arrayBuffer;
|
|
1813
|
+
return _regeneratorRuntime.wrap(function _callee19$(_context19) {
|
|
1814
|
+
while (1) {
|
|
1815
|
+
switch (_context19.prev = _context19.next) {
|
|
1816
|
+
case 0:
|
|
1817
|
+
if (!chunked) {
|
|
1818
|
+
_context19.next = 13;
|
|
1819
|
+
break;
|
|
1820
|
+
}
|
|
1821
|
+
|
|
1822
|
+
if (!(format !== "buffer")) {
|
|
1823
|
+
_context19.next = 10;
|
|
1824
|
+
break;
|
|
1825
|
+
}
|
|
1826
|
+
|
|
1827
|
+
arrayBuffer = chunk.buffer.slice(chunk.byteOffset, chunk.byteOffset + chunk.byteLength);
|
|
1828
|
+
|
|
1829
|
+
if (!(format === "arraybuffer")) {
|
|
1830
|
+
_context19.next = 7;
|
|
1831
|
+
break;
|
|
1832
|
+
}
|
|
1833
|
+
|
|
1834
|
+
chunk = arrayBuffer;
|
|
1835
|
+
_context19.next = 10;
|
|
1836
|
+
break;
|
|
1837
|
+
|
|
1838
|
+
case 7:
|
|
1839
|
+
_context19.next = 9;
|
|
1840
|
+
return _this2.utils.ResponseToFormat(format, new Response(arrayBuffer));
|
|
1841
|
+
|
|
1842
|
+
case 9:
|
|
1843
|
+
chunk = _context19.sent;
|
|
1844
|
+
|
|
1845
|
+
case 10:
|
|
1846
|
+
callback({
|
|
1847
|
+
bytesFinished: bytesFinished,
|
|
1848
|
+
bytesTotal: bytesTotal,
|
|
1849
|
+
chunk: chunk
|
|
1850
|
+
});
|
|
1851
|
+
_context19.next = 15;
|
|
1852
|
+
break;
|
|
1853
|
+
|
|
1854
|
+
case 13:
|
|
1855
|
+
if (callback) {
|
|
1856
|
+
callback({
|
|
1857
|
+
bytesFinished: bytesFinished,
|
|
1858
|
+
bytesTotal: bytesTotal
|
|
1859
|
+
});
|
|
1860
|
+
}
|
|
1861
|
+
|
|
1862
|
+
outputChunks.push(chunk);
|
|
1863
|
+
|
|
1864
|
+
case 15:
|
|
1865
|
+
case "end":
|
|
1866
|
+
return _context19.stop();
|
|
1583
1867
|
}
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
|
|
1589
|
-
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
path: downloadPath
|
|
1608
|
-
});
|
|
1609
|
-
case 18:
|
|
1610
|
-
response = _context20.sent;
|
|
1611
|
-
bytesFinished = Math.min(bytesFinished + chunkSize, bytesTotal);
|
|
1612
|
-
_context20.t0 = stream;
|
|
1613
|
-
_context20.t1 = Uint8Array;
|
|
1614
|
-
_context20.next = 24;
|
|
1615
|
-
return response.arrayBuffer();
|
|
1616
|
-
case 24:
|
|
1617
|
-
_context20.t2 = _context20.sent;
|
|
1618
|
-
_context20.t3 = new _context20.t1(_context20.t2);
|
|
1619
|
-
_context20.t0.write.call(_context20.t0, _context20.t3);
|
|
1620
|
-
case 27:
|
|
1621
|
-
i++;
|
|
1622
|
-
_context20.next = 14;
|
|
1623
|
-
break;
|
|
1624
|
-
case 30:
|
|
1625
|
-
// Wait for decryption to complete
|
|
1626
|
-
stream.end();
|
|
1627
|
-
_context20.next = 33;
|
|
1628
|
-
return new Promise(function (resolve) {
|
|
1629
|
-
return stream.on("finish", function () {
|
|
1630
|
-
resolve();
|
|
1868
|
+
}
|
|
1869
|
+
}, _callee19);
|
|
1870
|
+
}));
|
|
1871
|
+
|
|
1872
|
+
return function (_x21) {
|
|
1873
|
+
return _ref36.apply(this, arguments);
|
|
1874
|
+
};
|
|
1875
|
+
}());
|
|
1876
|
+
totalChunks = Math.ceil(bytesTotal / chunkSize);
|
|
1877
|
+
i = 0;
|
|
1878
|
+
|
|
1879
|
+
case 14:
|
|
1880
|
+
if (!(i < totalChunks)) {
|
|
1881
|
+
_context20.next = 30;
|
|
1882
|
+
break;
|
|
1883
|
+
}
|
|
1884
|
+
|
|
1885
|
+
headers["Range"] = "bytes=".concat(bytesFinished, "-").concat(bytesFinished + chunkSize - 1);
|
|
1886
|
+
_context20.next = 18;
|
|
1887
|
+
return this.HttpClient.Request({
|
|
1888
|
+
headers: headers,
|
|
1889
|
+
method: "GET",
|
|
1890
|
+
path: downloadPath
|
|
1631
1891
|
});
|
|
1632
|
-
|
|
1633
|
-
|
|
1634
|
-
|
|
1635
|
-
|
|
1892
|
+
|
|
1893
|
+
case 18:
|
|
1894
|
+
response = _context20.sent;
|
|
1895
|
+
bytesFinished = Math.min(bytesFinished + chunkSize, bytesTotal);
|
|
1896
|
+
_context20.t0 = stream;
|
|
1897
|
+
_context20.t1 = Uint8Array;
|
|
1898
|
+
_context20.next = 24;
|
|
1899
|
+
return response.arrayBuffer();
|
|
1900
|
+
|
|
1901
|
+
case 24:
|
|
1902
|
+
_context20.t2 = _context20.sent;
|
|
1903
|
+
_context20.t3 = new _context20.t1(_context20.t2);
|
|
1904
|
+
|
|
1905
|
+
_context20.t0.write.call(_context20.t0, _context20.t3);
|
|
1906
|
+
|
|
1907
|
+
case 27:
|
|
1908
|
+
i++;
|
|
1909
|
+
_context20.next = 14;
|
|
1636
1910
|
break;
|
|
1637
|
-
|
|
1638
|
-
|
|
1639
|
-
|
|
1640
|
-
|
|
1641
|
-
|
|
1642
|
-
|
|
1643
|
-
|
|
1644
|
-
|
|
1911
|
+
|
|
1912
|
+
case 30:
|
|
1913
|
+
// Wait for decryption to complete
|
|
1914
|
+
stream.end();
|
|
1915
|
+
_context20.next = 33;
|
|
1916
|
+
return new Promise(function (resolve) {
|
|
1917
|
+
return stream.on("finish", function () {
|
|
1918
|
+
resolve();
|
|
1919
|
+
});
|
|
1920
|
+
});
|
|
1921
|
+
|
|
1922
|
+
case 33:
|
|
1923
|
+
if (chunked) {
|
|
1924
|
+
_context20.next = 37;
|
|
1925
|
+
break;
|
|
1926
|
+
}
|
|
1927
|
+
|
|
1928
|
+
_context20.next = 36;
|
|
1929
|
+
return this.utils.ResponseToFormat(format, new Response(Buffer.concat(outputChunks)));
|
|
1930
|
+
|
|
1931
|
+
case 36:
|
|
1932
|
+
return _context20.abrupt("return", _context20.sent);
|
|
1933
|
+
|
|
1934
|
+
case 37:
|
|
1935
|
+
case "end":
|
|
1936
|
+
return _context20.stop();
|
|
1937
|
+
}
|
|
1645
1938
|
}
|
|
1646
1939
|
}, _callee20, this);
|
|
1647
1940
|
}));
|
|
1941
|
+
|
|
1648
1942
|
return function (_x20) {
|
|
1649
1943
|
return _ref35.apply(this, arguments);
|
|
1650
1944
|
};
|
|
1651
1945
|
}();
|
|
1652
|
-
|
|
1653
1946
|
/**
|
|
1654
1947
|
* Create a part upload draft
|
|
1655
1948
|
*
|
|
@@ -1663,56 +1956,63 @@ exports.DownloadEncrypted = /*#__PURE__*/function () {
|
|
|
1663
1956
|
*
|
|
1664
1957
|
* @returns {Promise<string>} - The part write token for the part draft
|
|
1665
1958
|
*/
|
|
1959
|
+
|
|
1960
|
+
|
|
1666
1961
|
exports.CreatePart = /*#__PURE__*/function () {
|
|
1667
1962
|
var _ref38 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee21(_ref37) {
|
|
1668
1963
|
var libraryId, objectId, writeToken, encryption, path, openResponse;
|
|
1669
1964
|
return _regeneratorRuntime.wrap(function _callee21$(_context21) {
|
|
1670
|
-
while (1)
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
|
-
|
|
1675
|
-
|
|
1676
|
-
|
|
1677
|
-
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
|
|
1683
|
-
|
|
1684
|
-
|
|
1685
|
-
|
|
1686
|
-
|
|
1687
|
-
|
|
1688
|
-
|
|
1689
|
-
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
-
|
|
1693
|
-
|
|
1694
|
-
|
|
1695
|
-
|
|
1696
|
-
|
|
1697
|
-
|
|
1698
|
-
|
|
1699
|
-
|
|
1700
|
-
|
|
1701
|
-
|
|
1702
|
-
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
|
|
1706
|
-
|
|
1707
|
-
|
|
1965
|
+
while (1) {
|
|
1966
|
+
switch (_context21.prev = _context21.next) {
|
|
1967
|
+
case 0:
|
|
1968
|
+
libraryId = _ref37.libraryId, objectId = _ref37.objectId, writeToken = _ref37.writeToken, encryption = _ref37.encryption;
|
|
1969
|
+
ValidateParameters({
|
|
1970
|
+
libraryId: libraryId,
|
|
1971
|
+
objectId: objectId
|
|
1972
|
+
});
|
|
1973
|
+
ValidateWriteToken(writeToken);
|
|
1974
|
+
path = UrlJoin("q", writeToken, "parts");
|
|
1975
|
+
_context21.t0 = this.utils;
|
|
1976
|
+
_context21.t1 = this.HttpClient;
|
|
1977
|
+
_context21.next = 8;
|
|
1978
|
+
return this.authClient.AuthorizationHeader({
|
|
1979
|
+
libraryId: libraryId,
|
|
1980
|
+
objectId: objectId,
|
|
1981
|
+
update: true,
|
|
1982
|
+
encryption: encryption
|
|
1983
|
+
});
|
|
1984
|
+
|
|
1985
|
+
case 8:
|
|
1986
|
+
_context21.t2 = _context21.sent;
|
|
1987
|
+
_context21.t3 = path;
|
|
1988
|
+
_context21.t4 = {
|
|
1989
|
+
headers: _context21.t2,
|
|
1990
|
+
method: "POST",
|
|
1991
|
+
path: _context21.t3,
|
|
1992
|
+
bodyType: "BINARY",
|
|
1993
|
+
body: "",
|
|
1994
|
+
failover: false
|
|
1995
|
+
};
|
|
1996
|
+
_context21.t5 = _context21.t1.Request.call(_context21.t1, _context21.t4);
|
|
1997
|
+
_context21.next = 14;
|
|
1998
|
+
return _context21.t0.ResponseToJson.call(_context21.t0, _context21.t5);
|
|
1999
|
+
|
|
2000
|
+
case 14:
|
|
2001
|
+
openResponse = _context21.sent;
|
|
2002
|
+
return _context21.abrupt("return", openResponse.part.write_token);
|
|
2003
|
+
|
|
2004
|
+
case 16:
|
|
2005
|
+
case "end":
|
|
2006
|
+
return _context21.stop();
|
|
2007
|
+
}
|
|
1708
2008
|
}
|
|
1709
2009
|
}, _callee21, this);
|
|
1710
2010
|
}));
|
|
2011
|
+
|
|
1711
2012
|
return function (_x22) {
|
|
1712
2013
|
return _ref38.apply(this, arguments);
|
|
1713
2014
|
};
|
|
1714
2015
|
}();
|
|
1715
|
-
|
|
1716
2016
|
/**
|
|
1717
2017
|
* Upload data to an open part draft
|
|
1718
2018
|
*
|
|
@@ -1728,71 +2028,82 @@ exports.CreatePart = /*#__PURE__*/function () {
|
|
|
1728
2028
|
*
|
|
1729
2029
|
* @returns {Promise<string>} - The part write token for the part draft
|
|
1730
2030
|
*/
|
|
2031
|
+
|
|
2032
|
+
|
|
1731
2033
|
exports.UploadPartChunk = /*#__PURE__*/function () {
|
|
1732
2034
|
var _ref40 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee22(_ref39) {
|
|
1733
2035
|
var libraryId, objectId, writeToken, partWriteToken, chunk, encryption, conk, path;
|
|
1734
2036
|
return _regeneratorRuntime.wrap(function _callee22$(_context22) {
|
|
1735
|
-
while (1)
|
|
1736
|
-
|
|
1737
|
-
|
|
1738
|
-
|
|
1739
|
-
|
|
1740
|
-
|
|
1741
|
-
|
|
1742
|
-
|
|
1743
|
-
|
|
1744
|
-
|
|
1745
|
-
|
|
1746
|
-
|
|
1747
|
-
|
|
1748
|
-
|
|
1749
|
-
|
|
1750
|
-
|
|
1751
|
-
|
|
1752
|
-
|
|
1753
|
-
|
|
1754
|
-
|
|
1755
|
-
|
|
1756
|
-
|
|
1757
|
-
|
|
1758
|
-
|
|
1759
|
-
|
|
1760
|
-
|
|
1761
|
-
|
|
1762
|
-
|
|
1763
|
-
|
|
1764
|
-
|
|
1765
|
-
|
|
1766
|
-
|
|
1767
|
-
|
|
1768
|
-
|
|
1769
|
-
|
|
1770
|
-
|
|
1771
|
-
|
|
1772
|
-
|
|
1773
|
-
|
|
1774
|
-
|
|
1775
|
-
|
|
1776
|
-
|
|
1777
|
-
|
|
1778
|
-
|
|
1779
|
-
|
|
1780
|
-
|
|
1781
|
-
|
|
1782
|
-
|
|
1783
|
-
|
|
1784
|
-
|
|
1785
|
-
|
|
1786
|
-
|
|
1787
|
-
|
|
2037
|
+
while (1) {
|
|
2038
|
+
switch (_context22.prev = _context22.next) {
|
|
2039
|
+
case 0:
|
|
2040
|
+
libraryId = _ref39.libraryId, objectId = _ref39.objectId, writeToken = _ref39.writeToken, partWriteToken = _ref39.partWriteToken, chunk = _ref39.chunk, encryption = _ref39.encryption;
|
|
2041
|
+
ValidateParameters({
|
|
2042
|
+
libraryId: libraryId,
|
|
2043
|
+
objectId: objectId
|
|
2044
|
+
});
|
|
2045
|
+
ValidateWriteToken(writeToken);
|
|
2046
|
+
|
|
2047
|
+
if (!(encryption && encryption !== "none")) {
|
|
2048
|
+
_context22.next = 10;
|
|
2049
|
+
break;
|
|
2050
|
+
}
|
|
2051
|
+
|
|
2052
|
+
_context22.next = 6;
|
|
2053
|
+
return this.EncryptionConk({
|
|
2054
|
+
libraryId: libraryId,
|
|
2055
|
+
objectId: objectId,
|
|
2056
|
+
writeToken: writeToken
|
|
2057
|
+
});
|
|
2058
|
+
|
|
2059
|
+
case 6:
|
|
2060
|
+
conk = _context22.sent;
|
|
2061
|
+
_context22.next = 9;
|
|
2062
|
+
return this.Crypto.Encrypt(conk, chunk);
|
|
2063
|
+
|
|
2064
|
+
case 9:
|
|
2065
|
+
chunk = _context22.sent;
|
|
2066
|
+
|
|
2067
|
+
case 10:
|
|
2068
|
+
path = UrlJoin("q", writeToken, "parts");
|
|
2069
|
+
_context22.t0 = this.utils;
|
|
2070
|
+
_context22.t1 = this.HttpClient;
|
|
2071
|
+
_context22.next = 15;
|
|
2072
|
+
return this.authClient.AuthorizationHeader({
|
|
2073
|
+
libraryId: libraryId,
|
|
2074
|
+
objectId: objectId,
|
|
2075
|
+
update: true,
|
|
2076
|
+
encryption: encryption
|
|
2077
|
+
});
|
|
2078
|
+
|
|
2079
|
+
case 15:
|
|
2080
|
+
_context22.t2 = _context22.sent;
|
|
2081
|
+
_context22.t3 = UrlJoin(path, partWriteToken);
|
|
2082
|
+
_context22.t4 = chunk;
|
|
2083
|
+
_context22.t5 = {
|
|
2084
|
+
headers: _context22.t2,
|
|
2085
|
+
method: "POST",
|
|
2086
|
+
path: _context22.t3,
|
|
2087
|
+
body: _context22.t4,
|
|
2088
|
+
bodyType: "BINARY",
|
|
2089
|
+
failover: false
|
|
2090
|
+
};
|
|
2091
|
+
_context22.t6 = _context22.t1.Request.call(_context22.t1, _context22.t5);
|
|
2092
|
+
_context22.next = 22;
|
|
2093
|
+
return _context22.t0.ResponseToJson.call(_context22.t0, _context22.t6);
|
|
2094
|
+
|
|
2095
|
+
case 22:
|
|
2096
|
+
case "end":
|
|
2097
|
+
return _context22.stop();
|
|
2098
|
+
}
|
|
1788
2099
|
}
|
|
1789
2100
|
}, _callee22, this);
|
|
1790
2101
|
}));
|
|
2102
|
+
|
|
1791
2103
|
return function (_x23) {
|
|
1792
2104
|
return _ref40.apply(this, arguments);
|
|
1793
2105
|
};
|
|
1794
2106
|
}();
|
|
1795
|
-
|
|
1796
2107
|
/**
|
|
1797
2108
|
* Finalize an open part draft
|
|
1798
2109
|
*
|
|
@@ -1807,58 +2118,66 @@ exports.UploadPartChunk = /*#__PURE__*/function () {
|
|
|
1807
2118
|
*
|
|
1808
2119
|
* @returns {Promise<object>} - The finalize response for the new part
|
|
1809
2120
|
*/
|
|
2121
|
+
|
|
2122
|
+
|
|
1810
2123
|
exports.FinalizePart = /*#__PURE__*/function () {
|
|
1811
2124
|
var _ref42 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee23(_ref41) {
|
|
1812
2125
|
var libraryId, objectId, writeToken, partWriteToken, encryption, path;
|
|
1813
2126
|
return _regeneratorRuntime.wrap(function _callee23$(_context23) {
|
|
1814
|
-
while (1)
|
|
1815
|
-
|
|
1816
|
-
|
|
1817
|
-
|
|
1818
|
-
|
|
1819
|
-
|
|
1820
|
-
|
|
1821
|
-
|
|
1822
|
-
|
|
1823
|
-
|
|
1824
|
-
|
|
1825
|
-
|
|
1826
|
-
|
|
1827
|
-
|
|
1828
|
-
|
|
1829
|
-
|
|
1830
|
-
|
|
1831
|
-
|
|
1832
|
-
|
|
1833
|
-
|
|
1834
|
-
|
|
1835
|
-
|
|
1836
|
-
|
|
1837
|
-
|
|
1838
|
-
|
|
1839
|
-
|
|
1840
|
-
|
|
1841
|
-
|
|
1842
|
-
|
|
1843
|
-
|
|
1844
|
-
|
|
1845
|
-
|
|
1846
|
-
|
|
1847
|
-
|
|
1848
|
-
|
|
1849
|
-
|
|
1850
|
-
|
|
1851
|
-
|
|
1852
|
-
|
|
1853
|
-
|
|
2127
|
+
while (1) {
|
|
2128
|
+
switch (_context23.prev = _context23.next) {
|
|
2129
|
+
case 0:
|
|
2130
|
+
libraryId = _ref41.libraryId, objectId = _ref41.objectId, writeToken = _ref41.writeToken, partWriteToken = _ref41.partWriteToken, encryption = _ref41.encryption;
|
|
2131
|
+
ValidateParameters({
|
|
2132
|
+
libraryId: libraryId,
|
|
2133
|
+
objectId: objectId
|
|
2134
|
+
});
|
|
2135
|
+
ValidateWriteToken(writeToken);
|
|
2136
|
+
path = UrlJoin("q", writeToken, "parts");
|
|
2137
|
+
_context23.t0 = this.utils;
|
|
2138
|
+
_context23.t1 = this.HttpClient;
|
|
2139
|
+
_context23.next = 8;
|
|
2140
|
+
return this.authClient.AuthorizationHeader({
|
|
2141
|
+
libraryId: libraryId,
|
|
2142
|
+
objectId: objectId,
|
|
2143
|
+
update: true,
|
|
2144
|
+
encryption: encryption
|
|
2145
|
+
});
|
|
2146
|
+
|
|
2147
|
+
case 8:
|
|
2148
|
+
_context23.t2 = _context23.sent;
|
|
2149
|
+
_context23.t3 = UrlJoin(path, partWriteToken);
|
|
2150
|
+
_context23.t4 = {
|
|
2151
|
+
headers: _context23.t2,
|
|
2152
|
+
method: "POST",
|
|
2153
|
+
path: _context23.t3,
|
|
2154
|
+
bodyType: "BINARY",
|
|
2155
|
+
body: "",
|
|
2156
|
+
failover: false
|
|
2157
|
+
};
|
|
2158
|
+
_context23.next = 13;
|
|
2159
|
+
return _context23.t1.Request.call(_context23.t1, _context23.t4);
|
|
2160
|
+
|
|
2161
|
+
case 13:
|
|
2162
|
+
_context23.t5 = _context23.sent;
|
|
2163
|
+
_context23.next = 16;
|
|
2164
|
+
return _context23.t0.ResponseToJson.call(_context23.t0, _context23.t5);
|
|
2165
|
+
|
|
2166
|
+
case 16:
|
|
2167
|
+
return _context23.abrupt("return", _context23.sent);
|
|
2168
|
+
|
|
2169
|
+
case 17:
|
|
2170
|
+
case "end":
|
|
2171
|
+
return _context23.stop();
|
|
2172
|
+
}
|
|
1854
2173
|
}
|
|
1855
2174
|
}, _callee23, this);
|
|
1856
2175
|
}));
|
|
2176
|
+
|
|
1857
2177
|
return function (_x24) {
|
|
1858
2178
|
return _ref42.apply(this, arguments);
|
|
1859
2179
|
};
|
|
1860
2180
|
}();
|
|
1861
|
-
|
|
1862
2181
|
/**
|
|
1863
2182
|
* Upload part to an object draft
|
|
1864
2183
|
*
|
|
@@ -1880,83 +2199,98 @@ exports.FinalizePart = /*#__PURE__*/function () {
|
|
|
1880
2199
|
*
|
|
1881
2200
|
* @returns {Promise<Object>} - Response containing information about the uploaded part
|
|
1882
2201
|
*/
|
|
2202
|
+
|
|
2203
|
+
|
|
1883
2204
|
exports.UploadPart = /*#__PURE__*/function () {
|
|
1884
2205
|
var _ref44 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee24(_ref43) {
|
|
1885
2206
|
var libraryId, objectId, writeToken, data, _ref43$encryption, encryption, _ref43$chunkSize, chunkSize, callback, partWriteToken, size, i, chunk;
|
|
2207
|
+
|
|
1886
2208
|
return _regeneratorRuntime.wrap(function _callee24$(_context24) {
|
|
1887
|
-
while (1)
|
|
1888
|
-
|
|
1889
|
-
|
|
1890
|
-
|
|
1891
|
-
|
|
1892
|
-
|
|
1893
|
-
|
|
1894
|
-
ValidateWriteToken(writeToken);
|
|
1895
|
-
_context24.next = 5;
|
|
1896
|
-
return this.CreatePart({
|
|
1897
|
-
libraryId: libraryId,
|
|
1898
|
-
objectId: objectId,
|
|
1899
|
-
writeToken: writeToken,
|
|
1900
|
-
encryption: encryption
|
|
1901
|
-
});
|
|
1902
|
-
case 5:
|
|
1903
|
-
partWriteToken = _context24.sent;
|
|
1904
|
-
size = data.length || data.byteLength || data.size;
|
|
1905
|
-
if (callback) {
|
|
1906
|
-
callback({
|
|
1907
|
-
bytesFinished: 0,
|
|
1908
|
-
bytesTotal: size
|
|
2209
|
+
while (1) {
|
|
2210
|
+
switch (_context24.prev = _context24.next) {
|
|
2211
|
+
case 0:
|
|
2212
|
+
libraryId = _ref43.libraryId, objectId = _ref43.objectId, writeToken = _ref43.writeToken, data = _ref43.data, _ref43$encryption = _ref43.encryption, encryption = _ref43$encryption === void 0 ? "none" : _ref43$encryption, _ref43$chunkSize = _ref43.chunkSize, chunkSize = _ref43$chunkSize === void 0 ? 10000000 : _ref43$chunkSize, callback = _ref43.callback;
|
|
2213
|
+
ValidateParameters({
|
|
2214
|
+
libraryId: libraryId,
|
|
2215
|
+
objectId: objectId
|
|
1909
2216
|
});
|
|
1910
|
-
|
|
1911
|
-
|
|
1912
|
-
|
|
1913
|
-
|
|
1914
|
-
|
|
2217
|
+
ValidateWriteToken(writeToken);
|
|
2218
|
+
_context24.next = 5;
|
|
2219
|
+
return this.CreatePart({
|
|
2220
|
+
libraryId: libraryId,
|
|
2221
|
+
objectId: objectId,
|
|
2222
|
+
writeToken: writeToken,
|
|
2223
|
+
encryption: encryption
|
|
2224
|
+
});
|
|
2225
|
+
|
|
2226
|
+
case 5:
|
|
2227
|
+
partWriteToken = _context24.sent;
|
|
2228
|
+
size = data.length || data.byteLength || data.size;
|
|
2229
|
+
|
|
2230
|
+
if (callback) {
|
|
2231
|
+
callback({
|
|
2232
|
+
bytesFinished: 0,
|
|
2233
|
+
bytesTotal: size
|
|
2234
|
+
});
|
|
2235
|
+
}
|
|
2236
|
+
|
|
2237
|
+
i = 0;
|
|
2238
|
+
|
|
2239
|
+
case 9:
|
|
2240
|
+
if (!(i < size)) {
|
|
2241
|
+
_context24.next = 17;
|
|
2242
|
+
break;
|
|
2243
|
+
}
|
|
2244
|
+
|
|
2245
|
+
chunk = data.slice(i, i + chunkSize);
|
|
2246
|
+
_context24.next = 13;
|
|
2247
|
+
return this.UploadPartChunk({
|
|
2248
|
+
libraryId: libraryId,
|
|
2249
|
+
objectId: objectId,
|
|
2250
|
+
writeToken: writeToken,
|
|
2251
|
+
partWriteToken: partWriteToken,
|
|
2252
|
+
chunk: chunk,
|
|
2253
|
+
encryption: encryption
|
|
2254
|
+
});
|
|
2255
|
+
|
|
2256
|
+
case 13:
|
|
2257
|
+
if (callback) {
|
|
2258
|
+
callback({
|
|
2259
|
+
bytesFinished: Math.min(i + chunkSize, size),
|
|
2260
|
+
bytesTotal: size
|
|
2261
|
+
});
|
|
2262
|
+
}
|
|
2263
|
+
|
|
2264
|
+
case 14:
|
|
2265
|
+
i += chunkSize;
|
|
2266
|
+
_context24.next = 9;
|
|
1915
2267
|
break;
|
|
1916
|
-
|
|
1917
|
-
|
|
1918
|
-
|
|
1919
|
-
|
|
1920
|
-
|
|
1921
|
-
|
|
1922
|
-
|
|
1923
|
-
|
|
1924
|
-
|
|
1925
|
-
encryption: encryption
|
|
1926
|
-
});
|
|
1927
|
-
case 13:
|
|
1928
|
-
if (callback) {
|
|
1929
|
-
callback({
|
|
1930
|
-
bytesFinished: Math.min(i + chunkSize, size),
|
|
1931
|
-
bytesTotal: size
|
|
2268
|
+
|
|
2269
|
+
case 17:
|
|
2270
|
+
_context24.next = 19;
|
|
2271
|
+
return this.FinalizePart({
|
|
2272
|
+
libraryId: libraryId,
|
|
2273
|
+
objectId: objectId,
|
|
2274
|
+
writeToken: writeToken,
|
|
2275
|
+
partWriteToken: partWriteToken,
|
|
2276
|
+
encryption: encryption
|
|
1932
2277
|
});
|
|
1933
|
-
|
|
1934
|
-
|
|
1935
|
-
|
|
1936
|
-
|
|
1937
|
-
|
|
1938
|
-
|
|
1939
|
-
|
|
1940
|
-
|
|
1941
|
-
libraryId: libraryId,
|
|
1942
|
-
objectId: objectId,
|
|
1943
|
-
writeToken: writeToken,
|
|
1944
|
-
partWriteToken: partWriteToken,
|
|
1945
|
-
encryption: encryption
|
|
1946
|
-
});
|
|
1947
|
-
case 19:
|
|
1948
|
-
return _context24.abrupt("return", _context24.sent);
|
|
1949
|
-
case 20:
|
|
1950
|
-
case "end":
|
|
1951
|
-
return _context24.stop();
|
|
2278
|
+
|
|
2279
|
+
case 19:
|
|
2280
|
+
return _context24.abrupt("return", _context24.sent);
|
|
2281
|
+
|
|
2282
|
+
case 20:
|
|
2283
|
+
case "end":
|
|
2284
|
+
return _context24.stop();
|
|
2285
|
+
}
|
|
1952
2286
|
}
|
|
1953
2287
|
}, _callee24, this);
|
|
1954
2288
|
}));
|
|
2289
|
+
|
|
1955
2290
|
return function (_x25) {
|
|
1956
2291
|
return _ref44.apply(this, arguments);
|
|
1957
2292
|
};
|
|
1958
2293
|
}();
|
|
1959
|
-
|
|
1960
2294
|
/**
|
|
1961
2295
|
* Delete the specified part from a content draft
|
|
1962
2296
|
*
|
|
@@ -1968,44 +2302,51 @@ exports.UploadPart = /*#__PURE__*/function () {
|
|
|
1968
2302
|
* @param {string} writeToken - Write token of the content object draft
|
|
1969
2303
|
* @param {string} partHash - Hash of the part to delete
|
|
1970
2304
|
*/
|
|
2305
|
+
|
|
2306
|
+
|
|
1971
2307
|
exports.DeletePart = /*#__PURE__*/function () {
|
|
1972
2308
|
var _ref46 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee25(_ref45) {
|
|
1973
2309
|
var libraryId, objectId, writeToken, partHash, path;
|
|
1974
2310
|
return _regeneratorRuntime.wrap(function _callee25$(_context25) {
|
|
1975
|
-
while (1)
|
|
1976
|
-
|
|
1977
|
-
|
|
1978
|
-
|
|
1979
|
-
|
|
1980
|
-
|
|
1981
|
-
|
|
1982
|
-
|
|
1983
|
-
|
|
1984
|
-
|
|
1985
|
-
|
|
1986
|
-
|
|
1987
|
-
|
|
1988
|
-
|
|
1989
|
-
|
|
1990
|
-
|
|
1991
|
-
|
|
1992
|
-
|
|
1993
|
-
|
|
1994
|
-
|
|
1995
|
-
|
|
1996
|
-
|
|
1997
|
-
|
|
1998
|
-
|
|
1999
|
-
|
|
2000
|
-
|
|
2001
|
-
|
|
2002
|
-
|
|
2003
|
-
|
|
2004
|
-
|
|
2005
|
-
|
|
2311
|
+
while (1) {
|
|
2312
|
+
switch (_context25.prev = _context25.next) {
|
|
2313
|
+
case 0:
|
|
2314
|
+
libraryId = _ref45.libraryId, objectId = _ref45.objectId, writeToken = _ref45.writeToken, partHash = _ref45.partHash;
|
|
2315
|
+
ValidateParameters({
|
|
2316
|
+
libraryId: libraryId,
|
|
2317
|
+
objectId: objectId
|
|
2318
|
+
});
|
|
2319
|
+
ValidateWriteToken(writeToken);
|
|
2320
|
+
ValidatePartHash(partHash);
|
|
2321
|
+
path = UrlJoin("q", writeToken, "parts", partHash);
|
|
2322
|
+
_context25.t0 = this.HttpClient;
|
|
2323
|
+
_context25.next = 8;
|
|
2324
|
+
return this.authClient.AuthorizationHeader({
|
|
2325
|
+
libraryId: libraryId,
|
|
2326
|
+
objectId: objectId,
|
|
2327
|
+
update: true
|
|
2328
|
+
});
|
|
2329
|
+
|
|
2330
|
+
case 8:
|
|
2331
|
+
_context25.t1 = _context25.sent;
|
|
2332
|
+
_context25.t2 = path;
|
|
2333
|
+
_context25.t3 = {
|
|
2334
|
+
headers: _context25.t1,
|
|
2335
|
+
method: "DELETE",
|
|
2336
|
+
path: _context25.t2,
|
|
2337
|
+
failover: false
|
|
2338
|
+
};
|
|
2339
|
+
_context25.next = 13;
|
|
2340
|
+
return _context25.t0.Request.call(_context25.t0, _context25.t3);
|
|
2341
|
+
|
|
2342
|
+
case 13:
|
|
2343
|
+
case "end":
|
|
2344
|
+
return _context25.stop();
|
|
2345
|
+
}
|
|
2006
2346
|
}
|
|
2007
2347
|
}, _callee25, this);
|
|
2008
2348
|
}));
|
|
2349
|
+
|
|
2009
2350
|
return function (_x26) {
|
|
2010
2351
|
return _ref46.apply(this, arguments);
|
|
2011
2352
|
};
|