@atlaskit/media-client 33.3.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 CHANGED
@@ -1,5 +1,13 @@
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
+
3
11
  ## 33.3.0
4
12
 
5
13
  ### 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, aritfactUrl, artifactPath, res, arrayBuffer, uint8Array, mvhdBytes, mvhdIndex, i, j, dataView, start, timeScale, duration, videoLength;
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:
@@ -270,86 +270,87 @@ var FileFetcherImpl = exports.FileFetcherImpl = /*#__PURE__*/function () {
270
270
  _context4.next = 7;
271
271
  return _this.getArtifactURL(fileState.artifacts, 'video.mp4');
272
272
  case 7:
273
- aritfactUrl = _context4.sent;
274
- artifactPath = new URL(aritfactUrl).pathname;
275
- _context4.next = 11;
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
279
  Range: 'bytes=0-199'
279
280
  }
280
281
  });
281
- case 11:
282
+ case 12:
282
283
  res = _context4.sent;
283
- _context4.next = 14;
284
+ _context4.next = 15;
284
285
  return res.arrayBuffer();
285
- case 14:
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 19:
292
+ case 20:
292
293
  if (!(i <= uint8Array.length - mvhdBytes.length)) {
293
- _context4.next = 34;
294
+ _context4.next = 35;
294
295
  break;
295
296
  }
296
297
  mvhdIndex = i;
297
298
  j = 0;
298
- case 22:
299
+ case 23:
299
300
  if (!(j < mvhdBytes.length)) {
300
- _context4.next = 29;
301
+ _context4.next = 30;
301
302
  break;
302
303
  }
303
304
  if (!(uint8Array[i + j] !== mvhdBytes[j])) {
304
- _context4.next = 26;
305
+ _context4.next = 27;
305
306
  break;
306
307
  }
307
308
  mvhdIndex = -1;
308
- return _context4.abrupt("break", 29);
309
- case 26:
309
+ return _context4.abrupt("break", 30);
310
+ case 27:
310
311
  j++;
311
- _context4.next = 22;
312
+ _context4.next = 23;
312
313
  break;
313
- case 29:
314
+ case 30:
314
315
  if (!(mvhdIndex !== -1)) {
315
- _context4.next = 31;
316
+ _context4.next = 32;
316
317
  break;
317
318
  }
318
- return _context4.abrupt("break", 34);
319
- case 31:
319
+ return _context4.abrupt("break", 35);
320
+ case 32:
320
321
  i++;
321
- _context4.next = 19;
322
+ _context4.next = 20;
322
323
  break;
323
- case 34:
324
+ case 35:
324
325
  if (!(mvhdIndex === -1)) {
325
- _context4.next = 36;
326
+ _context4.next = 37;
326
327
  break;
327
328
  }
328
329
  throw new Error('Unable to find mvhd bytes');
329
- case 36:
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 = 40;
336
+ _context4.next = 41;
336
337
  break;
337
338
  }
338
339
  return _context4.abrupt("return", 0);
339
- case 40:
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 = 44;
345
+ _context4.next = 45;
345
346
  break;
346
347
  }
347
348
  throw new Error('Timescale is invalid');
348
- case 44:
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 46:
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
- if (!((0, _isCommercial.isCommercial)() && (0, _platformFeatureFlags.fg)('platform_media_cdn_delivery'))) {
476
- _context9.next = 5;
477
- break;
478
- }
479
- cdnUrl = (_artifacts$artifactNa = artifacts[artifactName]) === null || _artifacts$artifactNa === void 0 ? void 0 : _artifacts$artifactNa.cdnUrl;
480
- if (!cdnUrl) {
481
- _context9.next = 5;
482
- break;
483
- }
484
- return _context9.abrupt("return", cdnUrl);
485
- case 5:
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 = 8;
487
+ _context9.next = 4;
489
488
  break;
490
489
  }
491
490
  throw new Error("artifact ".concat(artifactName, " not found"));
492
- case 8:
493
- _context9.next = 10;
491
+ case 4:
492
+ _context9.next = 6;
494
493
  return this.resolveAuth({
495
494
  collectionName: collectionName
496
495
  });
497
- case 10:
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 13:
506
+ case 9:
508
507
  case "end":
509
508
  return _context9.stop();
510
509
  }
