@atlaskit/media-client 33.2.0 → 33.3.1
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 +20 -0
- package/dist/cjs/client/file-fetcher/index.js +35 -34
- package/dist/cjs/client/media-store/MediaStore.js +17 -18
- package/dist/cjs/index.js +6 -0
- package/dist/cjs/models/file-state.js +4 -1
- package/dist/es2019/client/file-fetcher/index.js +8 -7
- package/dist/es2019/client/media-store/MediaStore.js +11 -7
- package/dist/es2019/index.js +1 -1
- package/dist/es2019/models/file-state.js +1 -0
- package/dist/esm/client/file-fetcher/index.js +35 -34
- package/dist/esm/client/media-store/MediaStore.js +17 -18
- package/dist/esm/index.js +1 -1
- package/dist/esm/models/file-state.js +3 -0
- package/dist/types/index.d.ts +1 -1
- package/dist/types/models/file-state.d.ts +4 -1
- package/dist/types-ts4.5/index.d.ts +1 -1
- package/dist/types-ts4.5/models/file-state.d.ts +4 -1
- package/package.json +5 -5
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,25 @@
|
|
|
1
1
|
# @atlaskit/media-client
|
|
2
2
|
|
|
3
|
+
## 33.3.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#159106](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/pull-requests/159106)
|
|
8
|
+
[`aee0b27cf6dd2`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/aee0b27cf6dd2) -
|
|
9
|
+
Fixed getVideoDurations to correctly use the full URL for the artifacts
|
|
10
|
+
|
|
11
|
+
## 33.3.0
|
|
12
|
+
|
|
13
|
+
### Minor Changes
|
|
14
|
+
|
|
15
|
+
- [#152511](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/pull-requests/152511)
|
|
16
|
+
[`c5dbe965a1abe`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/c5dbe965a1abe) -
|
|
17
|
+
Exported hasArtifacts utility
|
|
18
|
+
|
|
19
|
+
### Patch Changes
|
|
20
|
+
|
|
21
|
+
- Updated dependencies
|
|
22
|
+
|
|
3
23
|
## 33.2.0
|
|
4
24
|
|
|
5
25
|
### Minor Changes
|
|
@@ -253,7 +253,7 @@ var FileFetcherImpl = exports.FileFetcherImpl = /*#__PURE__*/function () {
|
|
|
253
253
|
}());
|
|
254
254
|
(0, _defineProperty2.default)(this, "getDurationOfVideo", /*#__PURE__*/function () {
|
|
255
255
|
var _ref4 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee4(id, collectionName) {
|
|
256
|
-
var fileState,
|
|
256
|
+
var fileState, artifactUrlString, artifactUrl, artifactPath, res, arrayBuffer, uint8Array, mvhdBytes, mvhdIndex, i, j, dataView, start, timeScale, duration, videoLength;
|
|
257
257
|
return _regenerator.default.wrap(function _callee4$(_context4) {
|
|
258
258
|
while (1) switch (_context4.prev = _context4.next) {
|
|
259
259
|
case 0:
|
|
@@ -261,95 +261,96 @@ var FileFetcherImpl = exports.FileFetcherImpl = /*#__PURE__*/function () {
|
|
|
261
261
|
return _this.getOrFetchFileState(id, collectionName);
|
|
262
262
|
case 2:
|
|
263
263
|
fileState = _context4.sent;
|
|
264
|
-
if (!(fileState.status !==
|
|
264
|
+
if (!(fileState.status !== 'processed' || fileState.mediaType !== 'video' || !fileState.artifacts['video.mp4'])) {
|
|
265
265
|
_context4.next = 5;
|
|
266
266
|
break;
|
|
267
267
|
}
|
|
268
|
-
throw new Error(
|
|
268
|
+
throw new Error('File is not a video');
|
|
269
269
|
case 5:
|
|
270
270
|
_context4.next = 7;
|
|
271
|
-
return _this.getArtifactURL(fileState.artifacts,
|
|
271
|
+
return _this.getArtifactURL(fileState.artifacts, 'video.mp4');
|
|
272
272
|
case 7:
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
273
|
+
artifactUrlString = _context4.sent;
|
|
274
|
+
artifactUrl = new URL(artifactUrlString);
|
|
275
|
+
artifactPath = "".concat(artifactUrl.pathname).concat(artifactUrl.search);
|
|
276
|
+
_context4.next = 12;
|
|
276
277
|
return _this.mediaApi.request(artifactPath, {
|
|
277
278
|
headers: {
|
|
278
|
-
Range:
|
|
279
|
+
Range: 'bytes=0-199'
|
|
279
280
|
}
|
|
280
281
|
});
|
|
281
|
-
case
|
|
282
|
+
case 12:
|
|
282
283
|
res = _context4.sent;
|
|
283
|
-
_context4.next =
|
|
284
|
+
_context4.next = 15;
|
|
284
285
|
return res.arrayBuffer();
|
|
285
|
-
case
|
|
286
|
+
case 15:
|
|
286
287
|
arrayBuffer = _context4.sent;
|
|
287
288
|
uint8Array = new Uint8Array(arrayBuffer);
|
|
288
289
|
mvhdBytes = new Uint8Array([109, 118, 104, 100]); // "mvhd" in ASCII
|
|
289
290
|
mvhdIndex = -1;
|
|
290
291
|
i = 0;
|
|
291
|
-
case
|
|
292
|
+
case 20:
|
|
292
293
|
if (!(i <= uint8Array.length - mvhdBytes.length)) {
|
|
293
|
-
_context4.next =
|
|
294
|
+
_context4.next = 35;
|
|
294
295
|
break;
|
|
295
296
|
}
|
|
296
297
|
mvhdIndex = i;
|
|
297
298
|
j = 0;
|
|
298
|
-
case
|
|
299
|
+
case 23:
|
|
299
300
|
if (!(j < mvhdBytes.length)) {
|
|
300
|
-
_context4.next =
|
|
301
|
+
_context4.next = 30;
|
|
301
302
|
break;
|
|
302
303
|
}
|
|
303
304
|
if (!(uint8Array[i + j] !== mvhdBytes[j])) {
|
|
304
|
-
_context4.next =
|
|
305
|
+
_context4.next = 27;
|
|
305
306
|
break;
|
|
306
307
|
}
|
|
307
308
|
mvhdIndex = -1;
|
|
308
|
-
return _context4.abrupt("break",
|
|
309
|
-
case
|
|
309
|
+
return _context4.abrupt("break", 30);
|
|
310
|
+
case 27:
|
|
310
311
|
j++;
|
|
311
|
-
_context4.next =
|
|
312
|
+
_context4.next = 23;
|
|
312
313
|
break;
|
|
313
|
-
case
|
|
314
|
+
case 30:
|
|
314
315
|
if (!(mvhdIndex !== -1)) {
|
|
315
|
-
_context4.next =
|
|
316
|
+
_context4.next = 32;
|
|
316
317
|
break;
|
|
317
318
|
}
|
|
318
|
-
return _context4.abrupt("break",
|
|
319
|
-
case
|
|
319
|
+
return _context4.abrupt("break", 35);
|
|
320
|
+
case 32:
|
|
320
321
|
i++;
|
|
321
|
-
_context4.next =
|
|
322
|
+
_context4.next = 20;
|
|
322
323
|
break;
|
|
323
|
-
case
|
|
324
|
+
case 35:
|
|
324
325
|
if (!(mvhdIndex === -1)) {
|
|
325
|
-
_context4.next =
|
|
326
|
+
_context4.next = 37;
|
|
326
327
|
break;
|
|
327
328
|
}
|
|
328
|
-
throw new Error(
|
|
329
|
-
case
|
|
329
|
+
throw new Error('Unable to find mvhd bytes');
|
|
330
|
+
case 37:
|
|
330
331
|
// Create DataView for reading big-endian integers
|
|
331
332
|
dataView = new DataView(arrayBuffer);
|
|
332
333
|
start = mvhdIndex + 16; // Skip atom header and version/flags
|
|
333
334
|
// Check if we have enough bytes to read timescale and duration
|
|
334
335
|
if (!(start + 8 > arrayBuffer.byteLength)) {
|
|
335
|
-
_context4.next =
|
|
336
|
+
_context4.next = 41;
|
|
336
337
|
break;
|
|
337
338
|
}
|
|
338
339
|
return _context4.abrupt("return", 0);
|
|
339
|
-
case
|
|
340
|
+
case 41:
|
|
340
341
|
// flase as second parameter indicates big-endian 32-bit integers
|
|
341
342
|
timeScale = dataView.getUint32(start, false);
|
|
342
343
|
duration = dataView.getUint32(start + 4, false);
|
|
343
344
|
if (!(timeScale === 0)) {
|
|
344
|
-
_context4.next =
|
|
345
|
+
_context4.next = 45;
|
|
345
346
|
break;
|
|
346
347
|
}
|
|
347
|
-
throw new Error(
|
|
348
|
-
case
|
|
348
|
+
throw new Error('Timescale is invalid');
|
|
349
|
+
case 45:
|
|
349
350
|
// get the video length in seconds
|
|
350
351
|
videoLength = Math.floor(duration / timeScale);
|
|
351
352
|
return _context4.abrupt("return", videoLength);
|
|
352
|
-
case
|
|
353
|
+
case 47:
|
|
353
354
|
case "end":
|
|
354
355
|
return _context4.stop();
|
|
355
356
|
}
|
|
@@ -462,8 +462,6 @@ var MediaStore = exports.MediaStore = /*#__PURE__*/function () {
|
|
|
462
462
|
value: function () {
|
|
463
463
|
var _getArtifactURL = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee9(artifacts, artifactName, collectionName) {
|
|
464
464
|
var maxAge,
|
|
465
|
-
_artifacts$artifactNa,
|
|
466
|
-
cdnUrl,
|
|
467
465
|
artifactUrl,
|
|
468
466
|
auth,
|
|
469
467
|
options,
|
|
@@ -472,29 +470,30 @@ var MediaStore = exports.MediaStore = /*#__PURE__*/function () {
|
|
|
472
470
|
while (1) switch (_context9.prev = _context9.next) {
|
|
473
471
|
case 0:
|
|
474
472
|
maxAge = _args9.length > 3 && _args9[3] !== undefined ? _args9[3] : _constants.FILE_CACHE_MAX_AGE;
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
473
|
+
// ----- WARNING ----------
|
|
474
|
+
// DO NOT USE!!!!!
|
|
475
|
+
// artifact.cdnUrl fails in Jira.
|
|
476
|
+
// ----------------------------------
|
|
477
|
+
// getArtifactURL returns a constructed url PATH, not the full Media/CDN Url.
|
|
478
|
+
// We use the provided cdnUrl from metadata first.
|
|
479
|
+
/* if (isCommercial() && fg('platform_media_cdn_delivery')) {
|
|
480
|
+
const cdnUrl = artifacts[artifactName]?.cdnUrl;
|
|
481
|
+
if (cdnUrl) {
|
|
482
|
+
return cdnUrl;
|
|
483
|
+
}
|
|
484
|
+
} */
|
|
486
485
|
artifactUrl = (0, _artifacts.getArtifactUrl)(artifacts, artifactName);
|
|
487
486
|
if (artifactUrl) {
|
|
488
|
-
_context9.next =
|
|
487
|
+
_context9.next = 4;
|
|
489
488
|
break;
|
|
490
489
|
}
|
|
491
490
|
throw new Error("artifact ".concat(artifactName, " not found"));
|
|
492
|
-
case
|
|
493
|
-
_context9.next =
|
|
491
|
+
case 4:
|
|
492
|
+
_context9.next = 6;
|
|
494
493
|
return this.resolveAuth({
|
|
495
494
|
collectionName: collectionName
|
|
496
495
|
});
|
|
497
|
-
case
|
|
496
|
+
case 6:
|
|
498
497
|
auth = _context9.sent;
|
|
499
498
|
options = {
|
|
500
499
|
params: {
|
|
@@ -504,7 +503,7 @@ var MediaStore = exports.MediaStore = /*#__PURE__*/function () {
|
|
|
504
503
|
auth: auth
|
|
505
504
|
};
|
|
506
505
|
return _context9.abrupt("return", (0, _helpers.createUrl)((0, _mediaCdn.mapToMediaCdnUrl)(artifactUrl, auth.token), options));
|
|
507
|
-
case
|
|
506
|
+
case 9:
|
|
508
507
|
case "end":
|
|
509
508
|
return _context9.stop();
|
|
510
509
|
}
|
package/dist/cjs/index.js
CHANGED
|
@@ -171,6 +171,12 @@ Object.defineProperty(exports, "globalMediaEventEmitter", {
|
|
|
171
171
|
return _globalMediaEventEmitter.globalMediaEventEmitter;
|
|
172
172
|
}
|
|
173
173
|
});
|
|
174
|
+
Object.defineProperty(exports, "hasArtifacts", {
|
|
175
|
+
enumerable: true,
|
|
176
|
+
get: function get() {
|
|
177
|
+
return _fileState.hasArtifacts;
|
|
178
|
+
}
|
|
179
|
+
});
|
|
174
180
|
Object.defineProperty(exports, "imageResizeModeToFileImageMode", {
|
|
175
181
|
enumerable: true,
|
|
176
182
|
get: function get() {
|
|
@@ -4,7 +4,7 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
|
4
4
|
Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
|
-
exports.mapMediaItemToFileState = exports.mapMediaFileToFileState = exports.isUploadingFileState = exports.isProcessingFileState = exports.isProcessedFileState = exports.isPreviewableFileState = exports.isNonErrorFinalFileState = exports.isImageRepresentationReady = exports.isFinalFileState = exports.isErrorFileState = void 0;
|
|
7
|
+
exports.mapMediaItemToFileState = exports.mapMediaFileToFileState = exports.isUploadingFileState = exports.isProcessingFileState = exports.isProcessedFileState = exports.isPreviewableFileState = exports.isNonErrorFinalFileState = exports.isImageRepresentationReady = exports.isFinalFileState = exports.isErrorFileState = exports.hasArtifacts = void 0;
|
|
8
8
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
9
9
|
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; }
|
|
10
10
|
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) { (0, _defineProperty2.default)(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; }
|
|
@@ -29,6 +29,9 @@ var isFinalFileState = exports.isFinalFileState = function isFinalFileState(file
|
|
|
29
29
|
var isNonErrorFinalFileState = exports.isNonErrorFinalFileState = function isNonErrorFinalFileState(fileState) {
|
|
30
30
|
return ['processed', 'failed-processing'].includes(fileState.status);
|
|
31
31
|
};
|
|
32
|
+
var hasArtifacts = exports.hasArtifacts = function hasArtifacts(fileState) {
|
|
33
|
+
return 'artifacts' in fileState && fileState.artifacts !== undefined;
|
|
34
|
+
};
|
|
32
35
|
var isImageRepresentationReady = exports.isImageRepresentationReady = function isImageRepresentationReady(fileState) {
|
|
33
36
|
switch (fileState.status) {
|
|
34
37
|
case 'processing':
|
|
@@ -163,14 +163,15 @@ export class FileFetcherImpl {
|
|
|
163
163
|
});
|
|
164
164
|
_defineProperty(this, "getDurationOfVideo", async (id, collectionName) => {
|
|
165
165
|
const fileState = await this.getOrFetchFileState(id, collectionName);
|
|
166
|
-
if (fileState.status !==
|
|
167
|
-
throw new Error(
|
|
166
|
+
if (fileState.status !== 'processed' || fileState.mediaType !== 'video' || !fileState.artifacts['video.mp4']) {
|
|
167
|
+
throw new Error('File is not a video');
|
|
168
168
|
}
|
|
169
|
-
const
|
|
170
|
-
const
|
|
169
|
+
const artifactUrlString = await this.getArtifactURL(fileState.artifacts, 'video.mp4');
|
|
170
|
+
const artifactUrl = new URL(artifactUrlString);
|
|
171
|
+
const artifactPath = `${artifactUrl.pathname}${artifactUrl.search}`;
|
|
171
172
|
const res = await this.mediaApi.request(artifactPath, {
|
|
172
173
|
headers: {
|
|
173
|
-
Range:
|
|
174
|
+
Range: 'bytes=0-199'
|
|
174
175
|
}
|
|
175
176
|
});
|
|
176
177
|
|
|
@@ -193,7 +194,7 @@ export class FileFetcherImpl {
|
|
|
193
194
|
}
|
|
194
195
|
}
|
|
195
196
|
if (mvhdIndex === -1) {
|
|
196
|
-
throw new Error(
|
|
197
|
+
throw new Error('Unable to find mvhd bytes');
|
|
197
198
|
}
|
|
198
199
|
|
|
199
200
|
// Create DataView for reading big-endian integers
|
|
@@ -209,7 +210,7 @@ export class FileFetcherImpl {
|
|
|
209
210
|
const timeScale = dataView.getUint32(start, false);
|
|
210
211
|
const duration = dataView.getUint32(start + 4, false);
|
|
211
212
|
if (timeScale === 0) {
|
|
212
|
-
throw new Error(
|
|
213
|
+
throw new Error('Timescale is invalid');
|
|
213
214
|
}
|
|
214
215
|
|
|
215
216
|
// get the video length in seconds
|
|
@@ -282,15 +282,19 @@ export class MediaStore {
|
|
|
282
282
|
return mapToMediaCdnUrl(createUrl(`${auth.baseUrl}/file/${id}/${binaryEndpoint}`, options), auth.token);
|
|
283
283
|
}
|
|
284
284
|
async getArtifactURL(artifacts, artifactName, collectionName, maxAge = FILE_CACHE_MAX_AGE) {
|
|
285
|
+
// ----- WARNING ----------
|
|
286
|
+
// DO NOT USE!!!!!
|
|
287
|
+
// artifact.cdnUrl fails in Jira.
|
|
288
|
+
// ----------------------------------
|
|
285
289
|
// getArtifactURL returns a constructed url PATH, not the full Media/CDN Url.
|
|
286
290
|
// We use the provided cdnUrl from metadata first.
|
|
287
|
-
if (isCommercial() && fg('platform_media_cdn_delivery')) {
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
291
|
+
/* if (isCommercial() && fg('platform_media_cdn_delivery')) {
|
|
292
|
+
const cdnUrl = artifacts[artifactName]?.cdnUrl;
|
|
293
|
+
if (cdnUrl) {
|
|
294
|
+
return cdnUrl;
|
|
295
|
+
}
|
|
296
|
+
} */
|
|
297
|
+
|
|
294
298
|
const artifactUrl = getArtifactUrl(artifacts, artifactName);
|
|
295
299
|
if (!artifactUrl) {
|
|
296
300
|
throw new Error(`artifact ${artifactName} not found`);
|
package/dist/es2019/index.js
CHANGED
|
@@ -3,7 +3,7 @@ export { UploadController } from './upload-controller';
|
|
|
3
3
|
export { isPreviewableType } from './models/media';
|
|
4
4
|
export { getArtifactUrl } from './models/artifacts';
|
|
5
5
|
export { isMediaClientError, getMediaClientErrorReason, isCommonMediaClientError, toCommonMediaClientError } from './models/errors';
|
|
6
|
-
export { isUploadingFileState, isProcessingFileState, isProcessedFileState, isErrorFileState, isPreviewableFileState, isFinalFileState, isImageRepresentationReady, isNonErrorFinalFileState, mapMediaFileToFileState, mapMediaItemToFileState } from './models/file-state';
|
|
6
|
+
export { isUploadingFileState, isProcessingFileState, isProcessedFileState, isErrorFileState, isPreviewableFileState, isFinalFileState, isImageRepresentationReady, isNonErrorFinalFileState, mapMediaFileToFileState, mapMediaItemToFileState, hasArtifacts } from './models/file-state';
|
|
7
7
|
export { uploadFile } from './uploader';
|
|
8
8
|
export { request, RequestError, isRequestError, isRateLimitedError, createRequestErrorReason } from './utils/request';
|
|
9
9
|
export { isAbortedRequestError, createUrl } from './utils/request/helpers';
|
|
@@ -5,6 +5,7 @@ export const isErrorFileState = fileState => fileState.status === 'error';
|
|
|
5
5
|
export const isPreviewableFileState = fileState => !isErrorFileState(fileState) && !!fileState.preview;
|
|
6
6
|
export const isFinalFileState = fileState => ['processed', 'failed-processing', 'error'].includes(fileState.status);
|
|
7
7
|
export const isNonErrorFinalFileState = fileState => ['processed', 'failed-processing'].includes(fileState.status);
|
|
8
|
+
export const hasArtifacts = fileState => 'artifacts' in fileState && fileState.artifacts !== undefined;
|
|
8
9
|
export const isImageRepresentationReady = fileState => {
|
|
9
10
|
switch (fileState.status) {
|
|
10
11
|
case 'processing':
|
|
@@ -235,7 +235,7 @@ export var FileFetcherImpl = /*#__PURE__*/function () {
|
|
|
235
235
|
}());
|
|
236
236
|
_defineProperty(this, "getDurationOfVideo", /*#__PURE__*/function () {
|
|
237
237
|
var _ref4 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4(id, collectionName) {
|
|
238
|
-
var fileState,
|
|
238
|
+
var fileState, artifactUrlString, artifactUrl, artifactPath, res, arrayBuffer, uint8Array, mvhdBytes, mvhdIndex, i, j, dataView, start, timeScale, duration, videoLength;
|
|
239
239
|
return _regeneratorRuntime.wrap(function _callee4$(_context4) {
|
|
240
240
|
while (1) switch (_context4.prev = _context4.next) {
|
|
241
241
|
case 0:
|
|
@@ -243,95 +243,96 @@ export var FileFetcherImpl = /*#__PURE__*/function () {
|
|
|
243
243
|
return _this.getOrFetchFileState(id, collectionName);
|
|
244
244
|
case 2:
|
|
245
245
|
fileState = _context4.sent;
|
|
246
|
-
if (!(fileState.status !==
|
|
246
|
+
if (!(fileState.status !== 'processed' || fileState.mediaType !== 'video' || !fileState.artifacts['video.mp4'])) {
|
|
247
247
|
_context4.next = 5;
|
|
248
248
|
break;
|
|
249
249
|
}
|
|
250
|
-
throw new Error(
|
|
250
|
+
throw new Error('File is not a video');
|
|
251
251
|
case 5:
|
|
252
252
|
_context4.next = 7;
|
|
253
|
-
return _this.getArtifactURL(fileState.artifacts,
|
|
253
|
+
return _this.getArtifactURL(fileState.artifacts, 'video.mp4');
|
|
254
254
|
case 7:
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
255
|
+
artifactUrlString = _context4.sent;
|
|
256
|
+
artifactUrl = new URL(artifactUrlString);
|
|
257
|
+
artifactPath = "".concat(artifactUrl.pathname).concat(artifactUrl.search);
|
|
258
|
+
_context4.next = 12;
|
|
258
259
|
return _this.mediaApi.request(artifactPath, {
|
|
259
260
|
headers: {
|
|
260
|
-
Range:
|
|
261
|
+
Range: 'bytes=0-199'
|
|
261
262
|
}
|
|
262
263
|
});
|
|
263
|
-
case
|
|
264
|
+
case 12:
|
|
264
265
|
res = _context4.sent;
|
|
265
|
-
_context4.next =
|
|
266
|
+
_context4.next = 15;
|
|
266
267
|
return res.arrayBuffer();
|
|
267
|
-
case
|
|
268
|
+
case 15:
|
|
268
269
|
arrayBuffer = _context4.sent;
|
|
269
270
|
uint8Array = new Uint8Array(arrayBuffer);
|
|
270
271
|
mvhdBytes = new Uint8Array([109, 118, 104, 100]); // "mvhd" in ASCII
|
|
271
272
|
mvhdIndex = -1;
|
|
272
273
|
i = 0;
|
|
273
|
-
case
|
|
274
|
+
case 20:
|
|
274
275
|
if (!(i <= uint8Array.length - mvhdBytes.length)) {
|
|
275
|
-
_context4.next =
|
|
276
|
+
_context4.next = 35;
|
|
276
277
|
break;
|
|
277
278
|
}
|
|
278
279
|
mvhdIndex = i;
|
|
279
280
|
j = 0;
|
|
280
|
-
case
|
|
281
|
+
case 23:
|
|
281
282
|
if (!(j < mvhdBytes.length)) {
|
|
282
|
-
_context4.next =
|
|
283
|
+
_context4.next = 30;
|
|
283
284
|
break;
|
|
284
285
|
}
|
|
285
286
|
if (!(uint8Array[i + j] !== mvhdBytes[j])) {
|
|
286
|
-
_context4.next =
|
|
287
|
+
_context4.next = 27;
|
|
287
288
|
break;
|
|
288
289
|
}
|
|
289
290
|
mvhdIndex = -1;
|
|
290
|
-
return _context4.abrupt("break",
|
|
291
|
-
case
|
|
291
|
+
return _context4.abrupt("break", 30);
|
|
292
|
+
case 27:
|
|
292
293
|
j++;
|
|
293
|
-
_context4.next =
|
|
294
|
+
_context4.next = 23;
|
|
294
295
|
break;
|
|
295
|
-
case
|
|
296
|
+
case 30:
|
|
296
297
|
if (!(mvhdIndex !== -1)) {
|
|
297
|
-
_context4.next =
|
|
298
|
+
_context4.next = 32;
|
|
298
299
|
break;
|
|
299
300
|
}
|
|
300
|
-
return _context4.abrupt("break",
|
|
301
|
-
case
|
|
301
|
+
return _context4.abrupt("break", 35);
|
|
302
|
+
case 32:
|
|
302
303
|
i++;
|
|
303
|
-
_context4.next =
|
|
304
|
+
_context4.next = 20;
|
|
304
305
|
break;
|
|
305
|
-
case
|
|
306
|
+
case 35:
|
|
306
307
|
if (!(mvhdIndex === -1)) {
|
|
307
|
-
_context4.next =
|
|
308
|
+
_context4.next = 37;
|
|
308
309
|
break;
|
|
309
310
|
}
|
|
310
|
-
throw new Error(
|
|
311
|
-
case
|
|
311
|
+
throw new Error('Unable to find mvhd bytes');
|
|
312
|
+
case 37:
|
|
312
313
|
// Create DataView for reading big-endian integers
|
|
313
314
|
dataView = new DataView(arrayBuffer);
|
|
314
315
|
start = mvhdIndex + 16; // Skip atom header and version/flags
|
|
315
316
|
// Check if we have enough bytes to read timescale and duration
|
|
316
317
|
if (!(start + 8 > arrayBuffer.byteLength)) {
|
|
317
|
-
_context4.next =
|
|
318
|
+
_context4.next = 41;
|
|
318
319
|
break;
|
|
319
320
|
}
|
|
320
321
|
return _context4.abrupt("return", 0);
|
|
321
|
-
case
|
|
322
|
+
case 41:
|
|
322
323
|
// flase as second parameter indicates big-endian 32-bit integers
|
|
323
324
|
timeScale = dataView.getUint32(start, false);
|
|
324
325
|
duration = dataView.getUint32(start + 4, false);
|
|
325
326
|
if (!(timeScale === 0)) {
|
|
326
|
-
_context4.next =
|
|
327
|
+
_context4.next = 45;
|
|
327
328
|
break;
|
|
328
329
|
}
|
|
329
|
-
throw new Error(
|
|
330
|
-
case
|
|
330
|
+
throw new Error('Timescale is invalid');
|
|
331
|
+
case 45:
|
|
331
332
|
// get the video length in seconds
|
|
332
333
|
videoLength = Math.floor(duration / timeScale);
|
|
333
334
|
return _context4.abrupt("return", videoLength);
|
|
334
|
-
case
|
|
335
|
+
case 47:
|
|
335
336
|
case "end":
|
|
336
337
|
return _context4.stop();
|
|
337
338
|
}
|
|
@@ -456,8 +456,6 @@ export var MediaStore = /*#__PURE__*/function () {
|
|
|
456
456
|
value: function () {
|
|
457
457
|
var _getArtifactURL = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee9(artifacts, artifactName, collectionName) {
|
|
458
458
|
var maxAge,
|
|
459
|
-
_artifacts$artifactNa,
|
|
460
|
-
cdnUrl,
|
|
461
459
|
artifactUrl,
|
|
462
460
|
auth,
|
|
463
461
|
options,
|
|
@@ -466,29 +464,30 @@ export var MediaStore = /*#__PURE__*/function () {
|
|
|
466
464
|
while (1) switch (_context9.prev = _context9.next) {
|
|
467
465
|
case 0:
|
|
468
466
|
maxAge = _args9.length > 3 && _args9[3] !== undefined ? _args9[3] : FILE_CACHE_MAX_AGE;
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
467
|
+
// ----- WARNING ----------
|
|
468
|
+
// DO NOT USE!!!!!
|
|
469
|
+
// artifact.cdnUrl fails in Jira.
|
|
470
|
+
// ----------------------------------
|
|
471
|
+
// getArtifactURL returns a constructed url PATH, not the full Media/CDN Url.
|
|
472
|
+
// We use the provided cdnUrl from metadata first.
|
|
473
|
+
/* if (isCommercial() && fg('platform_media_cdn_delivery')) {
|
|
474
|
+
const cdnUrl = artifacts[artifactName]?.cdnUrl;
|
|
475
|
+
if (cdnUrl) {
|
|
476
|
+
return cdnUrl;
|
|
477
|
+
}
|
|
478
|
+
} */
|
|
480
479
|
artifactUrl = getArtifactUrl(artifacts, artifactName);
|
|
481
480
|
if (artifactUrl) {
|
|
482
|
-
_context9.next =
|
|
481
|
+
_context9.next = 4;
|
|
483
482
|
break;
|
|
484
483
|
}
|
|
485
484
|
throw new Error("artifact ".concat(artifactName, " not found"));
|
|
486
|
-
case
|
|
487
|
-
_context9.next =
|
|
485
|
+
case 4:
|
|
486
|
+
_context9.next = 6;
|
|
488
487
|
return this.resolveAuth({
|
|
489
488
|
collectionName: collectionName
|
|
490
489
|
});
|
|
491
|
-
case
|
|
490
|
+
case 6:
|
|
492
491
|
auth = _context9.sent;
|
|
493
492
|
options = {
|
|
494
493
|
params: {
|
|
@@ -498,7 +497,7 @@ export var MediaStore = /*#__PURE__*/function () {
|
|
|
498
497
|
auth: auth
|
|
499
498
|
};
|
|
500
499
|
return _context9.abrupt("return", createUrl(mapToMediaCdnUrl(artifactUrl, auth.token), options));
|
|
501
|
-
case
|
|
500
|
+
case 9:
|
|
502
501
|
case "end":
|
|
503
502
|
return _context9.stop();
|
|
504
503
|
}
|
package/dist/esm/index.js
CHANGED
|
@@ -3,7 +3,7 @@ export { UploadController } from './upload-controller';
|
|
|
3
3
|
export { isPreviewableType } from './models/media';
|
|
4
4
|
export { getArtifactUrl } from './models/artifacts';
|
|
5
5
|
export { isMediaClientError, getMediaClientErrorReason, isCommonMediaClientError, toCommonMediaClientError } from './models/errors';
|
|
6
|
-
export { isUploadingFileState, isProcessingFileState, isProcessedFileState, isErrorFileState, isPreviewableFileState, isFinalFileState, isImageRepresentationReady, isNonErrorFinalFileState, mapMediaFileToFileState, mapMediaItemToFileState } from './models/file-state';
|
|
6
|
+
export { isUploadingFileState, isProcessingFileState, isProcessedFileState, isErrorFileState, isPreviewableFileState, isFinalFileState, isImageRepresentationReady, isNonErrorFinalFileState, mapMediaFileToFileState, mapMediaItemToFileState, hasArtifacts } from './models/file-state';
|
|
7
7
|
export { uploadFile } from './uploader';
|
|
8
8
|
export { request, RequestError, isRequestError, isRateLimitedError, createRequestErrorReason } from './utils/request';
|
|
9
9
|
export { isAbortedRequestError, createUrl } from './utils/request/helpers';
|
|
@@ -22,6 +22,9 @@ export var isFinalFileState = function isFinalFileState(fileState) {
|
|
|
22
22
|
export var isNonErrorFinalFileState = function isNonErrorFinalFileState(fileState) {
|
|
23
23
|
return ['processed', 'failed-processing'].includes(fileState.status);
|
|
24
24
|
};
|
|
25
|
+
export var hasArtifacts = function hasArtifacts(fileState) {
|
|
26
|
+
return 'artifacts' in fileState && fileState.artifacts !== undefined;
|
|
27
|
+
};
|
|
25
28
|
export var isImageRepresentationReady = function isImageRepresentationReady(fileState) {
|
|
26
29
|
switch (fileState.status) {
|
|
27
30
|
case 'processing':
|
package/dist/types/index.d.ts
CHANGED
|
@@ -8,7 +8,7 @@ export type { MediaFileProcessingStatus, MediaType, MediaFile, MediaRepresentati
|
|
|
8
8
|
export { getArtifactUrl } from './models/artifacts';
|
|
9
9
|
export { isMediaClientError, getMediaClientErrorReason, isCommonMediaClientError, toCommonMediaClientError, } from './models/errors';
|
|
10
10
|
export type { MediaClientError, MediaClientErrorReason, MediaClientErrorAttributes, } from './models/errors';
|
|
11
|
-
export { isUploadingFileState, isProcessingFileState, isProcessedFileState, isErrorFileState, isPreviewableFileState, isFinalFileState, isImageRepresentationReady, isNonErrorFinalFileState, mapMediaFileToFileState, mapMediaItemToFileState, } from './models/file-state';
|
|
11
|
+
export { isUploadingFileState, isProcessingFileState, isProcessedFileState, isErrorFileState, isPreviewableFileState, isFinalFileState, isImageRepresentationReady, isNonErrorFinalFileState, mapMediaFileToFileState, mapMediaItemToFileState, hasArtifacts, } from './models/file-state';
|
|
12
12
|
export type { FileStatus, PreviewOptions, GetFileOptions, NonErrorFileState, PreviewableFileState, } from './models/file-state';
|
|
13
13
|
export type { FileState, FilePreview, ErrorFileState, UploadingFileState, ProcessingFileState, ProcessedFileState, ProcessingFailedState, MediaFileArtifact, MediaFileArtifacts, } from '@atlaskit/media-state';
|
|
14
14
|
export type { MobileUpload, MobileUploadStartEvent, MobileUploadProgressEvent, MobileUploadEndEvent, MobileUploadErrorEvent, } from './models/mobile-upload';
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { type FileStatus as CommonFileStatus } from '@atlaskit/media-common';
|
|
2
2
|
import { type MediaStoreResponse } from '../client/media-store';
|
|
3
3
|
import { type MediaItemDetails, type MediaFile } from './media';
|
|
4
|
-
import { type FilePreview, type FileState, type ErrorFileState, type UploadingFileState, type ProcessingFileState, type ProcessedFileState, type ProcessingFailedState } from '@atlaskit/media-state';
|
|
4
|
+
import { type FilePreview, type FileState, type ErrorFileState, type UploadingFileState, type ProcessingFileState, type ProcessedFileState, type ProcessingFailedState, type MediaFileArtifacts } from '@atlaskit/media-state';
|
|
5
5
|
export type FileStatus = CommonFileStatus;
|
|
6
6
|
export interface PreviewOptions {
|
|
7
7
|
}
|
|
@@ -23,6 +23,9 @@ export declare const isErrorFileState: (fileState: FileState) => fileState is Er
|
|
|
23
23
|
export declare const isPreviewableFileState: (fileState: FileState) => fileState is (UploadingFileState | ProcessingFileState | ProcessedFileState | ProcessingFailedState) & PreviewableFileState;
|
|
24
24
|
export declare const isFinalFileState: (fileState: FileState) => fileState is ProcessedFileState | ErrorFileState | ProcessingFailedState;
|
|
25
25
|
export declare const isNonErrorFinalFileState: (fileState: FileState) => fileState is ProcessedFileState | ProcessingFailedState;
|
|
26
|
+
export declare const hasArtifacts: (fileState: FileState) => fileState is FileState & {
|
|
27
|
+
artifacts: MediaFileArtifacts;
|
|
28
|
+
};
|
|
26
29
|
export declare const isImageRepresentationReady: (fileState: FileState) => boolean;
|
|
27
30
|
export declare const mapMediaFileToFileState: (mediaFile: MediaStoreResponse<MediaFile>) => FileState;
|
|
28
31
|
export declare const mapMediaItemToFileState: (id: string, item: MediaItemDetails) => FileState;
|
|
@@ -8,7 +8,7 @@ export type { MediaFileProcessingStatus, MediaType, MediaFile, MediaRepresentati
|
|
|
8
8
|
export { getArtifactUrl } from './models/artifacts';
|
|
9
9
|
export { isMediaClientError, getMediaClientErrorReason, isCommonMediaClientError, toCommonMediaClientError, } from './models/errors';
|
|
10
10
|
export type { MediaClientError, MediaClientErrorReason, MediaClientErrorAttributes, } from './models/errors';
|
|
11
|
-
export { isUploadingFileState, isProcessingFileState, isProcessedFileState, isErrorFileState, isPreviewableFileState, isFinalFileState, isImageRepresentationReady, isNonErrorFinalFileState, mapMediaFileToFileState, mapMediaItemToFileState, } from './models/file-state';
|
|
11
|
+
export { isUploadingFileState, isProcessingFileState, isProcessedFileState, isErrorFileState, isPreviewableFileState, isFinalFileState, isImageRepresentationReady, isNonErrorFinalFileState, mapMediaFileToFileState, mapMediaItemToFileState, hasArtifacts, } from './models/file-state';
|
|
12
12
|
export type { FileStatus, PreviewOptions, GetFileOptions, NonErrorFileState, PreviewableFileState, } from './models/file-state';
|
|
13
13
|
export type { FileState, FilePreview, ErrorFileState, UploadingFileState, ProcessingFileState, ProcessedFileState, ProcessingFailedState, MediaFileArtifact, MediaFileArtifacts, } from '@atlaskit/media-state';
|
|
14
14
|
export type { MobileUpload, MobileUploadStartEvent, MobileUploadProgressEvent, MobileUploadEndEvent, MobileUploadErrorEvent, } from './models/mobile-upload';
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { type FileStatus as CommonFileStatus } from '@atlaskit/media-common';
|
|
2
2
|
import { type MediaStoreResponse } from '../client/media-store';
|
|
3
3
|
import { type MediaItemDetails, type MediaFile } from './media';
|
|
4
|
-
import { type FilePreview, type FileState, type ErrorFileState, type UploadingFileState, type ProcessingFileState, type ProcessedFileState, type ProcessingFailedState } from '@atlaskit/media-state';
|
|
4
|
+
import { type FilePreview, type FileState, type ErrorFileState, type UploadingFileState, type ProcessingFileState, type ProcessedFileState, type ProcessingFailedState, type MediaFileArtifacts } from '@atlaskit/media-state';
|
|
5
5
|
export type FileStatus = CommonFileStatus;
|
|
6
6
|
export interface PreviewOptions {
|
|
7
7
|
}
|
|
@@ -23,6 +23,9 @@ export declare const isErrorFileState: (fileState: FileState) => fileState is Er
|
|
|
23
23
|
export declare const isPreviewableFileState: (fileState: FileState) => fileState is (UploadingFileState | ProcessingFileState | ProcessedFileState | ProcessingFailedState) & PreviewableFileState;
|
|
24
24
|
export declare const isFinalFileState: (fileState: FileState) => fileState is ProcessedFileState | ErrorFileState | ProcessingFailedState;
|
|
25
25
|
export declare const isNonErrorFinalFileState: (fileState: FileState) => fileState is ProcessedFileState | ProcessingFailedState;
|
|
26
|
+
export declare const hasArtifacts: (fileState: FileState) => fileState is FileState & {
|
|
27
|
+
artifacts: MediaFileArtifacts;
|
|
28
|
+
};
|
|
26
29
|
export declare const isImageRepresentationReady: (fileState: FileState) => boolean;
|
|
27
30
|
export declare const mapMediaFileToFileState: (mediaFile: MediaStoreResponse<MediaFile>) => FileState;
|
|
28
31
|
export declare const mapMediaItemToFileState: (id: string, item: MediaItemDetails) => FileState;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/media-client",
|
|
3
|
-
"version": "33.
|
|
3
|
+
"version": "33.3.1",
|
|
4
4
|
"description": "Media API Web Client Library",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"registry": "https://registry.npmjs.org/"
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
37
|
"@atlaskit/chunkinator": "^7.0.0",
|
|
38
|
-
"@atlaskit/media-common": "^12.
|
|
38
|
+
"@atlaskit/media-common": "^12.1.0",
|
|
39
39
|
"@atlaskit/platform-feature-flags": "^1.1.0",
|
|
40
40
|
"@babel/runtime": "^7.0.0",
|
|
41
41
|
"dataloader": "^2.1.0",
|
|
@@ -51,13 +51,13 @@
|
|
|
51
51
|
},
|
|
52
52
|
"peerDependencies": {
|
|
53
53
|
"@atlaskit/media-core": "^36.1.0",
|
|
54
|
-
"@atlaskit/media-state": "^1.
|
|
54
|
+
"@atlaskit/media-state": "^1.6.0"
|
|
55
55
|
},
|
|
56
56
|
"devDependencies": {
|
|
57
57
|
"@atlaskit/media-core": "^36.1.0",
|
|
58
|
-
"@atlaskit/media-state": "^1.
|
|
58
|
+
"@atlaskit/media-state": "^1.6.0",
|
|
59
59
|
"@atlaskit/ssr": "workspace:^",
|
|
60
|
-
"@atlaskit/tokens": "^4.
|
|
60
|
+
"@atlaskit/tokens": "^4.9.0",
|
|
61
61
|
"@atlassian/feature-flags-test-utils": "^0.3.0",
|
|
62
62
|
"@emotion/react": "^11.7.1",
|
|
63
63
|
"@types/deep-equal": "^1.0.1",
|