@atlaskit/media-client 21.0.0 → 22.0.0

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.
Files changed (62) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/dist/cjs/client/file-fetcher/error.js +4 -4
  3. package/dist/cjs/client/file-fetcher/index.js +283 -297
  4. package/dist/cjs/client/media-client.js +42 -48
  5. package/dist/cjs/client/media-store/index.js +389 -310
  6. package/dist/cjs/client/media-store/resolveAuth.js +33 -36
  7. package/dist/cjs/client/stargate-client.js +17 -20
  8. package/dist/cjs/index.js +6 -0
  9. package/dist/cjs/models/media.js +4 -4
  10. package/dist/cjs/uploader/error.js +4 -4
  11. package/dist/cjs/uploader/index.js +97 -108
  12. package/dist/cjs/utils/convertBase64ToBlob.js +2 -2
  13. package/dist/cjs/utils/createFileDataLoader.js +68 -73
  14. package/dist/cjs/utils/getDimensionsFromBlob.js +26 -29
  15. package/dist/cjs/utils/getVideoDimensionsFromBlob.js +27 -30
  16. package/dist/cjs/utils/hashing/hasherCreator.js +35 -37
  17. package/dist/cjs/utils/mobileUpload/error.js +4 -4
  18. package/dist/cjs/utils/mobileUpload/helpers.js +44 -47
  19. package/dist/cjs/utils/mobileUpload/stateMachine/index.js +17 -20
  20. package/dist/cjs/utils/parseJwt.js +52 -0
  21. package/dist/cjs/utils/polling/index.js +43 -46
  22. package/dist/cjs/utils/request/errors.js +9 -9
  23. package/dist/cjs/utils/request/helpers.js +154 -167
  24. package/dist/cjs/utils/request/index.js +27 -30
  25. package/dist/cjs/utils/shouldFetchRemoteFileStates.js +42 -45
  26. package/dist/cjs/version.json +1 -1
  27. package/dist/es2019/client/file-fetcher/index.js +1 -3
  28. package/dist/es2019/client/media-store/index.js +58 -6
  29. package/dist/es2019/index.js +1 -1
  30. package/dist/es2019/models/media.js +3 -3
  31. package/dist/es2019/utils/parseJwt.js +46 -0
  32. package/dist/es2019/version.json +1 -1
  33. package/dist/esm/client/file-fetcher/error.js +4 -4
  34. package/dist/esm/client/file-fetcher/index.js +282 -296
  35. package/dist/esm/client/media-client.js +40 -47
  36. package/dist/esm/client/media-store/index.js +389 -310
  37. package/dist/esm/client/media-store/resolveAuth.js +33 -36
  38. package/dist/esm/client/stargate-client.js +17 -20
  39. package/dist/esm/index.js +1 -1
  40. package/dist/esm/models/media.js +3 -3
  41. package/dist/esm/uploader/error.js +4 -4
  42. package/dist/esm/uploader/index.js +97 -108
  43. package/dist/esm/utils/convertBase64ToBlob.js +2 -2
  44. package/dist/esm/utils/createFileDataLoader.js +68 -73
  45. package/dist/esm/utils/getDimensionsFromBlob.js +26 -29
  46. package/dist/esm/utils/getVideoDimensionsFromBlob.js +27 -30
  47. package/dist/esm/utils/hashing/hasherCreator.js +31 -34
  48. package/dist/esm/utils/mobileUpload/error.js +4 -4
  49. package/dist/esm/utils/mobileUpload/helpers.js +44 -47
  50. package/dist/esm/utils/mobileUpload/stateMachine/index.js +17 -20
  51. package/dist/esm/utils/parseJwt.js +46 -0
  52. package/dist/esm/utils/polling/index.js +43 -46
  53. package/dist/esm/utils/request/errors.js +9 -9
  54. package/dist/esm/utils/request/helpers.js +154 -167
  55. package/dist/esm/utils/request/index.js +27 -30
  56. package/dist/esm/utils/shouldFetchRemoteFileStates.js +42 -45
  57. package/dist/esm/version.json +1 -1
  58. package/dist/types/client/media-store/index.d.ts +15 -0
  59. package/dist/types/index.d.ts +1 -1
  60. package/dist/types/utils/parseJwt.d.ts +1 -0
  61. package/package.json +9 -9
  62. package/report.api.md +31 -0
@@ -1,7 +1,6 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
- var _typeof = require("@babel/runtime/helpers/typeof");
5
4
  Object.defineProperty(exports, "__esModule", {
6
5
  value: true
7
6
  });
@@ -18,6 +17,7 @@ Object.defineProperty(exports, "isFileFetcherError", {
18
17
  return _error.isFileFetcherError;
19
18
  }
20
19
  });
20
+ var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
21
21
  var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
22
22
  var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
23
23
  var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
@@ -51,13 +51,13 @@ var _polling = require("../../utils/polling");
51
51
  var _detectEmptyFile = require("../../utils/detectEmptyFile");
52
52
  var _mediaCommon = require("@atlaskit/media-common");
53
53
  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; }
