@atlaskit/media-client 14.0.0 → 14.3.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 +40 -0
- package/dist/cjs/client/file-fetcher/index.js +3 -10
- package/dist/cjs/client/media-client.js +48 -0
- package/dist/cjs/client/media-store/resolveAuth.js +36 -15
- package/dist/cjs/client/mobile-upload.js +98 -0
- package/dist/cjs/index.js +8 -0
- package/dist/cjs/models/mobile-upload.js +5 -0
- package/dist/cjs/utils/createFileDataLoader.js +4 -0
- package/dist/cjs/utils/imageResizeModeToFileImageMode.js +12 -0
- package/dist/cjs/utils/mobileUpload/error.js +67 -0
- package/dist/cjs/utils/mobileUpload/helpers.js +110 -0
- package/dist/cjs/utils/mobileUpload/index.js +49 -0
- package/dist/cjs/utils/mobileUpload/servicesCache.js +12 -0
- package/dist/cjs/utils/mobileUpload/stateMachine/index.js +103 -0
- package/dist/cjs/utils/mobileUpload/stateMachine/states/error.js +10 -0
- package/dist/cjs/utils/mobileUpload/stateMachine/states/processed.js +10 -0
- package/dist/cjs/utils/mobileUpload/stateMachine/states/processing.js +77 -0
- package/dist/cjs/utils/mobileUpload/stateMachine/states/processingFailed.js +10 -0
- package/dist/cjs/utils/mobileUpload/stateMachine/states/uploading.js +70 -0
- package/dist/cjs/utils/mobileUpload/stateMachine/types.js +5 -0
- package/dist/cjs/utils/polling/index.js +5 -6
- package/dist/cjs/utils/setTimeoutPromise.js +22 -0
- package/dist/cjs/version.json +1 -1
- package/dist/es2019/client/file-fetcher/index.js +5 -12
- package/dist/es2019/client/media-client.js +13 -0
- package/dist/es2019/client/media-store/resolveAuth.js +12 -4
- package/dist/es2019/client/mobile-upload.js +80 -0
- package/dist/es2019/index.js +1 -0
- package/dist/es2019/models/mobile-upload.js +1 -0
- package/dist/es2019/utils/createFileDataLoader.js +3 -0
- package/dist/es2019/utils/imageResizeModeToFileImageMode.js +1 -0
- package/dist/es2019/utils/mobileUpload/error.js +30 -0
- package/dist/es2019/utils/mobileUpload/helpers.js +55 -0
- package/dist/es2019/utils/mobileUpload/index.js +4 -0
- package/dist/es2019/utils/mobileUpload/servicesCache.js +4 -0
- package/dist/es2019/utils/mobileUpload/stateMachine/index.js +52 -0
- package/dist/es2019/utils/mobileUpload/stateMachine/states/error.js +3 -0
- package/dist/es2019/utils/mobileUpload/stateMachine/states/processed.js +3 -0
- package/dist/es2019/utils/mobileUpload/stateMachine/states/processing.js +60 -0
- package/dist/es2019/utils/mobileUpload/stateMachine/states/processingFailed.js +3 -0
- package/dist/es2019/utils/mobileUpload/stateMachine/states/uploading.js +44 -0
- package/dist/es2019/utils/mobileUpload/stateMachine/types.js +1 -0
- package/dist/es2019/utils/polling/index.js +5 -5
- package/dist/es2019/utils/setTimeoutPromise.js +6 -0
- package/dist/es2019/version.json +1 -1
- package/dist/esm/client/file-fetcher/index.js +5 -10
- package/dist/esm/client/media-client.js +42 -0
- package/dist/esm/client/media-store/resolveAuth.js +34 -14
- package/dist/esm/client/mobile-upload.js +83 -0
- package/dist/esm/index.js +1 -0
- package/dist/esm/models/mobile-upload.js +1 -0
- package/dist/esm/utils/createFileDataLoader.js +3 -0
- package/dist/esm/utils/imageResizeModeToFileImageMode.js +3 -0
- package/dist/esm/utils/mobileUpload/error.js +51 -0
- package/dist/esm/utils/mobileUpload/helpers.js +86 -0
- package/dist/esm/utils/mobileUpload/index.js +4 -0
- package/dist/esm/utils/mobileUpload/servicesCache.js +4 -0
- package/dist/esm/utils/mobileUpload/stateMachine/index.js +78 -0
- package/dist/esm/utils/mobileUpload/stateMachine/states/error.js +3 -0
- package/dist/esm/utils/mobileUpload/stateMachine/states/processed.js +3 -0
- package/dist/esm/utils/mobileUpload/stateMachine/states/processing.js +68 -0
- package/dist/esm/utils/mobileUpload/stateMachine/states/processingFailed.js +3 -0
- package/dist/esm/utils/mobileUpload/stateMachine/states/uploading.js +58 -0
- package/dist/esm/utils/mobileUpload/stateMachine/types.js +1 -0
- package/dist/esm/utils/polling/index.js +5 -5
- package/dist/esm/utils/setTimeoutPromise.js +10 -0
- package/dist/esm/version.json +1 -1
- package/dist/types/client/file-fetcher/index.d.ts +1 -0
- package/dist/types/client/media-client.d.ts +3 -0
- package/dist/types/client/media-store/error.d.ts +1 -1
- package/dist/types/client/media-store/resolveAuth.d.ts +2 -2
- package/dist/types/client/mobile-upload.d.ts +11 -0
- package/dist/types/index.d.ts +3 -1
- package/dist/types/models/errors/types.d.ts +1 -1
- package/dist/types/models/mobile-upload.d.ts +28 -0
- package/dist/types/utils/createFileDataLoader.d.ts +4 -3
- package/dist/types/utils/imageResizeModeToFileImageMode.d.ts +3 -0
- package/dist/types/utils/mobileUpload/error.d.ts +29 -0
- package/dist/types/utils/mobileUpload/helpers.d.ts +8 -0
- package/dist/types/utils/mobileUpload/index.d.ts +5 -0
- package/dist/types/utils/mobileUpload/servicesCache.d.ts +4 -0
- package/dist/types/utils/mobileUpload/stateMachine/index.d.ts +7 -0
- package/dist/types/utils/mobileUpload/stateMachine/states/error.d.ts +3 -0
- package/dist/types/utils/mobileUpload/stateMachine/states/processed.d.ts +3 -0
- package/dist/types/utils/mobileUpload/stateMachine/states/processing.d.ts +3 -0
- package/dist/types/utils/mobileUpload/stateMachine/states/processingFailed.d.ts +3 -0
- package/dist/types/utils/mobileUpload/stateMachine/states/uploading.d.ts +3 -0
- package/dist/types/utils/mobileUpload/stateMachine/types.d.ts +69 -0
- package/dist/types/utils/polling/index.d.ts +8 -3
- package/dist/types/utils/setTimeoutPromise.d.ts +2 -0
- package/package.json +9 -7
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { map } from 'rxjs/operators/map';
|
|
2
|
+
import { createMachine, interpret } from 'xstate';
|
|
3
|
+
import { isProcessingFileState } from '../../../models/file-state';
|
|
4
|
+
import { shouldFetchRemoteFileStates } from '../../shouldFetchRemoteFileStates';
|
|
5
|
+
import { createMobileDownloadFileStream } from '../helpers';
|
|
6
|
+
import { machineUploadingState } from './states/uploading';
|
|
7
|
+
import { machineProcessingState } from './states/processing';
|
|
8
|
+
import { machineProcessedState } from './states/processed';
|
|
9
|
+
import { machineProcessingFailedState } from './states/processingFailed';
|
|
10
|
+
import { machineErrorState } from './states/error';
|
|
11
|
+
export const createMobileUploadStateMachine = (dataloader, initialState, collectionName) => createMachine({
|
|
12
|
+
// Initial state
|
|
13
|
+
initial: initialState.status,
|
|
14
|
+
// Context
|
|
15
|
+
context: {
|
|
16
|
+
currentFileState: initialState
|
|
17
|
+
},
|
|
18
|
+
// State definitions
|
|
19
|
+
states: {
|
|
20
|
+
uploading: machineUploadingState,
|
|
21
|
+
processing: machineProcessingState,
|
|
22
|
+
processed: machineProcessedState,
|
|
23
|
+
processingFailed: machineProcessingFailedState,
|
|
24
|
+
error: machineErrorState
|
|
25
|
+
}
|
|
26
|
+
}, {
|
|
27
|
+
services: {
|
|
28
|
+
shouldFetchRemoteFileStates: async ctx => {
|
|
29
|
+
const {
|
|
30
|
+
currentFileState
|
|
31
|
+
} = ctx;
|
|
32
|
+
|
|
33
|
+
if (isProcessingFileState(currentFileState)) {
|
|
34
|
+
const {
|
|
35
|
+
mediaType,
|
|
36
|
+
mimeType,
|
|
37
|
+
preview
|
|
38
|
+
} = currentFileState;
|
|
39
|
+
return shouldFetchRemoteFileStates(mediaType, mimeType, preview);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
return false;
|
|
43
|
+
},
|
|
44
|
+
fetchRemoteFileStates: ctx => createMobileDownloadFileStream(dataloader, ctx.currentFileState.id, collectionName, ctx.currentFileState.occurrenceKey).pipe(map(fileState => ({
|
|
45
|
+
type: 'REMOTE_FILESTATE_RESULT',
|
|
46
|
+
fileState
|
|
47
|
+
})))
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
export function createMobileUploadService(machine) {
|
|
51
|
+
return interpret(machine);
|
|
52
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { assign, send } from 'xstate';
|
|
2
|
+
export const machineProcessingState = {
|
|
3
|
+
// Events
|
|
4
|
+
on: {
|
|
5
|
+
REMOTE_FILESTATE_PROCESSED: 'processed',
|
|
6
|
+
REMOTE_FILESTATE_PROCESSING_FAILED: 'processingFailed',
|
|
7
|
+
REMOTE_FILESTATE_ERROR: 'error'
|
|
8
|
+
},
|
|
9
|
+
// Initial sub state
|
|
10
|
+
initial: 'loading',
|
|
11
|
+
// Sub states definitions
|
|
12
|
+
states: {
|
|
13
|
+
loading: {
|
|
14
|
+
invoke: {
|
|
15
|
+
src: 'shouldFetchRemoteFileStates',
|
|
16
|
+
onDone: {
|
|
17
|
+
actions: send((_, event) => ({
|
|
18
|
+
// shouldFetchRemoteFileStates resolves a boolean
|
|
19
|
+
type: event.data ? 'REMOTE_FILESTATE_FETCH' : 'REMOTE_FILESTATE_BYPASS'
|
|
20
|
+
}))
|
|
21
|
+
},
|
|
22
|
+
onError: 'idle'
|
|
23
|
+
},
|
|
24
|
+
on: {
|
|
25
|
+
REMOTE_FILESTATE_FETCH: 'fetchingRemoteFileStates',
|
|
26
|
+
REMOTE_FILESTATE_BYPASS: 'idle'
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
fetchingRemoteFileStates: {
|
|
30
|
+
invoke: {
|
|
31
|
+
src: 'fetchRemoteFileStates',
|
|
32
|
+
onDone: {
|
|
33
|
+
actions: send(ctx => ({
|
|
34
|
+
type: ctx.currentFileState.status === 'processed' ? 'REMOTE_FILESTATE_PROCESSED' : 'REMOTE_FILESTATE_PROCESSING_FAILED'
|
|
35
|
+
}))
|
|
36
|
+
},
|
|
37
|
+
onError: {
|
|
38
|
+
actions: [assign({
|
|
39
|
+
currentFileState: (ctx, event) => ({
|
|
40
|
+
status: 'error',
|
|
41
|
+
id: ctx.currentFileState.id,
|
|
42
|
+
occurrenceKey: ctx.currentFileState.occurrenceKey,
|
|
43
|
+
message: event.data.message
|
|
44
|
+
})
|
|
45
|
+
}), send({
|
|
46
|
+
type: 'REMOTE_FILESTATE_ERROR'
|
|
47
|
+
})]
|
|
48
|
+
}
|
|
49
|
+
},
|
|
50
|
+
on: {
|
|
51
|
+
REMOTE_FILESTATE_RESULT: {
|
|
52
|
+
actions: assign({
|
|
53
|
+
currentFileState: (_, event) => event.fileState
|
|
54
|
+
})
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
},
|
|
58
|
+
idle: {}
|
|
59
|
+
}
|
|
60
|
+
};
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { assign } from 'xstate';
|
|
2
|
+
import { isUploadingFileState } from '../../../../models/file-state';
|
|
3
|
+
export const machineUploadingState = {
|
|
4
|
+
// Events
|
|
5
|
+
on: {
|
|
6
|
+
UPLOAD_PROGRESS: [{
|
|
7
|
+
target: 'uploading',
|
|
8
|
+
cond: (ctx, event) => isUploadingFileState(ctx.currentFileState) && event.progress > ctx.currentFileState.progress,
|
|
9
|
+
actions: assign({
|
|
10
|
+
currentFileState: (ctx, event) => ({ ...ctx.currentFileState,
|
|
11
|
+
progress: event.progress
|
|
12
|
+
})
|
|
13
|
+
})
|
|
14
|
+
}, {
|
|
15
|
+
target: 'error'
|
|
16
|
+
}],
|
|
17
|
+
UPLOAD_END: {
|
|
18
|
+
target: 'processing',
|
|
19
|
+
actions: assign({
|
|
20
|
+
currentFileState: ctx => isUploadingFileState(ctx.currentFileState) && {
|
|
21
|
+
status: 'processing',
|
|
22
|
+
id: ctx.currentFileState.id,
|
|
23
|
+
occurrenceKey: ctx.currentFileState.occurrenceKey,
|
|
24
|
+
name: ctx.currentFileState.name,
|
|
25
|
+
size: ctx.currentFileState.size,
|
|
26
|
+
mediaType: ctx.currentFileState.mediaType,
|
|
27
|
+
mimeType: ctx.currentFileState.mimeType,
|
|
28
|
+
preview: ctx.currentFileState.preview,
|
|
29
|
+
createdAt: ctx.currentFileState.createdAt
|
|
30
|
+
} || ctx.currentFileState
|
|
31
|
+
})
|
|
32
|
+
},
|
|
33
|
+
UPLOAD_ERROR: {
|
|
34
|
+
target: 'error',
|
|
35
|
+
actions: assign({
|
|
36
|
+
currentFileState: (ctx, event) => ({
|
|
37
|
+
status: 'error',
|
|
38
|
+
id: ctx.currentFileState.id,
|
|
39
|
+
message: event.message
|
|
40
|
+
})
|
|
41
|
+
})
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
2
|
-
import { getMediaFeatureFlag } from '@atlaskit/media-common/mediaFeatureFlags';
|
|
3
2
|
import { PollingError } from './errors';
|
|
3
|
+
// default polling options without using feature flags
|
|
4
4
|
export const defaultPollingOptions = {
|
|
5
|
-
poll_intervalMs:
|
|
6
|
-
poll_maxAttempts:
|
|
7
|
-
poll_backoffFactor:
|
|
8
|
-
poll_maxIntervalMs:
|
|
5
|
+
poll_intervalMs: 3000,
|
|
6
|
+
poll_maxAttempts: 30,
|
|
7
|
+
poll_backoffFactor: 1.25,
|
|
8
|
+
poll_maxIntervalMs: 200000
|
|
9
9
|
};
|
|
10
10
|
/**
|
|
11
11
|
* This class encapsulates polling functionality with the following features:
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export const resolveTimeout = (timeout, resolveWith) => new Promise((resolve, _reject) => {
|
|
2
|
+
setTimeout(resolve, timeout, resolveWith);
|
|
3
|
+
});
|
|
4
|
+
export const rejectTimeout = (timeout, rejectWith) => new Promise((_resolve, reject) => {
|
|
5
|
+
setTimeout(reject, timeout, rejectWith);
|
|
6
|
+
});
|
package/dist/es2019/version.json
CHANGED
|
@@ -12,7 +12,10 @@ import { Subscription } from 'rxjs/Subscription';
|
|
|
12
12
|
import { of } from 'rxjs/observable/of';
|
|
13
13
|
import { map } from 'rxjs/operators/map';
|
|
14
14
|
import { concatMap } from 'rxjs/operators/concatMap';
|
|
15
|
-
import uuid from 'uuid/v4';
|
|
15
|
+
import uuid from 'uuid/v4'; // import setimmediate to temporary fix dataloader 2.0.0 bug
|
|
16
|
+
// @see https://github.com/graphql/dataloader/issues/249
|
|
17
|
+
|
|
18
|
+
import 'setimmediate';
|
|
16
19
|
import { authToOwner } from '@atlaskit/media-core';
|
|
17
20
|
import { downloadUrl } from '@atlaskit/media-common/downloadUrl';
|
|
18
21
|
import { MediaStore } from '../media-store';
|
|
@@ -34,7 +37,6 @@ import { isMimeTypeSupportedByBrowser, getMediaTypeFromMimeType } from '@atlaski
|
|
|
34
37
|
import { shouldFetchRemoteFileStates, shouldFetchRemoteFileStatesObservable } from '../../utils/shouldFetchRemoteFileStates';
|
|
35
38
|
import { PollingFunction } from '../../utils/polling';
|
|
36
39
|
import { isEmptyFile } from '../../utils/detectEmptyFile';
|
|
37
|
-
import { getMediaFeatureFlag } from '@atlaskit/media-common/mediaFeatureFlags';
|
|
38
40
|
export { isFileFetcherError, FileFetcherError } from './error';
|
|
39
41
|
export var FileFetcherImpl = /*#__PURE__*/function () {
|
|
40
42
|
function FileFetcherImpl(mediaStore) {
|
|
@@ -44,14 +46,7 @@ export var FileFetcherImpl = /*#__PURE__*/function () {
|
|
|
44
46
|
|
|
45
47
|
_defineProperty(this, "createDownloadFileStream", function (id, collectionName, occurrenceKey) {
|
|
46
48
|
var subject = createFileStateSubject();
|
|
47
|
-
var
|
|
48
|
-
var pollingOptions = {
|
|
49
|
-
poll_intervalMs: getMediaFeatureFlag('poll_intervalMs', featureFlags),
|
|
50
|
-
poll_maxAttempts: getMediaFeatureFlag('poll_maxAttempts', featureFlags),
|
|
51
|
-
poll_backoffFactor: getMediaFeatureFlag('poll_backoffFactor', featureFlags),
|
|
52
|
-
poll_maxIntervalMs: getMediaFeatureFlag('poll_maxIntervalMs', featureFlags)
|
|
53
|
-
};
|
|
54
|
-
var poll = new PollingFunction(pollingOptions); // ensure subject errors if polling exceeds max iterations or uncaught exception in executor
|
|
49
|
+
var poll = new PollingFunction(); // ensure subject errors if polling exceeds max iterations or uncaught exception in executor
|
|
55
50
|
|
|
56
51
|
poll.onError = function (error) {
|
|
57
52
|
return subject.error(error);
|
|
@@ -8,6 +8,7 @@ import { CollectionFetcher } from './collection-fetcher';
|
|
|
8
8
|
import { FileFetcherImpl } from './file-fetcher';
|
|
9
9
|
import { StargateClient } from './stargate-client';
|
|
10
10
|
export var MediaClient = /*#__PURE__*/function () {
|
|
11
|
+
// mobile upload is lazily loaded
|
|
11
12
|
// Deprecated value introduced for backward compatibility with Context
|
|
12
13
|
function MediaClient(mediaClientConfig, featureFlags) {
|
|
13
14
|
_classCallCheck(this, MediaClient);
|
|
@@ -67,6 +68,47 @@ export var MediaClient = /*#__PURE__*/function () {
|
|
|
67
68
|
|
|
68
69
|
return getImageMetadata;
|
|
69
70
|
}()
|
|
71
|
+
}, {
|
|
72
|
+
key: "mobileUploadPromise",
|
|
73
|
+
value: function () {
|
|
74
|
+
var _mobileUploadPromise = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2() {
|
|
75
|
+
var module;
|
|
76
|
+
return _regeneratorRuntime.wrap(function _callee2$(_context2) {
|
|
77
|
+
while (1) {
|
|
78
|
+
switch (_context2.prev = _context2.next) {
|
|
79
|
+
case 0:
|
|
80
|
+
if (!this.mobileUpload) {
|
|
81
|
+
_context2.next = 2;
|
|
82
|
+
break;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
return _context2.abrupt("return", this.mobileUpload);
|
|
86
|
+
|
|
87
|
+
case 2:
|
|
88
|
+
_context2.next = 4;
|
|
89
|
+
return import(
|
|
90
|
+
/* webpackChunkName: "@atlaskit-internal_media-client-mobile-upload" */
|
|
91
|
+
'./mobile-upload');
|
|
92
|
+
|
|
93
|
+
case 4:
|
|
94
|
+
module = _context2.sent;
|
|
95
|
+
this.mobileUpload = new module.MobileUploadImpl(this.mediaStore);
|
|
96
|
+
return _context2.abrupt("return", this.mobileUpload);
|
|
97
|
+
|
|
98
|
+
case 7:
|
|
99
|
+
case "end":
|
|
100
|
+
return _context2.stop();
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}, _callee2, this);
|
|
104
|
+
}));
|
|
105
|
+
|
|
106
|
+
function mobileUploadPromise() {
|
|
107
|
+
return _mobileUploadPromise.apply(this, arguments);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
return mobileUploadPromise;
|
|
111
|
+
}()
|
|
70
112
|
}, {
|
|
71
113
|
key: "on",
|
|
72
114
|
value: function on(event, listener) {
|
|
@@ -1,38 +1,58 @@
|
|
|
1
1
|
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
2
2
|
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
|
|
3
3
|
import { MediaStoreError } from './error';
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
import { rejectTimeout } from '../../utils/setTimeoutPromise';
|
|
5
|
+
export var DEFAULT_AUTH_PROVIDER_TIMEOUT = 10000;
|
|
6
6
|
export var resolveAuth = /*#__PURE__*/function () {
|
|
7
7
|
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(authProvider, authContext) {
|
|
8
|
-
var
|
|
8
|
+
var authProviderTimeout,
|
|
9
|
+
auth,
|
|
10
|
+
_args = arguments;
|
|
9
11
|
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
10
12
|
while (1) {
|
|
11
13
|
switch (_context.prev = _context.next) {
|
|
12
14
|
case 0:
|
|
13
|
-
|
|
14
|
-
_context.
|
|
15
|
-
|
|
15
|
+
authProviderTimeout = _args.length > 2 && _args[2] !== undefined ? _args[2] : DEFAULT_AUTH_PROVIDER_TIMEOUT;
|
|
16
|
+
_context.prev = 1;
|
|
17
|
+
_context.next = 4;
|
|
18
|
+
return Promise.race([authProvider(authContext), rejectTimeout(authProviderTimeout, new MediaStoreError('authProviderTimedOut'))]);
|
|
16
19
|
|
|
17
|
-
case
|
|
20
|
+
case 4:
|
|
18
21
|
auth = _context.sent;
|
|
19
|
-
_context.next =
|
|
22
|
+
_context.next = 12;
|
|
20
23
|
break;
|
|
21
24
|
|
|
22
|
-
case
|
|
23
|
-
_context.prev =
|
|
24
|
-
_context.t0 = _context["catch"](
|
|
25
|
+
case 7:
|
|
26
|
+
_context.prev = 7;
|
|
27
|
+
_context.t0 = _context["catch"](1);
|
|
28
|
+
|
|
29
|
+
if (!(_context.t0 instanceof MediaStoreError)) {
|
|
30
|
+
_context.next = 11;
|
|
31
|
+
break;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
throw _context.t0;
|
|
35
|
+
|
|
36
|
+
case 11:
|
|
25
37
|
throw new MediaStoreError('failedAuthProvider', _context.t0);
|
|
26
38
|
|
|
27
|
-
case
|
|
39
|
+
case 12:
|
|
40
|
+
if (auth) {
|
|
41
|
+
_context.next = 14;
|
|
42
|
+
break;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
throw new MediaStoreError('emptyAuth');
|
|
46
|
+
|
|
47
|
+
case 14:
|
|
28
48
|
return _context.abrupt("return", auth);
|
|
29
49
|
|
|
30
|
-
case
|
|
50
|
+
case 15:
|
|
31
51
|
case "end":
|
|
32
52
|
return _context.stop();
|
|
33
53
|
}
|
|
34
54
|
}
|
|
35
|
-
}, _callee, null, [[
|
|
55
|
+
}, _callee, null, [[1, 7]]);
|
|
36
56
|
}));
|
|
37
57
|
|
|
38
58
|
return function resolveAuth(_x, _x2) {
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
|
|
2
|
+
import _createClass from "@babel/runtime/helpers/createClass";
|
|
3
|
+
import { getMediaTypeFromMimeType } from '@atlaskit/media-common';
|
|
4
|
+
import { getFileStreamsCache } from '../file-streams-cache';
|
|
5
|
+
import { createFileDataloader } from '../utils/createFileDataLoader';
|
|
6
|
+
import { createServicesCache, createMobileUploadStateMachine, createMobileUploadService, createMobileFileStateSubject } from '../utils/mobileUpload';
|
|
7
|
+
export var MobileUploadImpl = /*#__PURE__*/function () {
|
|
8
|
+
function MobileUploadImpl(mediaStore) {
|
|
9
|
+
_classCallCheck(this, MobileUploadImpl);
|
|
10
|
+
|
|
11
|
+
this.dataloader = createFileDataloader(mediaStore);
|
|
12
|
+
this.servicesCache = createServicesCache();
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
_createClass(MobileUploadImpl, [{
|
|
16
|
+
key: "notifyUploadStart",
|
|
17
|
+
value: function notifyUploadStart(event) {
|
|
18
|
+
var fileId = event.fileId,
|
|
19
|
+
collectionName = event.collectionName,
|
|
20
|
+
occurrenceKey = event.occurrenceKey,
|
|
21
|
+
fileName = event.fileName,
|
|
22
|
+
fileSize = event.fileSize,
|
|
23
|
+
fileMimetype = event.fileMimetype,
|
|
24
|
+
preview = event.preview,
|
|
25
|
+
createdAt = event.createdAt;
|
|
26
|
+
var mediaType = getMediaTypeFromMimeType(fileMimetype);
|
|
27
|
+
var initialState = {
|
|
28
|
+
status: 'uploading',
|
|
29
|
+
id: fileId,
|
|
30
|
+
occurrenceKey: occurrenceKey,
|
|
31
|
+
name: fileName,
|
|
32
|
+
size: fileSize,
|
|
33
|
+
progress: 0,
|
|
34
|
+
mediaType: mediaType,
|
|
35
|
+
mimeType: fileMimetype,
|
|
36
|
+
preview: preview,
|
|
37
|
+
createdAt: createdAt
|
|
38
|
+
};
|
|
39
|
+
var service = createMobileUploadService(createMobileUploadStateMachine(this.dataloader, initialState, collectionName));
|
|
40
|
+
var subject = createMobileFileStateSubject(service);
|
|
41
|
+
this.servicesCache.put(fileId, service);
|
|
42
|
+
getFileStreamsCache().set(fileId, subject);
|
|
43
|
+
}
|
|
44
|
+
}, {
|
|
45
|
+
key: "notifyUploadProgress",
|
|
46
|
+
value: function notifyUploadProgress(event) {
|
|
47
|
+
var fileId = event.fileId,
|
|
48
|
+
progress = event.progress;
|
|
49
|
+
var service = this.servicesCache.get(fileId);
|
|
50
|
+
|
|
51
|
+
if (service) {
|
|
52
|
+
service.send('UPLOAD_PROGRESS', {
|
|
53
|
+
progress: progress
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}, {
|
|
58
|
+
key: "notifyUploadEnd",
|
|
59
|
+
value: function notifyUploadEnd(event) {
|
|
60
|
+
var fileId = event.fileId;
|
|
61
|
+
var service = this.servicesCache.get(fileId);
|
|
62
|
+
|
|
63
|
+
if (service) {
|
|
64
|
+
service.send('UPLOAD_END');
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}, {
|
|
68
|
+
key: "notifyUploadError",
|
|
69
|
+
value: function notifyUploadError(event) {
|
|
70
|
+
var fileId = event.fileId,
|
|
71
|
+
message = event.message;
|
|
72
|
+
var service = this.servicesCache.get(fileId);
|
|
73
|
+
|
|
74
|
+
if (service) {
|
|
75
|
+
service.send('UPLOAD_ERROR', {
|
|
76
|
+
message: message
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}]);
|
|
81
|
+
|
|
82
|
+
return MobileUploadImpl;
|
|
83
|
+
}();
|
package/dist/esm/index.js
CHANGED
|
@@ -10,6 +10,7 @@ export { request, RequestError, isRequestError, isRateLimitedError } from './uti
|
|
|
10
10
|
export { isAbortedRequestError, mapResponseToJson, mapResponseToBlob, mapResponseToVoid, createUrl } from './utils/request/helpers';
|
|
11
11
|
export { PollingFunction } from './utils/polling';
|
|
12
12
|
export { isPollingError, PollingError } from './utils/polling/errors';
|
|
13
|
+
export { imageResizeModeToFileImageMode } from './utils/imageResizeModeToFileImageMode';
|
|
13
14
|
export { FileFetcherImpl, FileFetcherError, isFileFetcherError } from './client/file-fetcher';
|
|
14
15
|
export { CollectionFetcher } from './client/collection-fetcher';
|
|
15
16
|
export { MediaClient } from './client/media-client';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
2
2
|
import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
|
|
3
3
|
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
|
|
4
|
+
// import setimmediate to temporary fix dataloader 2.0.0 bug
|
|
5
|
+
// @see https://github.com/graphql/dataloader/issues/249
|
|
6
|
+
import 'setimmediate';
|
|
4
7
|
import Dataloader from 'dataloader';
|
|
5
8
|
export var MAX_BATCH_SIZE = 100;
|
|
6
9
|
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
|
|
2
|
+
import _createClass from "@babel/runtime/helpers/createClass";
|
|
3
|
+
import _inherits from "@babel/runtime/helpers/inherits";
|
|
4
|
+
import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
|
|
5
|
+
import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
|
|
6
|
+
|
|
7
|
+
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
|
8
|
+
|
|
9
|
+
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
10
|
+
|
|
11
|
+
import { BaseMediaClientError } from '../../models/errors';
|
|
12
|
+
export var MobileUploadError = /*#__PURE__*/function (_BaseMediaClientError) {
|
|
13
|
+
_inherits(MobileUploadError, _BaseMediaClientError);
|
|
14
|
+
|
|
15
|
+
var _super = _createSuper(MobileUploadError);
|
|
16
|
+
|
|
17
|
+
function MobileUploadError(reason, id, metadata) {
|
|
18
|
+
var _this;
|
|
19
|
+
|
|
20
|
+
_classCallCheck(this, MobileUploadError);
|
|
21
|
+
|
|
22
|
+
_this = _super.call(this, reason);
|
|
23
|
+
_this.reason = reason;
|
|
24
|
+
_this.id = id;
|
|
25
|
+
_this.metadata = metadata;
|
|
26
|
+
return _this;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
_createClass(MobileUploadError, [{
|
|
30
|
+
key: "attributes",
|
|
31
|
+
get: function get() {
|
|
32
|
+
var reason = this.reason,
|
|
33
|
+
id = this.id,
|
|
34
|
+
_this$metadata = this.metadata;
|
|
35
|
+
_this$metadata = _this$metadata === void 0 ? {} : _this$metadata;
|
|
36
|
+
var collectionName = _this$metadata.collectionName,
|
|
37
|
+
occurrenceKey = _this$metadata.occurrenceKey;
|
|
38
|
+
return {
|
|
39
|
+
reason: reason,
|
|
40
|
+
id: id,
|
|
41
|
+
collectionName: collectionName,
|
|
42
|
+
occurrenceKey: occurrenceKey
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
}]);
|
|
46
|
+
|
|
47
|
+
return MobileUploadError;
|
|
48
|
+
}(BaseMediaClientError);
|
|
49
|
+
export function isMobileUploadError(err) {
|
|
50
|
+
return err instanceof MobileUploadError;
|
|
51
|
+
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
2
|
+
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
|
|
3
|
+
import { ReplaySubject } from 'rxjs/ReplaySubject';
|
|
4
|
+
import { from } from 'rxjs/observable/from';
|
|
5
|
+
import { map } from 'rxjs/operators/map';
|
|
6
|
+
import { mapMediaItemToFileState } from '../../models/file-state';
|
|
7
|
+
import { createFileStateSubject } from '../createFileStateSubject';
|
|
8
|
+
import { isEmptyFile } from '../detectEmptyFile';
|
|
9
|
+
import { PollingFunction } from '../polling';
|
|
10
|
+
import { MobileUploadError } from './error';
|
|
11
|
+
export var createMobileFileStateSubject = function createMobileFileStateSubject(service) {
|
|
12
|
+
var subject = new ReplaySubject(1);
|
|
13
|
+
from(service.start()).pipe(map(function (state) {
|
|
14
|
+
return state.context.currentFileState;
|
|
15
|
+
})).subscribe(subject);
|
|
16
|
+
return subject;
|
|
17
|
+
};
|
|
18
|
+
export var createMobileDownloadFileStream = function createMobileDownloadFileStream(dataloader, id, collectionName, occurrenceKey) {
|
|
19
|
+
var subject = createFileStateSubject();
|
|
20
|
+
var poll = new PollingFunction(); // ensure subject errors if polling exceeds max iterations or uncaught exception in executor
|
|
21
|
+
|
|
22
|
+
poll.onError = function (error) {
|
|
23
|
+
return subject.error(error);
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
poll.execute( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
|
|
27
|
+
var response, fileState;
|
|
28
|
+
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
29
|
+
while (1) {
|
|
30
|
+
switch (_context.prev = _context.next) {
|
|
31
|
+
case 0:
|
|
32
|
+
_context.next = 2;
|
|
33
|
+
return dataloader.load({
|
|
34
|
+
id: id,
|
|
35
|
+
collectionName: collectionName
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
case 2:
|
|
39
|
+
response = _context.sent;
|
|
40
|
+
|
|
41
|
+
if (response) {
|
|
42
|
+
_context.next = 5;
|
|
43
|
+
break;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
throw new MobileUploadError('emptyItems', id, {
|
|
47
|
+
collectionName: collectionName,
|
|
48
|
+
occurrenceKey: occurrenceKey
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
case 5:
|
|
52
|
+
if (!isEmptyFile(response)) {
|
|
53
|
+
_context.next = 7;
|
|
54
|
+
break;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
throw new MobileUploadError('zeroVersionFile', id, {
|
|
58
|
+
collectionName: collectionName,
|
|
59
|
+
occurrenceKey: occurrenceKey
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
case 7:
|
|
63
|
+
fileState = mapMediaItemToFileState(id, response);
|
|
64
|
+
subject.next(fileState);
|
|
65
|
+
_context.t0 = fileState.status;
|
|
66
|
+
_context.next = _context.t0 === 'processing' ? 12 : _context.t0 === 'processed' ? 14 : 16;
|
|
67
|
+
break;
|
|
68
|
+
|
|
69
|
+
case 12:
|
|
70
|
+
// the only case for continuing polling, otherwise this function is run once only
|
|
71
|
+
poll.next();
|
|
72
|
+
return _context.abrupt("break", 16);
|
|
73
|
+
|
|
74
|
+
case 14:
|
|
75
|
+
subject.complete();
|
|
76
|
+
return _context.abrupt("break", 16);
|
|
77
|
+
|
|
78
|
+
case 16:
|
|
79
|
+
case "end":
|
|
80
|
+
return _context.stop();
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}, _callee);
|
|
84
|
+
})));
|
|
85
|
+
return subject;
|
|
86
|
+
};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { isMobileUploadError, MobileUploadError } from './error';
|
|
2
|
+
export { createServicesCache } from './servicesCache';
|
|
3
|
+
export { createMobileUploadService, createMobileUploadStateMachine } from './stateMachine';
|
|
4
|
+
export { createMobileFileStateSubject } from './helpers';
|