@atlaskit/media-client 25.0.1 → 25.0.3
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/CHANGELOG.md +12 -0
- package/dist/cjs/client/media-store/MediaStore.js +631 -0
- package/dist/cjs/client/media-store/index.js +19 -627
- package/dist/cjs/client/media-store/types.js +5 -0
- package/dist/es2019/client/media-store/MediaStore.js +385 -0
- package/dist/es2019/client/media-store/index.js +1 -385
- package/dist/es2019/client/media-store/types.js +1 -0
- package/dist/esm/client/media-store/MediaStore.js +624 -0
- package/dist/esm/client/media-store/index.js +1 -624
- package/dist/esm/client/media-store/types.js +1 -0
- package/dist/types/client/media-store/MediaStore.d.ts +34 -0
- package/dist/types/client/media-store/index.d.ts +2 -166
- package/dist/types/client/media-store/types.d.ts +161 -0
- package/dist/types-ts4.5/client/media-store/MediaStore.d.ts +34 -0
- package/dist/types-ts4.5/client/media-store/index.d.ts +2 -166
- package/dist/types-ts4.5/client/media-store/types.d.ts +161 -0
- package/package.json +2 -2
- package/report.api.md +120 -1
- package/tmp/api-report-tmp.d.ts +47 -1
|
@@ -1,625 +1,2 @@
|
|
|
1
|
-
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
|
|
2
|
-
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
|
|
3
|
-
import _createClass from "@babel/runtime/helpers/createClass";
|
|
4
|
-
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
5
|
-
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
6
|
-
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
7
|
-
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
8
|
-
import { getRandomHex } from '@atlaskit/media-common';
|
|
9
|
-
import { FILE_CACHE_MAX_AGE, MAX_RESOLUTION } from '../../constants';
|
|
10
|
-
import { getArtifactUrl } from '../../models/artifacts';
|
|
11
|
-
import { request as _request } from '../../utils/request';
|
|
12
|
-
import { createUrl, createMapResponseToJson, createMapResponseToBlob } from '../../utils/request/helpers';
|
|
13
|
-
import { resolveAuth, resolveInitialAuth } from './resolveAuth';
|
|
14
1
|
export { MediaStoreError, isMediaStoreError } from './error';
|
|
15
|
-
|
|
16
|
-
var MEDIA_API_ENVIRONMENT = 'media-api-environment';
|
|
17
|
-
var defaultImageOptions = {
|
|
18
|
-
'max-age': FILE_CACHE_MAX_AGE,
|
|
19
|
-
allowAnimated: true,
|
|
20
|
-
mode: 'crop'
|
|
21
|
-
};
|
|
22
|
-
var extendImageParams = function extendImageParams(params) {
|
|
23
|
-
var fetchMaxRes = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
24
|
-
return _objectSpread(_objectSpread(_objectSpread({}, defaultImageOptions), params), fetchMaxRes ? {
|
|
25
|
-
width: MAX_RESOLUTION,
|
|
26
|
-
height: MAX_RESOLUTION
|
|
27
|
-
} : {});
|
|
28
|
-
};
|
|
29
|
-
var jsonHeaders = {
|
|
30
|
-
Accept: 'application/json',
|
|
31
|
-
'Content-Type': 'application/json'
|
|
32
|
-
};
|
|
33
|
-
export var MediaStore = /*#__PURE__*/function () {
|
|
34
|
-
function MediaStore(config) {
|
|
35
|
-
var _this = this;
|
|
36
|
-
_classCallCheck(this, MediaStore);
|
|
37
|
-
_defineProperty(this, "resolveAuth", function (authContext) {
|
|
38
|
-
return resolveAuth(_this.config.authProvider, authContext);
|
|
39
|
-
});
|
|
40
|
-
_defineProperty(this, "resolveInitialAuth", function () {
|
|
41
|
-
return resolveInitialAuth(_this.config.initialAuth);
|
|
42
|
-
});
|
|
43
|
-
this.config = config;
|
|
44
|
-
}
|
|
45
|
-
_createClass(MediaStore, [{
|
|
46
|
-
key: "removeCollectionFile",
|
|
47
|
-
value: function () {
|
|
48
|
-
var _removeCollectionFile = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(id, collectionName, occurrenceKey, traceContext) {
|
|
49
|
-
var metadata, body, options;
|
|
50
|
-
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
51
|
-
while (1) switch (_context.prev = _context.next) {
|
|
52
|
-
case 0:
|
|
53
|
-
metadata = {
|
|
54
|
-
method: 'PUT',
|
|
55
|
-
endpoint: '/collection/{collectionName}'
|
|
56
|
-
};
|
|
57
|
-
body = {
|
|
58
|
-
actions: [{
|
|
59
|
-
action: 'remove',
|
|
60
|
-
item: {
|
|
61
|
-
type: 'file',
|
|
62
|
-
id: id,
|
|
63
|
-
occurrenceKey: occurrenceKey
|
|
64
|
-
}
|
|
65
|
-
}]
|
|
66
|
-
};
|
|
67
|
-
options = _objectSpread(_objectSpread({}, metadata), {}, {
|
|
68
|
-
authContext: {
|
|
69
|
-
collectionName: collectionName
|
|
70
|
-
},
|
|
71
|
-
headers: {
|
|
72
|
-
Accept: 'application/json',
|
|
73
|
-
'Content-Type': 'application/json'
|
|
74
|
-
},
|
|
75
|
-
body: JSON.stringify(body),
|
|
76
|
-
traceContext: traceContext
|
|
77
|
-
});
|
|
78
|
-
_context.next = 5;
|
|
79
|
-
return this.request("/collection/".concat(collectionName), options);
|
|
80
|
-
case 5:
|
|
81
|
-
case "end":
|
|
82
|
-
return _context.stop();
|
|
83
|
-
}
|
|
84
|
-
}, _callee, this);
|
|
85
|
-
}));
|
|
86
|
-
function removeCollectionFile(_x, _x2, _x3, _x4) {
|
|
87
|
-
return _removeCollectionFile.apply(this, arguments);
|
|
88
|
-
}
|
|
89
|
-
return removeCollectionFile;
|
|
90
|
-
}()
|
|
91
|
-
}, {
|
|
92
|
-
key: "createUpload",
|
|
93
|
-
value: function createUpload() {
|
|
94
|
-
var createUpTo = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1;
|
|
95
|
-
var collectionName = arguments.length > 1 ? arguments[1] : undefined;
|
|
96
|
-
var traceContext = arguments.length > 2 ? arguments[2] : undefined;
|
|
97
|
-
var metadata = {
|
|
98
|
-
method: 'POST',
|
|
99
|
-
endpoint: '/upload'
|
|
100
|
-
};
|
|
101
|
-
var options = _objectSpread(_objectSpread({}, metadata), {}, {
|
|
102
|
-
authContext: {
|
|
103
|
-
collectionName: collectionName
|
|
104
|
-
},
|
|
105
|
-
params: {
|
|
106
|
-
createUpTo: createUpTo
|
|
107
|
-
},
|
|
108
|
-
headers: {
|
|
109
|
-
Accept: 'application/json'
|
|
110
|
-
},
|
|
111
|
-
traceContext: traceContext
|
|
112
|
-
});
|
|
113
|
-
return this.request("/upload", options).then(createMapResponseToJson(metadata));
|
|
114
|
-
}
|
|
115
|
-
}, {
|
|
116
|
-
key: "uploadChunk",
|
|
117
|
-
value: function () {
|
|
118
|
-
var _uploadChunk = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(etag, blob, uploadId, partNumber, collectionName, traceContext) {
|
|
119
|
-
var metadata, options;
|
|
120
|
-
return _regeneratorRuntime.wrap(function _callee2$(_context2) {
|
|
121
|
-
while (1) switch (_context2.prev = _context2.next) {
|
|
122
|
-
case 0:
|
|
123
|
-
metadata = {
|
|
124
|
-
method: 'PUT',
|
|
125
|
-
endpoint: '/chunk/{etag}'
|
|
126
|
-
};
|
|
127
|
-
options = _objectSpread(_objectSpread({}, metadata), {}, {
|
|
128
|
-
params: {
|
|
129
|
-
uploadId: uploadId,
|
|
130
|
-
partNumber: partNumber
|
|
131
|
-
},
|
|
132
|
-
authContext: {
|
|
133
|
-
collectionName: collectionName
|
|
134
|
-
},
|
|
135
|
-
body: blob,
|
|
136
|
-
traceContext: traceContext
|
|
137
|
-
});
|
|
138
|
-
_context2.next = 4;
|
|
139
|
-
return this.request("/chunk/".concat(etag), options);
|
|
140
|
-
case 4:
|
|
141
|
-
case "end":
|
|
142
|
-
return _context2.stop();
|
|
143
|
-
}
|
|
144
|
-
}, _callee2, this);
|
|
145
|
-
}));
|
|
146
|
-
function uploadChunk(_x5, _x6, _x7, _x8, _x9, _x10) {
|
|
147
|
-
return _uploadChunk.apply(this, arguments);
|
|
148
|
-
}
|
|
149
|
-
return uploadChunk;
|
|
150
|
-
}()
|
|
151
|
-
}, {
|
|
152
|
-
key: "probeChunks",
|
|
153
|
-
value: function probeChunks(chunks, uploadId, collectionName, traceContext) {
|
|
154
|
-
var metadata = {
|
|
155
|
-
method: 'POST',
|
|
156
|
-
endpoint: '/chunk/probe'
|
|
157
|
-
};
|
|
158
|
-
var options = _objectSpread(_objectSpread({}, metadata), {}, {
|
|
159
|
-
params: {
|
|
160
|
-
uploadId: uploadId
|
|
161
|
-
},
|
|
162
|
-
authContext: {
|
|
163
|
-
collectionName: collectionName
|
|
164
|
-
},
|
|
165
|
-
headers: jsonHeaders,
|
|
166
|
-
body: JSON.stringify({
|
|
167
|
-
chunks: chunks
|
|
168
|
-
}),
|
|
169
|
-
traceContext: traceContext
|
|
170
|
-
});
|
|
171
|
-
return this.request("/chunk/probe", options).then(createMapResponseToJson(metadata));
|
|
172
|
-
}
|
|
173
|
-
}, {
|
|
174
|
-
key: "createFileFromUpload",
|
|
175
|
-
value: function createFileFromUpload(body) {
|
|
176
|
-
var params = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
177
|
-
var traceContext = arguments.length > 2 ? arguments[2] : undefined;
|
|
178
|
-
var metadata = {
|
|
179
|
-
method: 'POST',
|
|
180
|
-
endpoint: '/file/upload'
|
|
181
|
-
};
|
|
182
|
-
var options = _objectSpread(_objectSpread({}, metadata), {}, {
|
|
183
|
-
authContext: {
|
|
184
|
-
collectionName: params.collection
|
|
185
|
-
},
|
|
186
|
-
params: params,
|
|
187
|
-
headers: jsonHeaders,
|
|
188
|
-
body: JSON.stringify(body),
|
|
189
|
-
traceContext: traceContext
|
|
190
|
-
});
|
|
191
|
-
return this.request('/file/upload', options).then(createMapResponseToJson(metadata));
|
|
192
|
-
}
|
|
193
|
-
}, {
|
|
194
|
-
key: "getRejectedResponseFromDescriptor",
|
|
195
|
-
value: function getRejectedResponseFromDescriptor(descriptor, limit) {
|
|
196
|
-
return {
|
|
197
|
-
fileId: descriptor.fileId,
|
|
198
|
-
error: {
|
|
199
|
-
code: 'ExceedMaxFileSizeLimit',
|
|
200
|
-
title: 'The expected file size exceeded the maximum size limit.',
|
|
201
|
-
href: 'https://dt-api-filestore--app.ap-southeast-2.dev.atl-paas.net/api.html#BadRequest',
|
|
202
|
-
limit: limit,
|
|
203
|
-
size: descriptor.size
|
|
204
|
-
}
|
|
205
|
-
};
|
|
206
|
-
}
|
|
207
|
-
}, {
|
|
208
|
-
key: "touchFiles",
|
|
209
|
-
value: function () {
|
|
210
|
-
var _touchFiles = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(body) {
|
|
211
|
-
var params,
|
|
212
|
-
traceContext,
|
|
213
|
-
metadata,
|
|
214
|
-
options,
|
|
215
|
-
_args3 = arguments;
|
|
216
|
-
return _regeneratorRuntime.wrap(function _callee3$(_context3) {
|
|
217
|
-
while (1) switch (_context3.prev = _context3.next) {
|
|
218
|
-
case 0:
|
|
219
|
-
params = _args3.length > 1 && _args3[1] !== undefined ? _args3[1] : {};
|
|
220
|
-
traceContext = _args3.length > 2 ? _args3[2] : undefined;
|
|
221
|
-
metadata = {
|
|
222
|
-
method: 'POST',
|
|
223
|
-
endpoint: '/upload/createWithFiles'
|
|
224
|
-
};
|
|
225
|
-
options = _objectSpread(_objectSpread({}, metadata), {}, {
|
|
226
|
-
authContext: {
|
|
227
|
-
collectionName: params.collection
|
|
228
|
-
},
|
|
229
|
-
headers: jsonHeaders,
|
|
230
|
-
body: JSON.stringify(body),
|
|
231
|
-
traceContext: traceContext
|
|
232
|
-
});
|
|
233
|
-
return _context3.abrupt("return", this.request('/upload/createWithFiles', options).then(createMapResponseToJson(metadata)));
|
|
234
|
-
case 5:
|
|
235
|
-
case "end":
|
|
236
|
-
return _context3.stop();
|
|
237
|
-
}
|
|
238
|
-
}, _callee3, this);
|
|
239
|
-
}));
|
|
240
|
-
function touchFiles(_x11) {
|
|
241
|
-
return _touchFiles.apply(this, arguments);
|
|
242
|
-
}
|
|
243
|
-
return touchFiles;
|
|
244
|
-
}()
|
|
245
|
-
}, {
|
|
246
|
-
key: "getFile",
|
|
247
|
-
value: function getFile(fileId) {
|
|
248
|
-
var params = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
249
|
-
var traceContext = arguments.length > 2 ? arguments[2] : undefined;
|
|
250
|
-
var metadata = {
|
|
251
|
-
method: 'GET',
|
|
252
|
-
endpoint: '/file/{fileId}'
|
|
253
|
-
};
|
|
254
|
-
var options = _objectSpread(_objectSpread({}, metadata), {}, {
|
|
255
|
-
authContext: {
|
|
256
|
-
collectionName: params.collection
|
|
257
|
-
},
|
|
258
|
-
params: params,
|
|
259
|
-
traceContext: traceContext
|
|
260
|
-
});
|
|
261
|
-
return this.request("/file/".concat(fileId), options).then(createMapResponseToJson(metadata));
|
|
262
|
-
}
|
|
263
|
-
}, {
|
|
264
|
-
key: "getFileImageURL",
|
|
265
|
-
value: function () {
|
|
266
|
-
var _getFileImageURL = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4(id, params) {
|
|
267
|
-
var _ref, collectionName, auth;
|
|
268
|
-
return _regeneratorRuntime.wrap(function _callee4$(_context4) {
|
|
269
|
-
while (1) switch (_context4.prev = _context4.next) {
|
|
270
|
-
case 0:
|
|
271
|
-
_ref = params || {}, collectionName = _ref.collection;
|
|
272
|
-
_context4.next = 3;
|
|
273
|
-
return this.resolveAuth({
|
|
274
|
-
collectionName: collectionName
|
|
275
|
-
});
|
|
276
|
-
case 3:
|
|
277
|
-
auth = _context4.sent;
|
|
278
|
-
return _context4.abrupt("return", this.createFileImageURL(id, auth, params));
|
|
279
|
-
case 5:
|
|
280
|
-
case "end":
|
|
281
|
-
return _context4.stop();
|
|
282
|
-
}
|
|
283
|
-
}, _callee4, this);
|
|
284
|
-
}));
|
|
285
|
-
function getFileImageURL(_x12, _x13) {
|
|
286
|
-
return _getFileImageURL.apply(this, arguments);
|
|
287
|
-
}
|
|
288
|
-
return getFileImageURL;
|
|
289
|
-
}() // TODO Create ticket in case Trace Id can be supported through query params
|
|
290
|
-
}, {
|
|
291
|
-
key: "getFileImageURLSync",
|
|
292
|
-
value: function getFileImageURLSync(id, params) {
|
|
293
|
-
var auth = this.resolveInitialAuth();
|
|
294
|
-
return this.createFileImageURL(id, auth, params);
|
|
295
|
-
}
|
|
296
|
-
}, {
|
|
297
|
-
key: "createFileImageURL",
|
|
298
|
-
value: function createFileImageURL(id, auth, params) {
|
|
299
|
-
var options = {
|
|
300
|
-
params: extendImageParams(params),
|
|
301
|
-
auth: auth
|
|
302
|
-
};
|
|
303
|
-
return createUrl("".concat(auth.baseUrl, "/file/").concat(id, "/image"), options);
|
|
304
|
-
}
|
|
305
|
-
}, {
|
|
306
|
-
key: "getFileBinaryURL",
|
|
307
|
-
value: function () {
|
|
308
|
-
var _getFileBinaryURL = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee5(id, collectionName) {
|
|
309
|
-
var auth, options;
|
|
310
|
-
return _regeneratorRuntime.wrap(function _callee5$(_context5) {
|
|
311
|
-
while (1) switch (_context5.prev = _context5.next) {
|
|
312
|
-
case 0:
|
|
313
|
-
_context5.next = 2;
|
|
314
|
-
return this.resolveAuth({
|
|
315
|
-
collectionName: collectionName
|
|
316
|
-
});
|
|
317
|
-
case 2:
|
|
318
|
-
auth = _context5.sent;
|
|
319
|
-
options = {
|
|
320
|
-
params: {
|
|
321
|
-
dl: true,
|
|
322
|
-
collection: collectionName,
|
|
323
|
-
'max-age': FILE_CACHE_MAX_AGE
|
|
324
|
-
},
|
|
325
|
-
auth: auth
|
|
326
|
-
};
|
|
327
|
-
return _context5.abrupt("return", createUrl("".concat(auth.baseUrl, "/file/").concat(id, "/binary"), options));
|
|
328
|
-
case 5:
|
|
329
|
-
case "end":
|
|
330
|
-
return _context5.stop();
|
|
331
|
-
}
|
|
332
|
-
}, _callee5, this);
|
|
333
|
-
}));
|
|
334
|
-
function getFileBinaryURL(_x14, _x15) {
|
|
335
|
-
return _getFileBinaryURL.apply(this, arguments);
|
|
336
|
-
}
|
|
337
|
-
return getFileBinaryURL;
|
|
338
|
-
}()
|
|
339
|
-
}, {
|
|
340
|
-
key: "getArtifactURL",
|
|
341
|
-
value: function () {
|
|
342
|
-
var _getArtifactURL = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee6(artifacts, artifactName, collectionName) {
|
|
343
|
-
var artifactUrl, auth, options;
|
|
344
|
-
return _regeneratorRuntime.wrap(function _callee6$(_context6) {
|
|
345
|
-
while (1) switch (_context6.prev = _context6.next) {
|
|
346
|
-
case 0:
|
|
347
|
-
artifactUrl = getArtifactUrl(artifacts, artifactName);
|
|
348
|
-
if (artifactUrl) {
|
|
349
|
-
_context6.next = 3;
|
|
350
|
-
break;
|
|
351
|
-
}
|
|
352
|
-
throw new Error("artifact ".concat(artifactName, " not found"));
|
|
353
|
-
case 3:
|
|
354
|
-
_context6.next = 5;
|
|
355
|
-
return this.resolveAuth({
|
|
356
|
-
collectionName: collectionName
|
|
357
|
-
});
|
|
358
|
-
case 5:
|
|
359
|
-
auth = _context6.sent;
|
|
360
|
-
options = {
|
|
361
|
-
params: {
|
|
362
|
-
collection: collectionName,
|
|
363
|
-
'max-age': FILE_CACHE_MAX_AGE
|
|
364
|
-
},
|
|
365
|
-
auth: auth
|
|
366
|
-
};
|
|
367
|
-
return _context6.abrupt("return", createUrl("".concat(auth.baseUrl).concat(artifactUrl), options));
|
|
368
|
-
case 8:
|
|
369
|
-
case "end":
|
|
370
|
-
return _context6.stop();
|
|
371
|
-
}
|
|
372
|
-
}, _callee6, this);
|
|
373
|
-
}));
|
|
374
|
-
function getArtifactURL(_x16, _x17, _x18) {
|
|
375
|
-
return _getArtifactURL.apply(this, arguments);
|
|
376
|
-
}
|
|
377
|
-
return getArtifactURL;
|
|
378
|
-
}()
|
|
379
|
-
}, {
|
|
380
|
-
key: "getImage",
|
|
381
|
-
value: function () {
|
|
382
|
-
var _getImage = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee7(id, params, controller, fetchMaxRes, traceContext) {
|
|
383
|
-
var isWebpSupported, headers, metadata, options;
|
|
384
|
-
return _regeneratorRuntime.wrap(function _callee7$(_context7) {
|
|
385
|
-
while (1) switch (_context7.prev = _context7.next) {
|
|
386
|
-
case 0:
|
|
387
|
-
// TODO add checkWebpSupport() back https://product-fabric.atlassian.net/browse/MPT-584
|
|
388
|
-
isWebpSupported = false;
|
|
389
|
-
headers = {};
|
|
390
|
-
if (isWebpSupported) {
|
|
391
|
-
headers.accept = 'image/webp,image/*,*/*;q=0.8';
|
|
392
|
-
}
|
|
393
|
-
metadata = {
|
|
394
|
-
method: 'GET',
|
|
395
|
-
endpoint: '/file/{fileId}/image'
|
|
396
|
-
};
|
|
397
|
-
options = _objectSpread(_objectSpread({}, metadata), {}, {
|
|
398
|
-
authContext: {
|
|
399
|
-
collectionName: params && params.collection
|
|
400
|
-
},
|
|
401
|
-
params: extendImageParams(params, fetchMaxRes),
|
|
402
|
-
headers: headers,
|
|
403
|
-
traceContext: traceContext
|
|
404
|
-
});
|
|
405
|
-
return _context7.abrupt("return", this.request("/file/".concat(id, "/image"), options, controller).then(createMapResponseToBlob(metadata)));
|
|
406
|
-
case 6:
|
|
407
|
-
case "end":
|
|
408
|
-
return _context7.stop();
|
|
409
|
-
}
|
|
410
|
-
}, _callee7, this);
|
|
411
|
-
}));
|
|
412
|
-
function getImage(_x19, _x20, _x21, _x22, _x23) {
|
|
413
|
-
return _getImage.apply(this, arguments);
|
|
414
|
-
}
|
|
415
|
-
return getImage;
|
|
416
|
-
}()
|
|
417
|
-
}, {
|
|
418
|
-
key: "getItems",
|
|
419
|
-
value: function () {
|
|
420
|
-
var _getItems = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee8(ids, collectionName, traceContext) {
|
|
421
|
-
var descriptors, metadata, options;
|
|
422
|
-
return _regeneratorRuntime.wrap(function _callee8$(_context8) {
|
|
423
|
-
while (1) switch (_context8.prev = _context8.next) {
|
|
424
|
-
case 0:
|
|
425
|
-
descriptors = ids.map(function (id) {
|
|
426
|
-
return {
|
|
427
|
-
type: 'file',
|
|
428
|
-
id: id,
|
|
429
|
-
collection: collectionName
|
|
430
|
-
};
|
|
431
|
-
});
|
|
432
|
-
metadata = {
|
|
433
|
-
method: 'POST',
|
|
434
|
-
endpoint: '/items'
|
|
435
|
-
};
|
|
436
|
-
options = _objectSpread(_objectSpread({}, metadata), {}, {
|
|
437
|
-
authContext: {
|
|
438
|
-
collectionName: collectionName
|
|
439
|
-
},
|
|
440
|
-
headers: jsonHeaders,
|
|
441
|
-
body: JSON.stringify({
|
|
442
|
-
descriptors: descriptors
|
|
443
|
-
}),
|
|
444
|
-
traceContext: traceContext
|
|
445
|
-
});
|
|
446
|
-
return _context8.abrupt("return", this.request('/items', options).then(createMapResponseToJson(metadata)));
|
|
447
|
-
case 4:
|
|
448
|
-
case "end":
|
|
449
|
-
return _context8.stop();
|
|
450
|
-
}
|
|
451
|
-
}, _callee8, this);
|
|
452
|
-
}));
|
|
453
|
-
function getItems(_x24, _x25, _x26) {
|
|
454
|
-
return _getItems.apply(this, arguments);
|
|
455
|
-
}
|
|
456
|
-
return getItems;
|
|
457
|
-
}()
|
|
458
|
-
}, {
|
|
459
|
-
key: "getImageMetadata",
|
|
460
|
-
value: function () {
|
|
461
|
-
var _getImageMetadata = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee9(id, params, traceContext) {
|
|
462
|
-
var metadata, options;
|
|
463
|
-
return _regeneratorRuntime.wrap(function _callee9$(_context9) {
|
|
464
|
-
while (1) switch (_context9.prev = _context9.next) {
|
|
465
|
-
case 0:
|
|
466
|
-
metadata = {
|
|
467
|
-
method: 'GET',
|
|
468
|
-
endpoint: '/file/{fileId}/image/metadata'
|
|
469
|
-
};
|
|
470
|
-
options = _objectSpread(_objectSpread({}, metadata), {}, {
|
|
471
|
-
authContext: {
|
|
472
|
-
collectionName: params && params.collection
|
|
473
|
-
},
|
|
474
|
-
params: params,
|
|
475
|
-
traceContext: traceContext
|
|
476
|
-
});
|
|
477
|
-
return _context9.abrupt("return", this.request("/file/".concat(id, "/image/metadata"), options).then(createMapResponseToJson(metadata)));
|
|
478
|
-
case 3:
|
|
479
|
-
case "end":
|
|
480
|
-
return _context9.stop();
|
|
481
|
-
}
|
|
482
|
-
}, _callee9, this);
|
|
483
|
-
}));
|
|
484
|
-
function getImageMetadata(_x27, _x28, _x29) {
|
|
485
|
-
return _getImageMetadata.apply(this, arguments);
|
|
486
|
-
}
|
|
487
|
-
return getImageMetadata;
|
|
488
|
-
}()
|
|
489
|
-
}, {
|
|
490
|
-
key: "appendChunksToUpload",
|
|
491
|
-
value: function () {
|
|
492
|
-
var _appendChunksToUpload = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee10(uploadId, body, collectionName, traceContext) {
|
|
493
|
-
var metadata, options;
|
|
494
|
-
return _regeneratorRuntime.wrap(function _callee10$(_context10) {
|
|
495
|
-
while (1) switch (_context10.prev = _context10.next) {
|
|
496
|
-
case 0:
|
|
497
|
-
metadata = {
|
|
498
|
-
method: 'PUT',
|
|
499
|
-
endpoint: '/upload/{uploadId}/chunks'
|
|
500
|
-
};
|
|
501
|
-
options = _objectSpread(_objectSpread({}, metadata), {}, {
|
|
502
|
-
authContext: {
|
|
503
|
-
collectionName: collectionName
|
|
504
|
-
},
|
|
505
|
-
headers: jsonHeaders,
|
|
506
|
-
body: JSON.stringify(body),
|
|
507
|
-
traceContext: traceContext
|
|
508
|
-
});
|
|
509
|
-
_context10.next = 4;
|
|
510
|
-
return this.request("/upload/".concat(uploadId, "/chunks"), options);
|
|
511
|
-
case 4:
|
|
512
|
-
case "end":
|
|
513
|
-
return _context10.stop();
|
|
514
|
-
}
|
|
515
|
-
}, _callee10, this);
|
|
516
|
-
}));
|
|
517
|
-
function appendChunksToUpload(_x30, _x31, _x32, _x33) {
|
|
518
|
-
return _appendChunksToUpload.apply(this, arguments);
|
|
519
|
-
}
|
|
520
|
-
return appendChunksToUpload;
|
|
521
|
-
}()
|
|
522
|
-
}, {
|
|
523
|
-
key: "copyFileWithToken",
|
|
524
|
-
value: function copyFileWithToken(body, params, traceContext) {
|
|
525
|
-
var metadata = {
|
|
526
|
-
method: 'POST',
|
|
527
|
-
endpoint: '/file/copy/withToken'
|
|
528
|
-
};
|
|
529
|
-
var options = _objectSpread(_objectSpread({}, metadata), {}, {
|
|
530
|
-
authContext: {
|
|
531
|
-
collectionName: params.collection
|
|
532
|
-
},
|
|
533
|
-
// Contains collection name to write to
|
|
534
|
-
params: params,
|
|
535
|
-
// Contains collection name to write to
|
|
536
|
-
headers: jsonHeaders,
|
|
537
|
-
body: JSON.stringify(body),
|
|
538
|
-
// Contains collection name to read from
|
|
539
|
-
traceContext: traceContext
|
|
540
|
-
});
|
|
541
|
-
return this.request('/file/copy/withToken', options).then(createMapResponseToJson(metadata));
|
|
542
|
-
}
|
|
543
|
-
}, {
|
|
544
|
-
key: "request",
|
|
545
|
-
value: function () {
|
|
546
|
-
var _request2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee11(path) {
|
|
547
|
-
var options,
|
|
548
|
-
controller,
|
|
549
|
-
method,
|
|
550
|
-
endpoint,
|
|
551
|
-
authContext,
|
|
552
|
-
params,
|
|
553
|
-
headers,
|
|
554
|
-
body,
|
|
555
|
-
clientOptions,
|
|
556
|
-
traceContext,
|
|
557
|
-
auth,
|
|
558
|
-
extendedTraceContext,
|
|
559
|
-
response,
|
|
560
|
-
_args11 = arguments;
|
|
561
|
-
return _regeneratorRuntime.wrap(function _callee11$(_context11) {
|
|
562
|
-
while (1) switch (_context11.prev = _context11.next) {
|
|
563
|
-
case 0:
|
|
564
|
-
options = _args11.length > 1 && _args11[1] !== undefined ? _args11[1] : {
|
|
565
|
-
method: 'GET',
|
|
566
|
-
endpoint: undefined,
|
|
567
|
-
authContext: {}
|
|
568
|
-
};
|
|
569
|
-
controller = _args11.length > 2 ? _args11[2] : undefined;
|
|
570
|
-
method = options.method, endpoint = options.endpoint, authContext = options.authContext, params = options.params, headers = options.headers, body = options.body, clientOptions = options.clientOptions, traceContext = options.traceContext;
|
|
571
|
-
_context11.next = 5;
|
|
572
|
-
return this.resolveAuth(authContext);
|
|
573
|
-
case 5:
|
|
574
|
-
auth = _context11.sent;
|
|
575
|
-
extendedTraceContext = traceContext ? _objectSpread(_objectSpread({}, traceContext), {}, {
|
|
576
|
-
spanId: (traceContext === null || traceContext === void 0 ? void 0 : traceContext.spanId) || getRandomHex(8)
|
|
577
|
-
}) : undefined;
|
|
578
|
-
_context11.next = 9;
|
|
579
|
-
return _request("".concat(auth.baseUrl).concat(path), {
|
|
580
|
-
method: method,
|
|
581
|
-
endpoint: endpoint,
|
|
582
|
-
auth: auth,
|
|
583
|
-
params: params,
|
|
584
|
-
headers: headers,
|
|
585
|
-
body: body,
|
|
586
|
-
clientOptions: clientOptions,
|
|
587
|
-
traceContext: extendedTraceContext
|
|
588
|
-
}, controller);
|
|
589
|
-
case 9:
|
|
590
|
-
response = _context11.sent;
|
|
591
|
-
setKeyValueInSessionStorage(MEDIA_API_REGION, response.headers.get('x-media-region'));
|
|
592
|
-
setKeyValueInSessionStorage(MEDIA_API_ENVIRONMENT, response.headers.get('x-media-env'));
|
|
593
|
-
return _context11.abrupt("return", response);
|
|
594
|
-
case 13:
|
|
595
|
-
case "end":
|
|
596
|
-
return _context11.stop();
|
|
597
|
-
}
|
|
598
|
-
}, _callee11, this);
|
|
599
|
-
}));
|
|
600
|
-
function request(_x34) {
|
|
601
|
-
return _request2.apply(this, arguments);
|
|
602
|
-
}
|
|
603
|
-
return request;
|
|
604
|
-
}()
|
|
605
|
-
}]);
|
|
606
|
-
return MediaStore;
|
|
607
|
-
}();
|
|
608
|
-
var getValueFromSessionStorage = function getValueFromSessionStorage(key) {
|
|
609
|
-
return window && window.sessionStorage && window.sessionStorage.getItem(key) || undefined;
|
|
610
|
-
};
|
|
611
|
-
var setKeyValueInSessionStorage = function setKeyValueInSessionStorage(key, value) {
|
|
612
|
-
if (!value || !(window && window.sessionStorage)) {
|
|
613
|
-
return;
|
|
614
|
-
}
|
|
615
|
-
var currentValue = window.sessionStorage.getItem(key);
|
|
616
|
-
if (currentValue !== value) {
|
|
617
|
-
window.sessionStorage.setItem(key, value);
|
|
618
|
-
}
|
|
619
|
-
};
|
|
620
|
-
export var getMediaEnvironment = function getMediaEnvironment() {
|
|
621
|
-
return getValueFromSessionStorage(MEDIA_API_ENVIRONMENT);
|
|
622
|
-
};
|
|
623
|
-
export var getMediaRegion = function getMediaRegion() {
|
|
624
|
-
return getValueFromSessionStorage(MEDIA_API_REGION);
|
|
625
|
-
};
|
|
2
|
+
export { MediaStore, getMediaEnvironment, getMediaRegion } from './MediaStore';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { AuthContext, MediaApiConfig, Auth } from '@atlaskit/media-core';
|
|
2
|
+
import { MediaTraceContext } from '@atlaskit/media-common';
|
|
3
|
+
import { MediaFileArtifacts } from '@atlaskit/media-state';
|
|
4
|
+
import type { ItemsPayload, ImageMetadata, MediaStoreResponse, MediaStoreTouchFileParams, TouchFileDescriptor, MediaStoreTouchFileBody, RejectedTouchFile, MediaStoreRequestOptions, MediaStoreCreateFileFromUploadParams, MediaStoreCreateFileFromUploadBody, MediaStoreGetFileParams, MediaStoreGetFileImageParams, MediaStoreCopyFileWithTokenBody, MediaStoreCopyFileWithTokenParams, AppendChunksToUploadRequestBody, TouchedFiles, MediaApi } from './types';
|
|
5
|
+
import { MediaChunksProbe, MediaFile, MediaUpload } from '../../models/media';
|
|
6
|
+
export declare class MediaStore implements MediaApi {
|
|
7
|
+
private readonly config;
|
|
8
|
+
constructor(config: MediaApiConfig);
|
|
9
|
+
removeCollectionFile(id: string, collectionName: string, occurrenceKey?: string, traceContext?: MediaTraceContext): Promise<void>;
|
|
10
|
+
createUpload(createUpTo?: number, collectionName?: string, traceContext?: MediaTraceContext): Promise<MediaStoreResponse<MediaUpload[]>>;
|
|
11
|
+
uploadChunk(etag: string, blob: Blob, uploadId: string, partNumber: number, collectionName?: string, traceContext?: MediaTraceContext): Promise<void>;
|
|
12
|
+
probeChunks(chunks: string[], uploadId: string, collectionName?: string, traceContext?: MediaTraceContext): Promise<MediaStoreResponse<MediaChunksProbe>>;
|
|
13
|
+
createFileFromUpload(body: MediaStoreCreateFileFromUploadBody, params?: MediaStoreCreateFileFromUploadParams, traceContext?: MediaTraceContext): Promise<MediaStoreResponse<MediaFile>>;
|
|
14
|
+
getRejectedResponseFromDescriptor(descriptor: TouchFileDescriptor, limit: number): RejectedTouchFile;
|
|
15
|
+
touchFiles(body: MediaStoreTouchFileBody, params?: MediaStoreTouchFileParams, traceContext?: MediaTraceContext): Promise<MediaStoreResponse<TouchedFiles>>;
|
|
16
|
+
getFile(fileId: string, params?: MediaStoreGetFileParams, traceContext?: MediaTraceContext): Promise<MediaStoreResponse<MediaFile>>;
|
|
17
|
+
getFileImageURL(id: string, params?: MediaStoreGetFileImageParams): Promise<string>;
|
|
18
|
+
getFileImageURLSync(id: string, params?: MediaStoreGetFileImageParams): string;
|
|
19
|
+
private createFileImageURL;
|
|
20
|
+
getFileBinaryURL(id: string, collectionName?: string): Promise<string>;
|
|
21
|
+
getArtifactURL(artifacts: MediaFileArtifacts, artifactName: keyof MediaFileArtifacts, collectionName?: string): Promise<string>;
|
|
22
|
+
getImage(id: string, params?: MediaStoreGetFileImageParams, controller?: AbortController, fetchMaxRes?: boolean, traceContext?: MediaTraceContext): Promise<Blob>;
|
|
23
|
+
getItems(ids: string[], collectionName?: string, traceContext?: MediaTraceContext): Promise<MediaStoreResponse<ItemsPayload>>;
|
|
24
|
+
getImageMetadata(id: string, params?: MediaStoreGetFileImageParams, traceContext?: MediaTraceContext): Promise<{
|
|
25
|
+
metadata: ImageMetadata;
|
|
26
|
+
}>;
|
|
27
|
+
appendChunksToUpload(uploadId: string, body: AppendChunksToUploadRequestBody, collectionName?: string, traceContext?: MediaTraceContext): Promise<void>;
|
|
28
|
+
copyFileWithToken(body: MediaStoreCopyFileWithTokenBody, params: MediaStoreCopyFileWithTokenParams, traceContext?: MediaTraceContext): Promise<MediaStoreResponse<MediaFile>>;
|
|
29
|
+
request(path: string, options?: MediaStoreRequestOptions, controller?: AbortController): Promise<Response>;
|
|
30
|
+
resolveAuth: (authContext?: AuthContext) => Promise<Auth>;
|
|
31
|
+
resolveInitialAuth: () => Auth;
|
|
32
|
+
}
|
|
33
|
+
export declare const getMediaEnvironment: () => string | undefined;
|
|
34
|
+
export declare const getMediaRegion: () => string | undefined;
|