54
- 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) { (0, _defineProperty2.default)(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; }
55
- function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return exports; }; var exports = {}, Op = Object.prototype, hasOwn = Op.hasOwnProperty, defineProperty = Object.defineProperty || function (obj, key, desc) { obj[key] = desc.value; }, $Symbol = "function" == typeof Symbol ? Symbol : {}, iteratorSymbol = $Symbol.iterator || "@@iterator", asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator", toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag"; function define(obj, key, value) { return Object.defineProperty(obj, key, { value: value, enumerable: !0, configurable: !0, writable: !0 }), obj[key]; } try { define({}, ""); } catch (err) { define = function define(obj, key, value) { return obj[key] = value; }; } function wrap(innerFn, outerFn, self, tryLocsList) { var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator, generator = Object.create(protoGenerator.prototype), context = new Context(tryLocsList || []); return defineProperty(generator, "_invoke", { value: makeInvokeMethod(innerFn, self, context) }), generator; } function tryCatch(fn, obj, arg) { try { return { type: "normal", arg: fn.call(obj, arg) }; } catch (err) { return { type: "throw", arg: err }; } } exports.wrap = wrap; var ContinueSentinel = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var IteratorPrototype = {}; define(IteratorPrototype, iteratorSymbol, function () { return this; }); var getProto = Object.getPrototypeOf, NativeIteratorPrototype = getProto && getProto(getProto(values([]))); NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol) && (IteratorPrototype = NativeIteratorPrototype); var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype); function defineIteratorMethods(prototype) { ["next", "throw", "return"].forEach(function (method) { define(prototype, method, function (arg) { return this._invoke(method, arg); }); }); } function AsyncIterator(generator, PromiseImpl) { function invoke(method, arg, resolve, reject) { var record = tryCatch(generator[method], generator, arg); if ("throw" !== record.type) { var result = record.arg, value = result.value; return value && "object" == _typeof(value) && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) { invoke("next", value, resolve, reject); }, function (err) { invoke("throw", err, resolve, reject); }) : PromiseImpl.resolve(value).then(function (unwrapped) { result.value = unwrapped, resolve(result); }, function (error) { return invoke("throw", error, resolve, reject); }); } reject(record.arg); } var previousPromise; defineProperty(this, "_invoke", { value: function value(method, arg) { function callInvokeWithMethodAndArg() { return new PromiseImpl(function (resolve, reject) { invoke(method, arg, resolve, reject); }); } return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(innerFn, self, context) { var state = "suspendedStart"; return function (method, arg) { if ("executing" === state) throw new Error("Generator is already running"); if ("completed" === state) { if ("throw" === method) throw arg; return doneResult(); } for (context.method = method, context.arg = arg;;) { var delegate = context.delegate; if (delegate) { var delegateResult = maybeInvokeDelegate(delegate, context); if (delegateResult) { if (delegateResult === ContinueSentinel) continue; return delegateResult; } } if ("next" === context.method) context.sent = context._sent = context.arg;else if ("throw" === context.method) { if ("suspendedStart" === state) throw state = "completed", context.arg; context.dispatchException(context.arg); } else "return" === context.method && context.abrupt("return", context.arg); state = "executing"; var record = tryCatch(innerFn, self, context); if ("normal" === record.type) { if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel) continue; return { value: record.arg, done: context.done }; } "throw" === record.type && (state = "completed", context.method = "throw", context.arg = record.arg); } }; } function maybeInvokeDelegate(delegate, context) { var methodName = context.method, method = delegate.iterator[methodName]; if (undefined === method) return context.delegate = null, "throw" === methodName && delegate.iterator.return && (context.method = "return", context.arg = undefined, maybeInvokeDelegate(delegate, context), "throw" === context.method) || "return" !== methodName && (context.method = "throw", context.arg = new TypeError("The iterator does not provide a '" + methodName + "' method")), ContinueSentinel; var record = tryCatch(method, delegate.iterator, context.arg); if ("throw" === record.type) return context.method = "throw", context.arg = record.arg, context.delegate = null, ContinueSentinel; var info = record.arg; return info ? info.done ? (context[delegate.resultName] = info.value, context.next = delegate.nextLoc, "return" !== context.method && (context.method = "next", context.arg = undefined), context.delegate = null, ContinueSentinel) : info : (context.method = "throw", context.arg = new TypeError("iterator result is not an object"), context.delegate = null, ContinueSentinel); } function pushTryEntry(locs) { var entry = { tryLoc: locs[0] }; 1 in locs && (entry.catchLoc = locs[1]), 2 in locs && (entry.finallyLoc = locs[2], entry.afterLoc = locs[3]), this.tryEntries.push(entry); } function resetTryEntry(entry) { var record = entry.completion || {}; record.type = "normal", delete record.arg, entry.completion = record; } function Context(tryLocsList) { this.tryEntries = [{ tryLoc: "root" }], tryLocsList.forEach(pushTryEntry, this), this.reset(!0); } function values(iterable) { if (iterable) { var iteratorMethod = iterable[iteratorSymbol]; if (iteratorMethod) return iteratorMethod.call(iterable); if ("function" == typeof iterable.next) return iterable; if (!isNaN(iterable.length)) { var i = -1, next = function next() { for (; ++i < iterable.length;) { if (hasOwn.call(iterable, i)) return next.value = iterable[i], next.done = !1, next; } return next.value = undefined, next.done = !0, next; }; return next.next = next; } } return { next: doneResult }; } function doneResult() { return { value: undefined, done: !0 }; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, defineProperty(Gp, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), defineProperty(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"), exports.isGeneratorFunction = function (genFun) { var ctor = "function" == typeof genFun && genFun.constructor; return !!ctor && (ctor === GeneratorFunction || "GeneratorFunction" === (ctor.displayName || ctor.name)); }, exports.mark = function (genFun) { return Object.setPrototypeOf ? Object.setPrototypeOf(genFun, GeneratorFunctionPrototype) : (genFun.__proto__ = GeneratorFunctionPrototype, define(genFun, toStringTagSymbol, "GeneratorFunction")), genFun.prototype = Object.create(Gp), genFun; }, exports.awrap = function (arg) { return { __await: arg }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, asyncIteratorSymbol, function () { return this; }), exports.AsyncIterator = AsyncIterator, exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) { void 0 === PromiseImpl && (PromiseImpl = Promise); var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl); return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function (result) { return result.done ? result.value : iter.next(); }); }, defineIteratorMethods(Gp), define(Gp, toStringTagSymbol, "Generator"), define(Gp, iteratorSymbol, function () { return this; }), define(Gp, "toString", function () { return "[object Generator]"; }), exports.keys = function (val) { var object = Object(val), keys = []; for (var key in object) { keys.push(key); } return keys.reverse(), function next() { for (; keys.length;) { var key = keys.pop(); if (key in object) return next.value = key, next.done = !1, next; } return next.done = !0, next; }; }, exports.values = values, Context.prototype = { constructor: Context, reset: function reset(skipTempReset) { if (this.prev = 0, this.next = 0, this.sent = this._sent = undefined, this.done = !1, this.delegate = null, this.method = "next", this.arg = undefined, this.tryEntries.forEach(resetTryEntry), !skipTempReset) for (var name in this) { "t" === name.charAt(0) && hasOwn.call(this, name) && !isNaN(+name.slice(1)) && (this[name] = undefined); } }, stop: function stop() { this.done = !0; var rootRecord = this.tryEntries[0].completion; if ("throw" === rootRecord.type) throw rootRecord.arg; return this.rval; }, dispatchException: function dispatchException(exception) { if (this.done) throw exception; var context = this; function handle(loc, caught) { return record.type = "throw", record.arg = exception, context.next = loc, caught && (context.method = "next", context.arg = undefined), !!caught; } for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i], record = entry.completion; if ("root" === entry.tryLoc) return handle("end"); if (entry.tryLoc <= this.prev) { var hasCatch = hasOwn.call(entry, "catchLoc"), hasFinally = hasOwn.call(entry, "finallyLoc"); if (hasCatch && hasFinally) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } else if (hasCatch) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); } else { if (!hasFinally) throw new Error("try statement without catch or finally"); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } } } }, abrupt: function abrupt(type, arg) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) { var finallyEntry = entry; break; } } finallyEntry && ("break" === type || "continue" === type) && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc && (finallyEntry = null); var record = finallyEntry ? finallyEntry.completion : {}; return record.type = type, record.arg = arg, finallyEntry ? (this.method = "next", this.next = finallyEntry.finallyLoc, ContinueSentinel) : this.complete(record); }, complete: function complete(record, afterLoc) { if ("throw" === record.type) throw record.arg; return "break" === record.type || "continue" === record.type ? this.next = record.arg : "return" === record.type ? (this.rval = this.arg = record.arg, this.method = "return", this.next = "end") : "normal" === record.type && afterLoc && (this.next = afterLoc), ContinueSentinel; }, finish: function finish(finallyLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.finallyLoc === finallyLoc) return this.complete(entry.completion, entry.afterLoc), resetTryEntry(entry), ContinueSentinel; } }, catch: function _catch(tryLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc === tryLoc) { var record = entry.completion; if ("throw" === record.type) { var thrown = record.arg; resetTryEntry(entry); } return thrown; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(iterable, resultName, nextLoc) { return this.delegate = { iterator: values(iterable), resultName: resultName, nextLoc: nextLoc }, "next" === this.method && (this.arg = undefined), ContinueSentinel; } }, exports; } // import setimmediate to temporary fix dataloader 2.0.0 bug
54
+ 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) { (0, _defineProperty2.default)(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; } // import setimmediate to temporary fix dataloader 2.0.0 bug
56
55
  // @see https://github.com/graphql/dataloader/issues/249
57
56
  var FileFetcherImpl = /*#__PURE__*/function () {
58
57
  function FileFetcherImpl(mediaStore, featureFlags) {
59
58
  var _this = this;
60
59
  (0, _classCallCheck2.default)(this, FileFetcherImpl);
60
+ // TODO: ----- ADD TICKET TO PASS TRACE ID to this.dataloader.load
61
61
  (0, _defineProperty2.default)(this, "createDownloadFileStream", function (id, collectionName, occurrenceKey) {
62
62
  var subject = (0, _createMediaSubject.createMediaSubject)();
63
63
  var poll = new _polling.PollingFunction();
@@ -66,53 +66,51 @@ var FileFetcherImpl = /*#__PURE__*/function () {
66
66
  poll.onError = function (error) {
67
67
  return subject.error(error);
68
68
  };
69
- poll.execute( /*#__PURE__*/(0, _asyncToGenerator2.default)( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
69
+ poll.execute( /*#__PURE__*/(0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee() {
70
70
  var response, fileState;
71
- return _regeneratorRuntime().wrap(function _callee$(_context) {
72
- while (1) {
73
- switch (_context.prev = _context.next) {
74
- case 0:
75
- _context.next = 2;
76
- return _this.dataloader.load({
77
- id: id,
78
- collectionName: collectionName
79
- });
80
- case 2:
81
- response = _context.sent;
82
- if (response) {
83
- _context.next = 5;
84
- break;
85
- }
86
- throw new _error.FileFetcherError('emptyItems', id, {
87
- collectionName: collectionName,
88
- occurrenceKey: occurrenceKey
89
- });
90
- case 5:
91
- if (!(0, _detectEmptyFile.isEmptyFile)(response)) {
92
- _context.next = 7;
93
- break;
94
- }
95
- throw new _error.FileFetcherError('zeroVersionFile', id, {
96
- collectionName: collectionName,
97
- occurrenceKey: occurrenceKey
98
- });
99
- case 7:
100
- fileState = (0, _fileState.mapMediaItemToFileState)(id, response);
101
- subject.next(fileState);
102
- _context.t0 = fileState.status;
103
- _context.next = _context.t0 === 'processing' ? 12 : _context.t0 === 'processed' ? 14 : 16;
71
+ return _regenerator.default.wrap(function _callee$(_context) {
72
+ while (1) switch (_context.prev = _context.next) {
73
+ case 0:
74
+ _context.next = 2;
75
+ return _this.dataloader.load({
76
+ id: id,
77
+ collectionName: collectionName
78
+ });
79
+ case 2:
80
+ response = _context.sent;
81
+ if (response) {
82
+ _context.next = 5;
104
83
  break;
105
- case 12:
106
- // the only case for continuing polling, otherwise this function is run once only
107
- poll.next();
108
- return _context.abrupt("break", 16);
109
- case 14:
110
- subject.complete();
111
- return _context.abrupt("break", 16);
112
- case 16:
113
- case "end":
114
- return _context.stop();
115
- }
84
+ }
85
+ throw new _error.FileFetcherError('emptyItems', id, {
86
+ collectionName: collectionName,
87
+ occurrenceKey: occurrenceKey
88
+ });
89
+ case 5:
90
+ if (!(0, _detectEmptyFile.isEmptyFile)(response)) {
91
+ _context.next = 7;
92
+ break;
93
+ }
94
+ throw new _error.FileFetcherError('zeroVersionFile', id, {
95
+ collectionName: collectionName,
96
+ occurrenceKey: occurrenceKey
97
+ });
98
+ case 7:
99
+ fileState = (0, _fileState.mapMediaItemToFileState)(id, response);
100
+ subject.next(fileState);
101
+ _context.t0 = fileState.status;
102
+ _context.next = _context.t0 === 'processing' ? 12 : _context.t0 === 'processed' ? 14 : 16;
103
+ break;
104
+ case 12:
105
+ // the only case for continuing polling, otherwise this function is run once only
106
+ poll.next();
107
+ return _context.abrupt("break", 16);
108
+ case 14:
109
+ subject.complete();
110
+ return _context.abrupt("break", 16);
111
+ case 16:
112
+ case "end":
113
+ return _context.stop();
116
114
  }
117
115
  }, _callee);
118
116
  })));
@@ -191,8 +189,6 @@ var FileFetcherImpl = /*#__PURE__*/function () {
191
189
  value: function getFileBinaryURL(id, collectionName) {
192
190
  return this.mediaStore.getFileBinaryURL(id, collectionName);
193
191
  }
194
-
195
- // TODO: ----- ADD TICKET TO PASS TRACE ID to this.dataloader.load
196
192
  }, {
197
193
  key: "touchFiles",
198
194
  value: function touchFiles(descriptors, collection, traceContext) {
@@ -227,124 +223,118 @@ var FileFetcherImpl = /*#__PURE__*/function () {
227
223
  }, {
228
224
  key: "uploadExternal",
229
225
  value: function () {
230
- var _uploadExternal = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(url, collection, traceContext) {
226
+ var _uploadExternal = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee4(url, collection, traceContext) {
231
227
  var _this3 = this;
232
228
  var uploadableFileUpfrontIds, id, occurrenceKey, subject, deferredBlob, preview, name, fileState;
233
- return _regeneratorRuntime().wrap(function _callee4$(_context4) {
234
- while (1) {
235
- switch (_context4.prev = _context4.next) {
236
- case 0:
237
- uploadableFileUpfrontIds = this.generateUploadableFileUpfrontIds(collection, traceContext);
238
- id = uploadableFileUpfrontIds.id, occurrenceKey = uploadableFileUpfrontIds.occurrenceKey;
239
- subject = (0, _createMediaSubject.createMediaSubject)();
240
- deferredBlob = fetch(url).then(function (response) {
241
- return response.blob();
242
- }).catch(function () {
243
- return undefined;
244
- });
245
- preview = new Promise( /*#__PURE__*/function () {
246
- var _ref3 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(resolve, reject) {
247
- var blob;
248
- return _regeneratorRuntime().wrap(function _callee2$(_context2) {
249
- while (1) {
250
- switch (_context2.prev = _context2.next) {
251
- case 0:
252
- _context2.next = 2;
253
- return deferredBlob;
254
- case 2:
255
- blob = _context2.sent;
256
- if (!blob) {
257
- reject('Could not fetch the blob');
258
- }
259
- resolve({
260
- value: blob,
261
- origin: 'remote'
262
- });
263
- case 5:
264
- case "end":
265
- return _context2.stop();
229
+ return _regenerator.default.wrap(function _callee4$(_context4) {
230
+ while (1) switch (_context4.prev = _context4.next) {
231
+ case 0:
232
+ uploadableFileUpfrontIds = this.generateUploadableFileUpfrontIds(collection, traceContext);
233
+ id = uploadableFileUpfrontIds.id, occurrenceKey = uploadableFileUpfrontIds.occurrenceKey;
234
+ subject = (0, _createMediaSubject.createMediaSubject)();
235
+ deferredBlob = fetch(url).then(function (response) {
236
+ return response.blob();
237
+ }).catch(function () {
238
+ return undefined;
239
+ });
240
+ preview = new Promise( /*#__PURE__*/function () {
241
+ var _ref3 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2(resolve, reject) {
242
+ var blob;
243
+ return _regenerator.default.wrap(function _callee2$(_context2) {
244
+ while (1) switch (_context2.prev = _context2.next) {
245
+ case 0:
246
+ _context2.next = 2;
247
+ return deferredBlob;
248
+ case 2:
249
+ blob = _context2.sent;
250
+ if (!blob) {
251
+ reject('Could not fetch the blob');
266
252
  }
267
- }
268
- }, _callee2);
269
- }));
270
- return function (_x4, _x5) {
271
- return _ref3.apply(this, arguments);
272
- };
273
- }());
274
- name = url.split('/').pop() || ''; // we create a initial fileState with the minimum info that we have at this point
275
- fileState = {
276
- status: 'processing',
277
- name: name,
278
- size: 0,
279
- mediaType: 'unknown',
280
- mimeType: '',
281
- id: id,
282
- occurrenceKey: occurrenceKey,
283
- preview: preview
253
+ resolve({
254
+ value: blob,
255
+ origin: 'remote'
256
+ });
257
+ case 5:
258
+ case "end":
259
+ return _context2.stop();
260
+ }
261
+ }, _callee2);
262
+ }));
263
+ return function (_x4, _x5) {
264
+ return _ref3.apply(this, arguments);
284
265
  };
285
- subject.next(fileState);
286
- // we save it into the cache as soon as possible, in case someone subscribes
287
- (0, _fileStreamsCache.getFileStreamsCache)().set(id, subject);
288
- return _context4.abrupt("return", new Promise( /*#__PURE__*/function () {
289
- var _ref4 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(resolve, reject) {
290
- var blob, type, size, file, mediaType, dimensions;
291
- return _regeneratorRuntime().wrap(function _callee3$(_context3) {
292
- while (1) {
293
- switch (_context3.prev = _context3.next) {
294
- case 0:
295
- _context3.next = 2;
296
- return deferredBlob;
297
- case 2:
298
- blob = _context3.sent;
299
- if (blob) {
300
- _context3.next = 5;
301
- break;
302
- }
303
- return _context3.abrupt("return", reject('Could not download remote file'));
304
- case 5:
305
- type = blob.type, size = blob.size;
306
- file = {
307
- content: blob,
308
- mimeType: type,
309
- collection: collection,
310
- name: name
311
- };
312
- mediaType = (0, _mediaTypeUtils.getMediaTypeFromMimeType)(type); // we emit a richer state after the blob is fetched
313
- subject.next({
314
- status: 'processing',
315
- name: name,
316
- size: size,
317
- mediaType: mediaType,
318
- mimeType: type,
319
- id: id,
320
- occurrenceKey: occurrenceKey,
321
- preview: preview
322
- });
323
- // we don't want to wait for the file to be upload
324
- _this3.upload(file, undefined, uploadableFileUpfrontIds, traceContext);
325
- _context3.next = 12;
326
- return (0, _getDimensionsFromBlob.getDimensionsFromBlob)(mediaType, blob);
327
- case 12:
328
- dimensions = _context3.sent;
329
- resolve({
330
- dimensions: dimensions,
331
- uploadableFileUpfrontIds: uploadableFileUpfrontIds
332
- });
333
- case 14:
334
- case "end":
335
- return _context3.stop();
266
+ }());
267
+ name = url.split('/').pop() || ''; // we create a initial fileState with the minimum info that we have at this point
268
+ fileState = {
269
+ status: 'processing',
270
+ name: name,
271
+ size: 0,
272
+ mediaType: 'unknown',
273
+ mimeType: '',
274
+ id: id,
275
+ occurrenceKey: occurrenceKey,
276
+ preview: preview
277
+ };
278
+ subject.next(fileState);
279
+ // we save it into the cache as soon as possible, in case someone subscribes
280
+ (0, _fileStreamsCache.getFileStreamsCache)().set(id, subject);
281
+ return _context4.abrupt("return", new Promise( /*#__PURE__*/function () {
282
+ var _ref4 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee3(resolve, reject) {
283
+ var blob, type, size, file, mediaType, dimensions;
284
+ return _regenerator.default.wrap(function _callee3$(_context3) {
285
+ while (1) switch (_context3.prev = _context3.next) {
286
+ case 0:
287
+ _context3.next = 2;
288
+ return deferredBlob;
289
+ case 2:
290
+ blob = _context3.sent;
291
+ if (blob) {
292
+ _context3.next = 5;
293
+ break;
336
294
  }
337
- }
338
- }, _callee3);
339
- }));
340
- return function (_x6, _x7) {
341
- return _ref4.apply(this, arguments);
342
- };
343
- }()));
344
- case 10:
345
- case "end":
346
- return _context4.stop();
347
- }
295
+ return _context3.abrupt("return", reject('Could not download remote file'));
296
+ case 5:
297
+ type = blob.type, size = blob.size;
298
+ file = {
299
+ content: blob,
300
+ mimeType: type,
301
+ collection: collection,
302
+ name: name
303
+ };
304
+ mediaType = (0, _mediaTypeUtils.getMediaTypeFromMimeType)(type); // we emit a richer state after the blob is fetched
305
+ subject.next({
306
+ status: 'processing',
307
+ name: name,
308
+ size: size,
309
+ mediaType: mediaType,
310
+ mimeType: type,
311
+ id: id,
312
+ occurrenceKey: occurrenceKey,
313
+ preview: preview
314
+ });
315
+ // we don't want to wait for the file to be upload
316
+ _this3.upload(file, undefined, uploadableFileUpfrontIds, traceContext);
317
+ _context3.next = 12;
318
+ return (0, _getDimensionsFromBlob.getDimensionsFromBlob)(mediaType, blob);
319
+ case 12:
320
+ dimensions = _context3.sent;
321
+ resolve({
322
+ dimensions: dimensions,
323
+ uploadableFileUpfrontIds: uploadableFileUpfrontIds
324
+ });
325
+ case 14:
326
+ case "end":
327
+ return _context3.stop();
328
+ }
329
+ }, _callee3);
330
+ }));
331
+ return function (_x6, _x7) {
332
+ return _ref4.apply(this, arguments);
333
+ };
334
+ }()));
335
+ case 10:
336
+ case "end":
337
+ return _context4.stop();
348
338
  }
349
339
  }, _callee4, this);
350
340
  }));
@@ -498,33 +488,31 @@ var FileFetcherImpl = /*#__PURE__*/function () {
498
488
  }, {
499
489
  key: "downloadBinary",
500
490
  value: function () {
501
- var _downloadBinary = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(id) {
491
+ var _downloadBinary = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee5(id) {
502
492
  var name,
503
493
  collectionName,
504
494
  url,
505
495
  _args5 = arguments;
506
- return _regeneratorRuntime().wrap(function _callee5$(_context5) {
507
- while (1) {
508
- switch (_context5.prev = _context5.next) {
509
- case 0:
510
- name = _args5.length > 1 && _args5[1] !== undefined ? _args5[1] : 'download';
511
- collectionName = _args5.length > 2 ? _args5[2] : undefined;
512
- _context5.next = 4;
513
- return this.mediaStore.getFileBinaryURL(id, collectionName);
514
- case 4:
515
- url = _context5.sent;
516
- (0, _downloadUrl.downloadUrl)(url, {
517
- name: name
518
- });
519
- _globalMediaEventEmitter.globalMediaEventEmitter.emit('media-viewed', {
520
- fileId: id,
521
- isUserCollection: collectionName === _constants.RECENTS_COLLECTION,
522
- viewingLevel: 'download'
523
- });
524
- case 7:
525
- case "end":
526
- return _context5.stop();
527
- }
496
+ return _regenerator.default.wrap(function _callee5$(_context5) {
497
+ while (1) switch (_context5.prev = _context5.next) {
498
+ case 0:
499
+ name = _args5.length > 1 && _args5[1] !== undefined ? _args5[1] : 'download';
500
+ collectionName = _args5.length > 2 ? _args5[2] : undefined;
501
+ _context5.next = 4;
502
+ return this.mediaStore.getFileBinaryURL(id, collectionName);
503
+ case 4:
504
+ url = _context5.sent;
505
+ (0, _downloadUrl.downloadUrl)(url, {
506
+ name: name
507
+ });
508
+ _globalMediaEventEmitter.globalMediaEventEmitter.emit('media-viewed', {
509
+ fileId: id,
510
+ isUserCollection: collectionName === _constants.RECENTS_COLLECTION,
511
+ viewingLevel: 'download'
512
+ });
513
+ case 7:
514
+ case "end":
515
+ return _context5.stop();
528
516
  }
529
517
  }, _callee5, this);
530
518
  }));
@@ -536,7 +524,7 @@ var FileFetcherImpl = /*#__PURE__*/function () {
536
524
  }, {
537
525
  key: "copyFile",
538
526
  value: function () {
539
- var _copyFile = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(source, destination) {
527
+ var _copyFile = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee6(source, destination) {
540
528
  var options,
541
529
  traceContext,
542
530
  authProvider,
@@ -566,120 +554,118 @@ var FileFetcherImpl = /*#__PURE__*/function () {
566
554
  previewOverride,
567
555
  _fileCache,
568
556
  _args6 = arguments;
569
- return _regeneratorRuntime().wrap(function _callee6$(_context6) {
570
- while (1) {
571
- switch (_context6.prev = _context6.next) {
572
- case 0:
573
- options = _args6.length > 2 && _args6[2] !== undefined ? _args6[2] : {};
574
- traceContext = _args6.length > 3 ? _args6[3] : undefined;
575
- authProvider = source.authProvider, sourceCollection = source.collection, id = source.id;
576
- destinationAuthProvider = destination.authProvider, destinationCollectionName = destination.collection, replaceFileId = destination.replaceFileId, occurrenceKey = destination.occurrenceKey;
577
- preview = options.preview, mimeType = options.mimeType;
578
- mediaStore = destination.mediaStore || new _mediaStore.MediaStore({
579
- authProvider: destinationAuthProvider
580
- });
581
- _context6.t0 = _mediaCore.authToOwner;
582
- _context6.next = 9;
583
- return authProvider({
584
- collectionName: sourceCollection
585
- });
586
- case 9:
587
- _context6.t1 = _context6.sent;
588
- owner = (0, _context6.t0)(_context6.t1);
589
- body = {
590
- sourceFile: {
591
- id: id,
592
- collection: sourceCollection,
593
- owner: owner
594
- }
595
- };
596
- params = {
597
- collection: destinationCollectionName,
598
- replaceFileId: replaceFileId,
599
- occurrenceKey: occurrenceKey
600
- };
601
- cache = (0, _fileStreamsCache.getFileStreamsCache)();
602
- _context6.prev = 14;
603
- _context6.next = 17;
604
- return mediaStore.copyFileWithToken(body, params, traceContext);
605
- case 17:
606
- _yield$mediaStore$cop = _context6.sent;
607
- copiedFile = _yield$mediaStore$cop.data;
608
- // if we were passed a "mimeType", we propagate it into copiedFileWithMimeType
609
- copiedFileWithMimeType = _objectSpread(_objectSpread({}, copiedFile), mimeType ? {
610
- mimeType: mimeType
611
- } : undefined);
612
- copiedId = copiedFileWithMimeType.id, copiedMimeType = copiedFileWithMimeType.mimeType; // backend may return an "unknown" mediaType just after the copy
613
- // it's better to deduce it from "copiedMimeType" using getMediaTypeFromMimeType()
614
- mediaType = copiedMimeType ? (0, _mediaTypeUtils.getMediaTypeFromMimeType)(copiedMimeType) : 'unknown';
615
- copiedFileState = (0, _fileState.mapMediaFileToFileState)({
616
- data: copiedFileWithMimeType
617
- });
618
- fileCache = cache.get(copiedId);
619
- subject = fileCache || (0, _createMediaSubject.createMediaSubject)(); // if we were passed a "preview", we propagate it into the copiedFileState
620
- previewOverride = !(0, _fileState.isErrorFileState)(copiedFileState) && !!preview ? {
621
- preview: preview
622
- } : {};
623
- _context6.t2 = !(0, _fileState.isFinalFileState)(copiedFileState) &&
624
- // mimeType should always be returned by "copyFileWithToken"
625
- // but in case it's not, we don't want to penalize "copyFile"
626
- copiedMimeType;
627
- if (!_context6.t2) {
628
- _context6.next = 31;
629
- break;
630
- }
631
- _context6.next = 30;
632
- return (0, _shouldFetchRemoteFileStates.shouldFetchRemoteFileStates)(mediaType, copiedMimeType, preview);
633
- case 30:
634
- _context6.t2 = _context6.sent;
635
- case 31:
636
- if (!_context6.t2) {
637
- _context6.next = 36;
638
- break;
557
+ return _regenerator.default.wrap(function _callee6$(_context6) {
558
+ while (1) switch (_context6.prev = _context6.next) {
559
+ case 0:
560
+ options = _args6.length > 2 && _args6[2] !== undefined ? _args6[2] : {};
561
+ traceContext = _args6.length > 3 ? _args6[3] : undefined;
562
+ authProvider = source.authProvider, sourceCollection = source.collection, id = source.id;
563
+ destinationAuthProvider = destination.authProvider, destinationCollectionName = destination.collection, replaceFileId = destination.replaceFileId, occurrenceKey = destination.occurrenceKey;
564
+ preview = options.preview, mimeType = options.mimeType;
565
+ mediaStore = destination.mediaStore || new _mediaStore.MediaStore({
566
+ authProvider: destinationAuthProvider
567
+ });
568
+ _context6.t0 = _mediaCore.authToOwner;
569
+ _context6.next = 9;
570
+ return authProvider({
571
+ collectionName: sourceCollection
572
+ });
573
+ case 9:
574
+ _context6.t1 = _context6.sent;
575
+ owner = (0, _context6.t0)(_context6.t1);
576
+ body = {
577
+ sourceFile: {
578
+ id: id,
579
+ collection: sourceCollection,
580
+ owner: owner
639
581
  }
640
- subject.next(_objectSpread(_objectSpread(_objectSpread({}, copiedFileState), (0, _overrideMediaTypeIfUnknown.overrideMediaTypeIfUnknown)(copiedFileState, mediaType)), previewOverride));
641
- processingSubscription = this.createDownloadFileStream(copiedId, destinationCollectionName, occurrenceKey).subscribe({
642
- next: function next(remoteFileState) {
643
- return subject.next(_objectSpread(_objectSpread(_objectSpread({}, remoteFileState), (0, _overrideMediaTypeIfUnknown.overrideMediaTypeIfUnknown)(remoteFileState, mediaType)), !(0, _fileState.isErrorFileState)(remoteFileState) && previewOverride));
644
- },
645
- error: function error(err) {
646
- return subject.error(err);
647
- },
648
- complete: function complete() {
649
- return subject.complete();
650
- }
651
- });
652
- _context6.next = 37;
582
+ };
583
+ params = {
584
+ collection: destinationCollectionName,
585
+ replaceFileId: replaceFileId,
586
+ occurrenceKey: occurrenceKey
587
+ };
588
+ cache = (0, _fileStreamsCache.getFileStreamsCache)();
589
+ _context6.prev = 14;
590
+ _context6.next = 17;
591
+ return mediaStore.copyFileWithToken(body, params, traceContext);
592
+ case 17:
593
+ _yield$mediaStore$cop = _context6.sent;
594
+ copiedFile = _yield$mediaStore$cop.data;
595
+ // if we were passed a "mimeType", we propagate it into copiedFileWithMimeType
596
+ copiedFileWithMimeType = _objectSpread(_objectSpread({}, copiedFile), mimeType ? {
597
+ mimeType: mimeType
598
+ } : undefined);
599
+ copiedId = copiedFileWithMimeType.id, copiedMimeType = copiedFileWithMimeType.mimeType; // backend may return an "unknown" mediaType just after the copy
600
+ // it's better to deduce it from "copiedMimeType" using getMediaTypeFromMimeType()
601
+ mediaType = copiedMimeType ? (0, _mediaTypeUtils.getMediaTypeFromMimeType)(copiedMimeType) : 'unknown';
602
+ copiedFileState = (0, _fileState.mapMediaFileToFileState)({
603
+ data: copiedFileWithMimeType
604
+ });
605
+ fileCache = cache.get(copiedId);
606
+ subject = fileCache || (0, _createMediaSubject.createMediaSubject)(); // if we were passed a "preview", we propagate it into the copiedFileState
607
+ previewOverride = !(0, _fileState.isErrorFileState)(copiedFileState) && !!preview ? {
608
+ preview: preview
609
+ } : {};
610
+ _context6.t2 = !(0, _fileState.isFinalFileState)(copiedFileState) &&
611
+ // mimeType should always be returned by "copyFileWithToken"
612
+ // but in case it's not, we don't want to penalize "copyFile"
613
+ copiedMimeType;
614
+ if (!_context6.t2) {
615
+ _context6.next = 31;
653
616
  break;
654
- case 36:
655
- if (!(0, _fileState.isProcessingFileState)(copiedFileState)) {
656
- subject.next(_objectSpread(_objectSpread({}, copiedFileState), !(0, _fileState.isErrorFileState)(copiedFileState) && previewOverride));
657
- }
658
- case 37:
659
- if (!cache.has(copiedId)) {
660
- (0, _fileStreamsCache.getFileStreamsCache)().set(copiedId, subject);
661
- }
662
- return _context6.abrupt("return", copiedFile);
663
- case 41:
664
- _context6.prev = 41;
665
- _context6.t3 = _context6["catch"](14);
666
- if (processingSubscription) {
667
- processingSubscription.unsubscribe();
617
+ }
618
+ _context6.next = 30;
619
+ return (0, _shouldFetchRemoteFileStates.shouldFetchRemoteFileStates)(mediaType, copiedMimeType, preview);
620
+ case 30:
621
+ _context6.t2 = _context6.sent;
622
+ case 31:
623
+ if (!_context6.t2) {
624
+ _context6.next = 36;
625
+ break;
626
+ }
627
+ subject.next(_objectSpread(_objectSpread(_objectSpread({}, copiedFileState), (0, _overrideMediaTypeIfUnknown.overrideMediaTypeIfUnknown)(copiedFileState, mediaType)), previewOverride));
628
+ processingSubscription = this.createDownloadFileStream(copiedId, destinationCollectionName, occurrenceKey).subscribe({
629
+ next: function next(remoteFileState) {
630
+ return subject.next(_objectSpread(_objectSpread(_objectSpread({}, remoteFileState), (0, _overrideMediaTypeIfUnknown.overrideMediaTypeIfUnknown)(remoteFileState, mediaType)), !(0, _fileState.isErrorFileState)(remoteFileState) && previewOverride));
631
+ },
632
+ error: function error(err) {
633
+ return subject.error(err);
634
+ },
635
+ complete: function complete() {
636
+ return subject.complete();
668
637
  }
669
- if (replaceFileId) {
670
- _fileCache = cache.get(replaceFileId);
671
- if (_fileCache) {
672
- _fileCache.error(_context6.t3);
673
- } else {
674
- // Create a new subject with the error state for new subscriptions
675
- cache.set(id, (0, _createMediaSubject.createMediaSubject)(_context6.t3));
676
- }
638
+ });
639
+ _context6.next = 37;
640
+ break;
641
+ case 36:
642
+ if (!(0, _fileState.isProcessingFileState)(copiedFileState)) {
643
+ subject.next(_objectSpread(_objectSpread({}, copiedFileState), !(0, _fileState.isErrorFileState)(copiedFileState) && previewOverride));
644
+ }
645
+ case 37:
646
+ if (!cache.has(copiedId)) {
647
+ (0, _fileStreamsCache.getFileStreamsCache)().set(copiedId, subject);
648
+ }
649
+ return _context6.abrupt("return", copiedFile);
650
+ case 41:
651
+ _context6.prev = 41;
652
+ _context6.t3 = _context6["catch"](14);
653
+ if (processingSubscription) {
654
+ processingSubscription.unsubscribe();
655
+ }
656
+ if (replaceFileId) {
657
+ _fileCache = cache.get(replaceFileId);
658
+ if (_fileCache) {
659
+ _fileCache.error(_context6.t3);
660
+ } else {
661
+ // Create a new subject with the error state for new subscriptions
662
+ cache.set(id, (0, _createMediaSubject.createMediaSubject)(_context6.t3));
677
663
  }
678
- throw _context6.t3;
679
- case 46:
680
- case "end":
681
- return _context6.stop();
682
- }
664
+ }
665
+ throw _context6.t3;
666
+ case 46:
667
+ case "end":
668
+ return _context6.stop();
683
669
  }
684
670
  }, _callee6, this, [[14, 41]]);
685
671
  }));