@atlaskit/media-client 21.0.0 → 21.1.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.
- package/CHANGELOG.md +6 -0
- package/dist/cjs/client/file-fetcher/error.js +4 -4
- package/dist/cjs/client/file-fetcher/index.js +283 -297
- package/dist/cjs/client/media-client.js +42 -48
- package/dist/cjs/client/media-store/index.js +389 -310
- package/dist/cjs/client/media-store/resolveAuth.js +33 -36
- package/dist/cjs/client/stargate-client.js +17 -20
- package/dist/cjs/index.js +6 -0
- package/dist/cjs/models/media.js +4 -4
- package/dist/cjs/uploader/error.js +4 -4
- package/dist/cjs/uploader/index.js +97 -108
- package/dist/cjs/utils/convertBase64ToBlob.js +2 -2
- package/dist/cjs/utils/createFileDataLoader.js +68 -73
- package/dist/cjs/utils/getDimensionsFromBlob.js +26 -29
- package/dist/cjs/utils/getVideoDimensionsFromBlob.js +27 -30
- package/dist/cjs/utils/hashing/hasherCreator.js +35 -37
- package/dist/cjs/utils/mobileUpload/error.js +4 -4
- package/dist/cjs/utils/mobileUpload/helpers.js +44 -47
- package/dist/cjs/utils/mobileUpload/stateMachine/index.js +17 -20
- package/dist/cjs/utils/parseJwt.js +52 -0
- package/dist/cjs/utils/polling/index.js +43 -46
- package/dist/cjs/utils/request/errors.js +9 -9
- package/dist/cjs/utils/request/helpers.js +154 -167
- package/dist/cjs/utils/request/index.js +27 -30
- package/dist/cjs/utils/shouldFetchRemoteFileStates.js +42 -45
- package/dist/cjs/version.json +1 -1
- package/dist/es2019/client/file-fetcher/index.js +1 -3
- package/dist/es2019/client/media-store/index.js +58 -6
- package/dist/es2019/index.js +1 -1
- package/dist/es2019/models/media.js +3 -3
- package/dist/es2019/utils/parseJwt.js +46 -0
- package/dist/es2019/version.json +1 -1
- package/dist/esm/client/file-fetcher/error.js +4 -4
- package/dist/esm/client/file-fetcher/index.js +282 -296
- package/dist/esm/client/media-client.js +40 -47
- package/dist/esm/client/media-store/index.js +389 -310
- package/dist/esm/client/media-store/resolveAuth.js +33 -36
- package/dist/esm/client/stargate-client.js +17 -20
- package/dist/esm/index.js +1 -1
- package/dist/esm/models/media.js +3 -3
- package/dist/esm/uploader/error.js +4 -4
- package/dist/esm/uploader/index.js +97 -108
- package/dist/esm/utils/convertBase64ToBlob.js +2 -2
- package/dist/esm/utils/createFileDataLoader.js +68 -73
- package/dist/esm/utils/getDimensionsFromBlob.js +26 -29
- package/dist/esm/utils/getVideoDimensionsFromBlob.js +27 -30
- package/dist/esm/utils/hashing/hasherCreator.js +31 -34
- package/dist/esm/utils/mobileUpload/error.js +4 -4
- package/dist/esm/utils/mobileUpload/helpers.js +44 -47
- package/dist/esm/utils/mobileUpload/stateMachine/index.js +17 -20
- package/dist/esm/utils/parseJwt.js +46 -0
- package/dist/esm/utils/polling/index.js +43 -46
- package/dist/esm/utils/request/errors.js +9 -9
- package/dist/esm/utils/request/helpers.js +154 -167
- package/dist/esm/utils/request/index.js +27 -30
- package/dist/esm/utils/shouldFetchRemoteFileStates.js +42 -45
- package/dist/esm/version.json +1 -1
- package/dist/types/client/media-store/index.d.ts +15 -0
- package/dist/types/index.d.ts +1 -1
- package/dist/types/utils/parseJwt.d.ts +1 -0
- package/package.json +2 -2
- package/report.api.md +31 -0
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import _typeof from "@babel/runtime/helpers/typeof";
|
|
2
1
|
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
|
|
3
2
|
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
|
|
4
3
|
import _createClass from "@babel/runtime/helpers/createClass";
|
|
5
4
|
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
6
5
|
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; }
|
|
7
6
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
8
|
-
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; }
|
|
7
|
+
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
9
8
|
import { Subscription } from 'rxjs/Subscription';
|
|
10
9
|
import { of } from 'rxjs/observable/of';
|
|
11
10
|
import { map } from 'rxjs/operators/map';
|
|
@@ -41,6 +40,7 @@ export var FileFetcherImpl = /*#__PURE__*/function () {
|
|
|
41
40
|
function FileFetcherImpl(mediaStore, featureFlags) {
|
|
42
41
|
var _this = this;
|
|
43
42
|
_classCallCheck(this, FileFetcherImpl);
|
|
43
|
+
// TODO: ----- ADD TICKET TO PASS TRACE ID to this.dataloader.load
|
|
44
44
|
_defineProperty(this, "createDownloadFileStream", function (id, collectionName, occurrenceKey) {
|
|
45
45
|
var subject = createMediaSubject();
|
|
46
46
|
var poll = new PollingFunction();
|
|
@@ -49,53 +49,51 @@ export var FileFetcherImpl = /*#__PURE__*/function () {
|
|
|
49
49
|
poll.onError = function (error) {
|
|
50
50
|
return subject.error(error);
|
|
51
51
|
};
|
|
52
|
-
poll.execute( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime
|
|
52
|
+
poll.execute( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
|
|
53
53
|
var response, fileState;
|
|
54
|
-
return _regeneratorRuntime
|
|
55
|
-
while (1) {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
_context.next = 5;
|
|
67
|
-
break;
|
|
68
|
-
}
|
|
69
|
-
throw new FileFetcherError('emptyItems', id, {
|
|
70
|
-
collectionName: collectionName,
|
|
71
|
-
occurrenceKey: occurrenceKey
|
|
72
|
-
});
|
|
73
|
-
case 5:
|
|
74
|
-
if (!isEmptyFile(response)) {
|
|
75
|
-
_context.next = 7;
|
|
76
|
-
break;
|
|
77
|
-
}
|
|
78
|
-
throw new FileFetcherError('zeroVersionFile', id, {
|
|
79
|
-
collectionName: collectionName,
|
|
80
|
-
occurrenceKey: occurrenceKey
|
|
81
|
-
});
|
|
82
|
-
case 7:
|
|
83
|
-
fileState = mapMediaItemToFileState(id, response);
|
|
84
|
-
subject.next(fileState);
|
|
85
|
-
_context.t0 = fileState.status;
|
|
86
|
-
_context.next = _context.t0 === 'processing' ? 12 : _context.t0 === 'processed' ? 14 : 16;
|
|
54
|
+
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
55
|
+
while (1) switch (_context.prev = _context.next) {
|
|
56
|
+
case 0:
|
|
57
|
+
_context.next = 2;
|
|
58
|
+
return _this.dataloader.load({
|
|
59
|
+
id: id,
|
|
60
|
+
collectionName: collectionName
|
|
61
|
+
});
|
|
62
|
+
case 2:
|
|
63
|
+
response = _context.sent;
|
|
64
|
+
if (response) {
|
|
65
|
+
_context.next = 5;
|
|
87
66
|
break;
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
67
|
+
}
|
|
68
|
+
throw new FileFetcherError('emptyItems', id, {
|
|
69
|
+
collectionName: collectionName,
|
|
70
|
+
occurrenceKey: occurrenceKey
|
|
71
|
+
});
|
|
72
|
+
case 5:
|
|
73
|
+
if (!isEmptyFile(response)) {
|
|
74
|
+
_context.next = 7;
|
|
75
|
+
break;
|
|
76
|
+
}
|
|
77
|
+
throw new FileFetcherError('zeroVersionFile', id, {
|
|
78
|
+
collectionName: collectionName,
|
|
79
|
+
occurrenceKey: occurrenceKey
|
|
80
|
+
});
|
|
81
|
+
case 7:
|
|
82
|
+
fileState = mapMediaItemToFileState(id, response);
|
|
83
|
+
subject.next(fileState);
|
|
84
|
+
_context.t0 = fileState.status;
|
|
85
|
+
_context.next = _context.t0 === 'processing' ? 12 : _context.t0 === 'processed' ? 14 : 16;
|
|
86
|
+
break;
|
|
87
|
+
case 12:
|
|
88
|
+
// the only case for continuing polling, otherwise this function is run once only
|
|
89
|
+
poll.next();
|
|
90
|
+
return _context.abrupt("break", 16);
|
|
91
|
+
case 14:
|
|
92
|
+
subject.complete();
|
|
93
|
+
return _context.abrupt("break", 16);
|
|
94
|
+
case 16:
|
|
95
|
+
case "end":
|
|
96
|
+
return _context.stop();
|
|
99
97
|
}
|
|
100
98
|
}, _callee);
|
|
101
99
|
})));
|
|
@@ -174,8 +172,6 @@ export var FileFetcherImpl = /*#__PURE__*/function () {
|
|
|
174
172
|
value: function getFileBinaryURL(id, collectionName) {
|
|
175
173
|
return this.mediaStore.getFileBinaryURL(id, collectionName);
|
|
176
174
|
}
|
|
177
|
-
|
|
178
|
-
// TODO: ----- ADD TICKET TO PASS TRACE ID to this.dataloader.load
|
|
179
175
|
}, {
|
|
180
176
|
key: "touchFiles",
|
|
181
177
|
value: function touchFiles(descriptors, collection, traceContext) {
|
|
@@ -210,124 +206,118 @@ export var FileFetcherImpl = /*#__PURE__*/function () {
|
|
|
210
206
|
}, {
|
|
211
207
|
key: "uploadExternal",
|
|
212
208
|
value: function () {
|
|
213
|
-
var _uploadExternal = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime
|
|
209
|
+
var _uploadExternal = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4(url, collection, traceContext) {
|
|
214
210
|
var _this3 = this;
|
|
215
211
|
var uploadableFileUpfrontIds, id, occurrenceKey, subject, deferredBlob, preview, name, fileState;
|
|
216
|
-
return _regeneratorRuntime
|
|
217
|
-
while (1) {
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
var
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
if (!blob) {
|
|
240
|
-
reject('Could not fetch the blob');
|
|
241
|
-
}
|
|
242
|
-
resolve({
|
|
243
|
-
value: blob,
|
|
244
|
-
origin: 'remote'
|
|
245
|
-
});
|
|
246
|
-
case 5:
|
|
247
|
-
case "end":
|
|
248
|
-
return _context2.stop();
|
|
212
|
+
return _regeneratorRuntime.wrap(function _callee4$(_context4) {
|
|
213
|
+
while (1) switch (_context4.prev = _context4.next) {
|
|
214
|
+
case 0:
|
|
215
|
+
uploadableFileUpfrontIds = this.generateUploadableFileUpfrontIds(collection, traceContext);
|
|
216
|
+
id = uploadableFileUpfrontIds.id, occurrenceKey = uploadableFileUpfrontIds.occurrenceKey;
|
|
217
|
+
subject = createMediaSubject();
|
|
218
|
+
deferredBlob = fetch(url).then(function (response) {
|
|
219
|
+
return response.blob();
|
|
220
|
+
}).catch(function () {
|
|
221
|
+
return undefined;
|
|
222
|
+
});
|
|
223
|
+
preview = new Promise( /*#__PURE__*/function () {
|
|
224
|
+
var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(resolve, reject) {
|
|
225
|
+
var blob;
|
|
226
|
+
return _regeneratorRuntime.wrap(function _callee2$(_context2) {
|
|
227
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
228
|
+
case 0:
|
|
229
|
+
_context2.next = 2;
|
|
230
|
+
return deferredBlob;
|
|
231
|
+
case 2:
|
|
232
|
+
blob = _context2.sent;
|
|
233
|
+
if (!blob) {
|
|
234
|
+
reject('Could not fetch the blob');
|
|
249
235
|
}
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
mediaType: 'unknown',
|
|
263
|
-
mimeType: '',
|
|
264
|
-
id: id,
|
|
265
|
-
occurrenceKey: occurrenceKey,
|
|
266
|
-
preview: preview
|
|
236
|
+
resolve({
|
|
237
|
+
value: blob,
|
|
238
|
+
origin: 'remote'
|
|
239
|
+
});
|
|
240
|
+
case 5:
|
|
241
|
+
case "end":
|
|
242
|
+
return _context2.stop();
|
|
243
|
+
}
|
|
244
|
+
}, _callee2);
|
|
245
|
+
}));
|
|
246
|
+
return function (_x4, _x5) {
|
|
247
|
+
return _ref3.apply(this, arguments);
|
|
267
248
|
};
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
subject.next({
|
|
297
|
-
status: 'processing',
|
|
298
|
-
name: name,
|
|
299
|
-
size: size,
|
|
300
|
-
mediaType: mediaType,
|
|
301
|
-
mimeType: type,
|
|
302
|
-
id: id,
|
|
303
|
-
occurrenceKey: occurrenceKey,
|
|
304
|
-
preview: preview
|
|
305
|
-
});
|
|
306
|
-
// we don't want to wait for the file to be upload
|
|
307
|
-
_this3.upload(file, undefined, uploadableFileUpfrontIds, traceContext);
|
|
308
|
-
_context3.next = 12;
|
|
309
|
-
return getDimensionsFromBlob(mediaType, blob);
|
|
310
|
-
case 12:
|
|
311
|
-
dimensions = _context3.sent;
|
|
312
|
-
resolve({
|
|
313
|
-
dimensions: dimensions,
|
|
314
|
-
uploadableFileUpfrontIds: uploadableFileUpfrontIds
|
|
315
|
-
});
|
|
316
|
-
case 14:
|
|
317
|
-
case "end":
|
|
318
|
-
return _context3.stop();
|
|
249
|
+
}());
|
|
250
|
+
name = url.split('/').pop() || ''; // we create a initial fileState with the minimum info that we have at this point
|
|
251
|
+
fileState = {
|
|
252
|
+
status: 'processing',
|
|
253
|
+
name: name,
|
|
254
|
+
size: 0,
|
|
255
|
+
mediaType: 'unknown',
|
|
256
|
+
mimeType: '',
|
|
257
|
+
id: id,
|
|
258
|
+
occurrenceKey: occurrenceKey,
|
|
259
|
+
preview: preview
|
|
260
|
+
};
|
|
261
|
+
subject.next(fileState);
|
|
262
|
+
// we save it into the cache as soon as possible, in case someone subscribes
|
|
263
|
+
getFileStreamsCache().set(id, subject);
|
|
264
|
+
return _context4.abrupt("return", new Promise( /*#__PURE__*/function () {
|
|
265
|
+
var _ref4 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(resolve, reject) {
|
|
266
|
+
var blob, type, size, file, mediaType, dimensions;
|
|
267
|
+
return _regeneratorRuntime.wrap(function _callee3$(_context3) {
|
|
268
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
269
|
+
case 0:
|
|
270
|
+
_context3.next = 2;
|
|
271
|
+
return deferredBlob;
|
|
272
|
+
case 2:
|
|
273
|
+
blob = _context3.sent;
|
|
274
|
+
if (blob) {
|
|
275
|
+
_context3.next = 5;
|
|
276
|
+
break;
|
|
319
277
|
}
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
278
|
+
return _context3.abrupt("return", reject('Could not download remote file'));
|
|
279
|
+
case 5:
|
|
280
|
+
type = blob.type, size = blob.size;
|
|
281
|
+
file = {
|
|
282
|
+
content: blob,
|
|
283
|
+
mimeType: type,
|
|
284
|
+
collection: collection,
|
|
285
|
+
name: name
|
|
286
|
+
};
|
|
287
|
+
mediaType = getMediaTypeFromMimeType(type); // we emit a richer state after the blob is fetched
|
|
288
|
+
subject.next({
|
|
289
|
+
status: 'processing',
|
|
290
|
+
name: name,
|
|
291
|
+
size: size,
|
|
292
|
+
mediaType: mediaType,
|
|
293
|
+
mimeType: type,
|
|
294
|
+
id: id,
|
|
295
|
+
occurrenceKey: occurrenceKey,
|
|
296
|
+
preview: preview
|
|
297
|
+
});
|
|
298
|
+
// we don't want to wait for the file to be upload
|
|
299
|
+
_this3.upload(file, undefined, uploadableFileUpfrontIds, traceContext);
|
|
300
|
+
_context3.next = 12;
|
|
301
|
+
return getDimensionsFromBlob(mediaType, blob);
|
|
302
|
+
case 12:
|
|
303
|
+
dimensions = _context3.sent;
|
|
304
|
+
resolve({
|
|
305
|
+
dimensions: dimensions,
|
|
306
|
+
uploadableFileUpfrontIds: uploadableFileUpfrontIds
|
|
307
|
+
});
|
|
308
|
+
case 14:
|
|
309
|
+
case "end":
|
|
310
|
+
return _context3.stop();
|
|
311
|
+
}
|
|
312
|
+
}, _callee3);
|
|
313
|
+
}));
|
|
314
|
+
return function (_x6, _x7) {
|
|
315
|
+
return _ref4.apply(this, arguments);
|
|
316
|
+
};
|
|
317
|
+
}()));
|
|
318
|
+
case 10:
|
|
319
|
+
case "end":
|
|
320
|
+
return _context4.stop();
|
|
331
321
|
}
|
|
332
322
|
}, _callee4, this);
|
|
333
323
|
}));
|
|
@@ -481,33 +471,31 @@ export var FileFetcherImpl = /*#__PURE__*/function () {
|
|
|
481
471
|
}, {
|
|
482
472
|
key: "downloadBinary",
|
|
483
473
|
value: function () {
|
|
484
|
-
var _downloadBinary = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime
|
|
474
|
+
var _downloadBinary = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee5(id) {
|
|
485
475
|
var name,
|
|
486
476
|
collectionName,
|
|
487
477
|
url,
|
|
488
478
|
_args5 = arguments;
|
|
489
|
-
return _regeneratorRuntime
|
|
490
|
-
while (1) {
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
return _context5.stop();
|
|
510
|
-
}
|
|
479
|
+
return _regeneratorRuntime.wrap(function _callee5$(_context5) {
|
|
480
|
+
while (1) switch (_context5.prev = _context5.next) {
|
|
481
|
+
case 0:
|
|
482
|
+
name = _args5.length > 1 && _args5[1] !== undefined ? _args5[1] : 'download';
|
|
483
|
+
collectionName = _args5.length > 2 ? _args5[2] : undefined;
|
|
484
|
+
_context5.next = 4;
|
|
485
|
+
return this.mediaStore.getFileBinaryURL(id, collectionName);
|
|
486
|
+
case 4:
|
|
487
|
+
url = _context5.sent;
|
|
488
|
+
downloadUrl(url, {
|
|
489
|
+
name: name
|
|
490
|
+
});
|
|
491
|
+
globalMediaEventEmitter.emit('media-viewed', {
|
|
492
|
+
fileId: id,
|
|
493
|
+
isUserCollection: collectionName === RECENTS_COLLECTION,
|
|
494
|
+
viewingLevel: 'download'
|
|
495
|
+
});
|
|
496
|
+
case 7:
|
|
497
|
+
case "end":
|
|
498
|
+
return _context5.stop();
|
|
511
499
|
}
|
|
512
500
|
}, _callee5, this);
|
|
513
501
|
}));
|
|
@@ -519,7 +507,7 @@ export var FileFetcherImpl = /*#__PURE__*/function () {
|
|
|
519
507
|
}, {
|
|
520
508
|
key: "copyFile",
|
|
521
509
|
value: function () {
|
|
522
|
-
var _copyFile = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime
|
|
510
|
+
var _copyFile = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee6(source, destination) {
|
|
523
511
|
var options,
|
|
524
512
|
traceContext,
|
|
525
513
|
authProvider,
|
|
@@ -549,120 +537,118 @@ export var FileFetcherImpl = /*#__PURE__*/function () {
|
|
|
549
537
|
previewOverride,
|
|
550
538
|
_fileCache,
|
|
551
539
|
_args6 = arguments;
|
|
552
|
-
return _regeneratorRuntime
|
|
553
|
-
while (1) {
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
owner: owner
|
|
577
|
-
}
|
|
578
|
-
};
|
|
579
|
-
params = {
|
|
580
|
-
collection: destinationCollectionName,
|
|
581
|
-
replaceFileId: replaceFileId,
|
|
582
|
-
occurrenceKey: occurrenceKey
|
|
583
|
-
};
|
|
584
|
-
cache = getFileStreamsCache();
|
|
585
|
-
_context6.prev = 14;
|
|
586
|
-
_context6.next = 17;
|
|
587
|
-
return mediaStore.copyFileWithToken(body, params, traceContext);
|
|
588
|
-
case 17:
|
|
589
|
-
_yield$mediaStore$cop = _context6.sent;
|
|
590
|
-
copiedFile = _yield$mediaStore$cop.data;
|
|
591
|
-
// if we were passed a "mimeType", we propagate it into copiedFileWithMimeType
|
|
592
|
-
copiedFileWithMimeType = _objectSpread(_objectSpread({}, copiedFile), mimeType ? {
|
|
593
|
-
mimeType: mimeType
|
|
594
|
-
} : undefined);
|
|
595
|
-
copiedId = copiedFileWithMimeType.id, copiedMimeType = copiedFileWithMimeType.mimeType; // backend may return an "unknown" mediaType just after the copy
|
|
596
|
-
// it's better to deduce it from "copiedMimeType" using getMediaTypeFromMimeType()
|
|
597
|
-
mediaType = copiedMimeType ? getMediaTypeFromMimeType(copiedMimeType) : 'unknown';
|
|
598
|
-
copiedFileState = mapMediaFileToFileState({
|
|
599
|
-
data: copiedFileWithMimeType
|
|
600
|
-
});
|
|
601
|
-
fileCache = cache.get(copiedId);
|
|
602
|
-
subject = fileCache || createMediaSubject(); // if we were passed a "preview", we propagate it into the copiedFileState
|
|
603
|
-
previewOverride = !isErrorFileState(copiedFileState) && !!preview ? {
|
|
604
|
-
preview: preview
|
|
605
|
-
} : {};
|
|
606
|
-
_context6.t2 = !isFinalFileState(copiedFileState) &&
|
|
607
|
-
// mimeType should always be returned by "copyFileWithToken"
|
|
608
|
-
// but in case it's not, we don't want to penalize "copyFile"
|
|
609
|
-
copiedMimeType;
|
|
610
|
-
if (!_context6.t2) {
|
|
611
|
-
_context6.next = 31;
|
|
612
|
-
break;
|
|
613
|
-
}
|
|
614
|
-
_context6.next = 30;
|
|
615
|
-
return shouldFetchRemoteFileStates(mediaType, copiedMimeType, preview);
|
|
616
|
-
case 30:
|
|
617
|
-
_context6.t2 = _context6.sent;
|
|
618
|
-
case 31:
|
|
619
|
-
if (!_context6.t2) {
|
|
620
|
-
_context6.next = 36;
|
|
621
|
-
break;
|
|
540
|
+
return _regeneratorRuntime.wrap(function _callee6$(_context6) {
|
|
541
|
+
while (1) switch (_context6.prev = _context6.next) {
|
|
542
|
+
case 0:
|
|
543
|
+
options = _args6.length > 2 && _args6[2] !== undefined ? _args6[2] : {};
|
|
544
|
+
traceContext = _args6.length > 3 ? _args6[3] : undefined;
|
|
545
|
+
authProvider = source.authProvider, sourceCollection = source.collection, id = source.id;
|
|
546
|
+
destinationAuthProvider = destination.authProvider, destinationCollectionName = destination.collection, replaceFileId = destination.replaceFileId, occurrenceKey = destination.occurrenceKey;
|
|
547
|
+
preview = options.preview, mimeType = options.mimeType;
|
|
548
|
+
mediaStore = destination.mediaStore || new MediaStore({
|
|
549
|
+
authProvider: destinationAuthProvider
|
|
550
|
+
});
|
|
551
|
+
_context6.t0 = authToOwner;
|
|
552
|
+
_context6.next = 9;
|
|
553
|
+
return authProvider({
|
|
554
|
+
collectionName: sourceCollection
|
|
555
|
+
});
|
|
556
|
+
case 9:
|
|
557
|
+
_context6.t1 = _context6.sent;
|
|
558
|
+
owner = (0, _context6.t0)(_context6.t1);
|
|
559
|
+
body = {
|
|
560
|
+
sourceFile: {
|
|
561
|
+
id: id,
|
|
562
|
+
collection: sourceCollection,
|
|
563
|
+
owner: owner
|
|
622
564
|
}
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
565
|
+
};
|
|
566
|
+
params = {
|
|
567
|
+
collection: destinationCollectionName,
|
|
568
|
+
replaceFileId: replaceFileId,
|
|
569
|
+
occurrenceKey: occurrenceKey
|
|
570
|
+
};
|
|
571
|
+
cache = getFileStreamsCache();
|
|
572
|
+
_context6.prev = 14;
|
|
573
|
+
_context6.next = 17;
|
|
574
|
+
return mediaStore.copyFileWithToken(body, params, traceContext);
|
|
575
|
+
case 17:
|
|
576
|
+
_yield$mediaStore$cop = _context6.sent;
|
|
577
|
+
copiedFile = _yield$mediaStore$cop.data;
|
|
578
|
+
// if we were passed a "mimeType", we propagate it into copiedFileWithMimeType
|
|
579
|
+
copiedFileWithMimeType = _objectSpread(_objectSpread({}, copiedFile), mimeType ? {
|
|
580
|
+
mimeType: mimeType
|
|
581
|
+
} : undefined);
|
|
582
|
+
copiedId = copiedFileWithMimeType.id, copiedMimeType = copiedFileWithMimeType.mimeType; // backend may return an "unknown" mediaType just after the copy
|
|
583
|
+
// it's better to deduce it from "copiedMimeType" using getMediaTypeFromMimeType()
|
|
584
|
+
mediaType = copiedMimeType ? getMediaTypeFromMimeType(copiedMimeType) : 'unknown';
|
|
585
|
+
copiedFileState = mapMediaFileToFileState({
|
|
586
|
+
data: copiedFileWithMimeType
|
|
587
|
+
});
|
|
588
|
+
fileCache = cache.get(copiedId);
|
|
589
|
+
subject = fileCache || createMediaSubject(); // if we were passed a "preview", we propagate it into the copiedFileState
|
|
590
|
+
previewOverride = !isErrorFileState(copiedFileState) && !!preview ? {
|
|
591
|
+
preview: preview
|
|
592
|
+
} : {};
|
|
593
|
+
_context6.t2 = !isFinalFileState(copiedFileState) &&
|
|
594
|
+
// mimeType should always be returned by "copyFileWithToken"
|
|
595
|
+
// but in case it's not, we don't want to penalize "copyFile"
|
|
596
|
+
copiedMimeType;
|
|
597
|
+
if (!_context6.t2) {
|
|
598
|
+
_context6.next = 31;
|
|
636
599
|
break;
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
600
|
+
}
|
|
601
|
+
_context6.next = 30;
|
|
602
|
+
return shouldFetchRemoteFileStates(mediaType, copiedMimeType, preview);
|
|
603
|
+
case 30:
|
|
604
|
+
_context6.t2 = _context6.sent;
|
|
605
|
+
case 31:
|
|
606
|
+
if (!_context6.t2) {
|
|
607
|
+
_context6.next = 36;
|
|
608
|
+
break;
|
|
609
|
+
}
|
|
610
|
+
subject.next(_objectSpread(_objectSpread(_objectSpread({}, copiedFileState), overrideMediaTypeIfUnknown(copiedFileState, mediaType)), previewOverride));
|
|
611
|
+
processingSubscription = this.createDownloadFileStream(copiedId, destinationCollectionName, occurrenceKey).subscribe({
|
|
612
|
+
next: function next(remoteFileState) {
|
|
613
|
+
return subject.next(_objectSpread(_objectSpread(_objectSpread({}, remoteFileState), overrideMediaTypeIfUnknown(remoteFileState, mediaType)), !isErrorFileState(remoteFileState) && previewOverride));
|
|
614
|
+
},
|
|
615
|
+
error: function error(err) {
|
|
616
|
+
return subject.error(err);
|
|
617
|
+
},
|
|
618
|
+
complete: function complete() {
|
|
619
|
+
return subject.complete();
|
|
651
620
|
}
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
621
|
+
});
|
|
622
|
+
_context6.next = 37;
|
|
623
|
+
break;
|
|
624
|
+
case 36:
|
|
625
|
+
if (!isProcessingFileState(copiedFileState)) {
|
|
626
|
+
subject.next(_objectSpread(_objectSpread({}, copiedFileState), !isErrorFileState(copiedFileState) && previewOverride));
|
|
627
|
+
}
|
|
628
|
+
case 37:
|
|
629
|
+
if (!cache.has(copiedId)) {
|
|
630
|
+
getFileStreamsCache().set(copiedId, subject);
|
|
631
|
+
}
|
|
632
|
+
return _context6.abrupt("return", copiedFile);
|
|
633
|
+
case 41:
|
|
634
|
+
_context6.prev = 41;
|
|
635
|
+
_context6.t3 = _context6["catch"](14);
|
|
636
|
+
if (processingSubscription) {
|
|
637
|
+
processingSubscription.unsubscribe();
|
|
638
|
+
}
|
|
639
|
+
if (replaceFileId) {
|
|
640
|
+
_fileCache = cache.get(replaceFileId);
|
|
641
|
+
if (_fileCache) {
|
|
642
|
+
_fileCache.error(_context6.t3);
|
|
643
|
+
} else {
|
|
644
|
+
// Create a new subject with the error state for new subscriptions
|
|
645
|
+
cache.set(id, createMediaSubject(_context6.t3));
|
|
660
646
|
}
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
647
|
+
}
|
|
648
|
+
throw _context6.t3;
|
|
649
|
+
case 46:
|
|
650
|
+
case "end":
|
|
651
|
+
return _context6.stop();
|
|
666
652
|
}
|
|
667
653
|
}, _callee6, this, [[14, 41]]);
|
|
668
654
|
}));
|