@@ -166,8 +166,9 @@ export class FileFetcherImpl {
166
166
  if (fileState.status !== 'processed' || fileState.mediaType !== 'video' || !fileState.artifacts['video.mp4']) {
167
167
  throw new Error('File is not a video');
168
168
  }
169
- const aritfactUrl = await this.getArtifactURL(fileState.artifacts, 'video.mp4');
170
- const artifactPath = new URL(aritfactUrl).pathname;
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
174
  Range: 'bytes=0-199'
@@ -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
- var _artifacts$artifactNa;
289
- const cdnUrl = (_artifacts$artifactNa = artifacts[artifactName]) === null || _artifacts$artifactNa === void 0 ? void 0 : _artifacts$artifactNa.cdnUrl;
290
- if (cdnUrl) {
291
- return cdnUrl;
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`);
@@ -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, aritfactUrl, artifactPath, res, arrayBuffer, uint8Array, mvhdBytes, mvhdIndex, i, j, dataView, start, timeScale, duration, videoLength;
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:
@@ -252,86 +252,87 @@ export var FileFetcherImpl = /*#__PURE__*/function () {
252
252
  _context4.next = 7;
253
253
  return _this.getArtifactURL(fileState.artifacts, 'video.mp4');
254
254
  case 7:
255
- aritfactUrl = _context4.sent;
256
- artifactPath = new URL(aritfactUrl).pathname;
257
- _context4.next = 11;
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
261
  Range: 'bytes=0-199'
261
262
  }
262
263
  });
263
- case 11:
264
+ case 12:
264
265
  res = _context4.sent;
265
- _context4.next = 14;
266
+ _context4.next = 15;
266
267
  return res.arrayBuffer();
267
- case 14:
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 19:
274
+ case 20:
274
275
  if (!(i <= uint8Array.length - mvhdBytes.length)) {
275
- _context4.next = 34;
276
+ _context4.next = 35;
276
277
  break;
277
278
  }
278
279
  mvhdIndex = i;
279
280
  j = 0;
280
- case 22:
281
+ case 23:
281
282
  if (!(j < mvhdBytes.length)) {
282
- _context4.next = 29;
283
+ _context4.next = 30;
283
284
  break;
284
285
  }
285
286
  if (!(uint8Array[i + j] !== mvhdBytes[j])) {
286
- _context4.next = 26;
287
+ _context4.next = 27;
287
288
  break;
288
289
  }
289
290
  mvhdIndex = -1;
290
- return _context4.abrupt("break", 29);
291
- case 26:
291
+ return _context4.abrupt("break", 30);
292
+ case 27:
292
293
  j++;
293
- _context4.next = 22;
294
+ _context4.next = 23;
294
295
  break;
295
- case 29:
296
+ case 30:
296
297
  if (!(mvhdIndex !== -1)) {
297
- _context4.next = 31;
298
+ _context4.next = 32;
298
299
  break;
299
300
  }
300
- return _context4.abrupt("break", 34);
301
- case 31:
301
+ return _context4.abrupt("break", 35);
302
+ case 32:
302
303
  i++;
303
- _context4.next = 19;
304
+ _context4.next = 20;
304
305
  break;
305
- case 34:
306
+ case 35:
306
307
  if (!(mvhdIndex === -1)) {
307
- _context4.next = 36;
308
+ _context4.next = 37;
308
309
  break;
309
310
  }
310
311
  throw new Error('Unable to find mvhd bytes');
311
- case 36:
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 = 40;
318
+ _context4.next = 41;
318
319
  break;
319
320
  }
320
321
  return _context4.abrupt("return", 0);
321
- case 40:
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 = 44;
327
+ _context4.next = 45;
327
328
  break;
328
329
  }
329
330
  throw new Error('Timescale is invalid');
330
- case 44:
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 46:
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
- if (!(isCommercial() && fg('platform_media_cdn_delivery'))) {
470
- _context9.next = 5;
471
- break;
472
- }
473
- cdnUrl = (_artifacts$artifactNa = artifacts[artifactName]) === null || _artifacts$artifactNa === void 0 ? void 0 : _artifacts$artifactNa.cdnUrl;
474
- if (!cdnUrl) {
475
- _context9.next = 5;
476
- break;
477
- }
478
- return _context9.abrupt("return", cdnUrl);
479
- case 5:
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 = 8;
481
+ _context9.next = 4;
483
482
  break;
484
483
  }
485
484
  throw new Error("artifact ".concat(artifactName, " not found"));
486
- case 8:
487
- _context9.next = 10;
485
+ case 4:
486
+ _context9.next = 6;
488
487
  return this.resolveAuth({
489
488
  collectionName: collectionName
490
489
  });
491
- case 10:
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 13:
500
+ case 9:
502
501
  case "end":
503
502
  return _context9.stop();
504
503
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/media-client",
3
- "version": "33.3.0",
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.0.0",
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",
@@ -57,7 +57,7 @@
57
57
  "@atlaskit/media-core": "^36.1.0",
58
58
  "@atlaskit/media-state": "^1.6.0",
59
59
  "@atlaskit/ssr": "workspace:^",
60
- "@atlaskit/tokens": "^4.8.0",
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",