@atlaskit/media-test-helpers 30.1.1 → 30.1.2
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/I18nWrapper.js +8 -24
- package/dist/cjs/MockGlobalImage.js +0 -16
- package/dist/cjs/authProvider.js +0 -18
- package/dist/cjs/await-error.js +0 -10
- package/dist/cjs/clipboardEventMocks.js +6 -39
- package/dist/cjs/createMouseEvent.js +4 -8
- package/dist/cjs/createTouchEvent.js +0 -2
- package/dist/cjs/docs-content-tabs.js +1 -14
- package/dist/cjs/example-mediaFeatureFlags.js +0 -7
- package/dist/cjs/exampleMediaItems.js +6 -7
- package/dist/cjs/fakeI18n.js +2 -4
- package/dist/cjs/fakeMediaClient.js +5 -18
- package/dist/cjs/featureFlagsWrapper/dropdown.js +12 -46
- package/dist/cjs/featureFlagsWrapper/helpers.js +0 -14
- package/dist/cjs/featureFlagsWrapper/index.js +5 -19
- package/dist/cjs/fileReader.js +0 -28
- package/dist/cjs/fileStateFactory/createFileState.js +9 -27
- package/dist/cjs/fileStateFactory/factory.js +7 -44
- package/dist/cjs/fileStateFactory/helpers.js +10 -23
- package/dist/cjs/fileStateFactory/index.js +0 -3
- package/dist/cjs/flushPromises.js +0 -2
- package/dist/cjs/getAuthFromContextProvider.js +0 -9
- package/dist/cjs/getJest.js +3 -5
- package/dist/cjs/globalEventEmitterListeners.js +0 -8
- package/dist/cjs/images.js +0 -6
- package/dist/cjs/index.js +0 -42
- package/dist/cjs/jestHelpers.js +0 -20
- package/dist/cjs/keyboardEventWithKeyCode.js +0 -18
- package/dist/cjs/mediaClientErrors.js +0 -11
- package/dist/cjs/mediaClientProvider.js +1 -17
- package/dist/cjs/mediaPickerAuthProvider.js +5 -21
- package/dist/cjs/mockCanvas.js +0 -4
- package/dist/cjs/mockData/handlers/copyWithToken.js +0 -14
- package/dist/cjs/mockData/handlers/getFile.js +0 -8
- package/dist/cjs/mockData/handlers/getFileImage.js +0 -9
- package/dist/cjs/mockData/handlers/index.js +0 -5
- package/dist/cjs/mockData/handlers/tenantAuth.js +0 -6
- package/dist/cjs/mockData/handlers/userCollectionFetch.js +0 -11
- package/dist/cjs/mockData/index.js +0 -9
- package/dist/cjs/mockData/matchers.js +0 -11
- package/dist/cjs/mockData/utils.js +10 -10
- package/dist/cjs/mockLoadImage.js +2 -14
- package/dist/cjs/mocks/database/chunk.js +0 -3
- package/dist/cjs/mocks/database/collection-item.js +14 -23
- package/dist/cjs/mocks/database/collection.js +0 -2
- package/dist/cjs/mocks/database/index.js +5 -23
- package/dist/cjs/mocks/database/upload.js +0 -6
- package/dist/cjs/mocks/fileAndDirectoriesUtils.js +12 -20
- package/dist/cjs/mocks/media-mock.js +14 -45
- package/dist/cjs/mocks/routers/api-router.js +78 -162
- package/dist/cjs/mocks/routers/index.js +0 -2
- package/dist/cjs/mocks/routers/media-playground-router.js +0 -3
- package/dist/cjs/mocks/websockets/index.js +0 -1
- package/dist/cjs/mocks/websockets/messages.js +0 -9
- package/dist/cjs/mocks/websockets/remote-upload-server.js +19 -45
- package/dist/cjs/mountWithIntlContext.js +9 -27
- package/dist/cjs/nextTick.js +0 -4
- package/dist/cjs/renderWithIntl.js +0 -6
- package/dist/cjs/story-list.js +4 -22
- package/dist/cjs/story-styles.js +0 -6
- package/dist/cjs/styled.js +0 -6
- package/dist/cjs/timeoutPromise.js +0 -1
- package/dist/cjs/ufoLogger.js +0 -7
- package/dist/cjs/utils/index.js +2 -11
- package/dist/cjs/utils/logging.js +11 -12
- package/dist/cjs/utils/mockData.js +5 -19
- package/dist/cjs/version.json +1 -1
- package/dist/cjs/waitUntil.js +2 -10
- package/dist/es2019/I18nWrapper.js +2 -4
- package/dist/es2019/MockGlobalImage.js +0 -3
- package/dist/es2019/authProvider.js +2 -5
- package/dist/es2019/clipboardEventMocks.js +12 -26
- package/dist/es2019/createMouseEvent.js +0 -2
- package/dist/es2019/docs-content-tabs.js +1 -3
- package/dist/es2019/example-mediaFeatureFlags.js +3 -2
- package/dist/es2019/exampleMediaItems.js +8 -3
- package/dist/es2019/fakeI18n.js +2 -1
- package/dist/es2019/fakeMediaClient.js +0 -1
- package/dist/es2019/featureFlagsWrapper/dropdown.js +0 -10
- package/dist/es2019/featureFlagsWrapper/helpers.js +2 -1
- package/dist/es2019/featureFlagsWrapper/index.js +2 -7
- package/dist/es2019/fileReader.js +0 -17
- package/dist/es2019/fileStateFactory/createFileState.js +6 -14
- package/dist/es2019/fileStateFactory/factory.js +4 -15
- package/dist/es2019/fileStateFactory/helpers.js +2 -7
- package/dist/es2019/getJest.js +3 -6
- package/dist/es2019/globalEventEmitterListeners.js +0 -3
- package/dist/es2019/images.js +2 -1
- package/dist/es2019/keyboardEventWithKeyCode.js +0 -5
- package/dist/es2019/mediaClientErrors.js +2 -1
- package/dist/es2019/mediaClientProvider.js +1 -1
- package/dist/es2019/mediaPickerAuthProvider.js +2 -5
- package/dist/es2019/mockData/handlers/copyWithToken.js +0 -2
- package/dist/es2019/mockData/handlers/getFile.js +0 -3
- package/dist/es2019/mockData/handlers/getFileImage.js +0 -3
- package/dist/es2019/mockData/handlers/tenantAuth.js +0 -2
- package/dist/es2019/mockData/handlers/userCollectionFetch.js +0 -2
- package/dist/es2019/mockData/index.js +0 -2
- package/dist/es2019/mockData/utils.js +10 -6
- package/dist/es2019/mockLoadImage.js +4 -2
- package/dist/es2019/mocks/database/index.js +0 -2
- package/dist/es2019/mocks/fileAndDirectoriesUtils.js +20 -14
- package/dist/es2019/mocks/media-mock.js +4 -16
- package/dist/es2019/mocks/routers/api-router.js +13 -45
- package/dist/es2019/mocks/websockets/remote-upload-server.js +11 -14
- package/dist/es2019/mountWithIntlContext.js +4 -4
- package/dist/es2019/story-list.js +0 -1
- package/dist/es2019/ufoLogger.js +0 -1
- package/dist/es2019/utils/index.js +0 -2
- package/dist/es2019/utils/logging.js +4 -4
- package/dist/es2019/utils/mockData.js +5 -3
- package/dist/es2019/version.json +1 -1
- package/dist/es2019/waitUntil.js +0 -1
- package/dist/esm/I18nWrapper.js +8 -12
- package/dist/esm/MockGlobalImage.js +0 -10
- package/dist/esm/authProvider.js +0 -10
- package/dist/esm/await-error.js +0 -6
- package/dist/esm/clipboardEventMocks.js +15 -39
- package/dist/esm/createMouseEvent.js +4 -6
- package/dist/esm/docs-content-tabs.js +2 -5
- package/dist/esm/example-mediaFeatureFlags.js +0 -3
- package/dist/esm/exampleMediaItems.js +8 -3
- package/dist/esm/fakeI18n.js +2 -1
- package/dist/esm/fakeMediaClient.js +5 -8
- package/dist/esm/featureFlagsWrapper/dropdown.js +12 -30
- package/dist/esm/featureFlagsWrapper/helpers.js +0 -3
- package/dist/esm/featureFlagsWrapper/index.js +5 -12
- package/dist/esm/fileReader.js +0 -28
- package/dist/esm/fileStateFactory/createFileState.js +9 -22
- package/dist/esm/fileStateFactory/factory.js +7 -41
- package/dist/esm/fileStateFactory/helpers.js +10 -18
- package/dist/esm/getAuthFromContextProvider.js +0 -3
- package/dist/esm/getJest.js +3 -3
- package/dist/esm/globalEventEmitterListeners.js +0 -3
- package/dist/esm/images.js +2 -1
- package/dist/esm/jestHelpers.js +0 -2
- package/dist/esm/keyboardEventWithKeyCode.js +0 -10
- package/dist/esm/mediaClientErrors.js +0 -3
- package/dist/esm/mediaClientProvider.js +1 -1
- package/dist/esm/mediaPickerAuthProvider.js +5 -12
- package/dist/esm/mockData/handlers/copyWithToken.js +0 -4
- package/dist/esm/mockData/handlers/getFile.js +0 -3
- package/dist/esm/mockData/handlers/getFileImage.js +0 -3
- package/dist/esm/mockData/handlers/tenantAuth.js +0 -2
- package/dist/esm/mockData/handlers/userCollectionFetch.js +0 -5
- package/dist/esm/mockData/index.js +0 -2
- package/dist/esm/mockData/utils.js +10 -6
- package/dist/esm/mockLoadImage.js +2 -4
- package/dist/esm/mocks/database/collection-item.js +14 -15
- package/dist/esm/mocks/database/index.js +5 -7
- package/dist/esm/mocks/fileAndDirectoriesUtils.js +12 -13
- package/dist/esm/mocks/media-mock.js +14 -26
- package/dist/esm/mocks/routers/api-router.js +78 -144
- package/dist/esm/mocks/websockets/remote-upload-server.js +19 -24
- package/dist/esm/mountWithIntlContext.js +9 -17
- package/dist/esm/story-list.js +4 -12
- package/dist/esm/story-styles.js +0 -2
- package/dist/esm/styled.js +0 -2
- package/dist/esm/ufoLogger.js +0 -4
- package/dist/esm/utils/index.js +2 -5
- package/dist/esm/utils/logging.js +11 -11
- package/dist/esm/utils/mockData.js +5 -3
- package/dist/esm/version.json +1 -1
- package/dist/esm/waitUntil.js +2 -6
- package/package.json +4 -4
|
@@ -8,15 +8,10 @@ import _inherits from "@babel/runtime/helpers/inherits";
|
|
|
8
8
|
import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
|
|
9
9
|
import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
|
|
10
10
|
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
11
|
-
|
|
12
11
|
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; }
|
|
13
|
-
|
|
14
12
|
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; }
|
|
15
|
-
|
|
16
13
|
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); }; }
|
|
17
|
-
|
|
18
14
|
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; } }
|
|
19
|
-
|
|
20
15
|
// eslint-disable-line no-console
|
|
21
16
|
import { Router, KakapoResponse } from 'kakapo';
|
|
22
17
|
import uuid from 'uuid/v4';
|
|
@@ -28,18 +23,13 @@ import { createUpload } from '../database/upload';
|
|
|
28
23
|
import { logRequest } from '../../utils/logging';
|
|
29
24
|
import { getTextFileType, getFakeFileName, mockDataUri } from '../../utils/mockData';
|
|
30
25
|
import { mapDataUriToBlob } from '../../utils';
|
|
31
|
-
|
|
32
26
|
var RouterWithLogging = /*#__PURE__*/function (_Router) {
|
|
33
27
|
_inherits(RouterWithLogging, _Router);
|
|
34
|
-
|
|
35
28
|
var _super = _createSuper(RouterWithLogging);
|
|
36
|
-
|
|
37
29
|
function RouterWithLogging() {
|
|
38
30
|
_classCallCheck(this, RouterWithLogging);
|
|
39
|
-
|
|
40
31
|
return _super.apply(this, arguments);
|
|
41
32
|
}
|
|
42
|
-
|
|
43
33
|
_createClass(RouterWithLogging, [{
|
|
44
34
|
key: "register",
|
|
45
35
|
value: function register(method, path, originalHandler) {
|
|
@@ -47,15 +37,12 @@ var RouterWithLogging = /*#__PURE__*/function (_Router) {
|
|
|
47
37
|
var response;
|
|
48
38
|
var requestWithBodyObject;
|
|
49
39
|
var error;
|
|
50
|
-
|
|
51
40
|
try {
|
|
52
41
|
response = originalHandler(request, database);
|
|
53
42
|
var body = request.body;
|
|
54
|
-
|
|
55
43
|
try {
|
|
56
44
|
body = JSON.parse(body);
|
|
57
45
|
} catch (e) {}
|
|
58
|
-
|
|
59
46
|
requestWithBodyObject = {
|
|
60
47
|
request: _objectSpread(_objectSpread({}, request), {}, {
|
|
61
48
|
body: body
|
|
@@ -64,7 +51,6 @@ var RouterWithLogging = /*#__PURE__*/function (_Router) {
|
|
|
64
51
|
} catch (e) {
|
|
65
52
|
error = e;
|
|
66
53
|
}
|
|
67
|
-
|
|
68
54
|
logRequest({
|
|
69
55
|
path: path,
|
|
70
56
|
method: method,
|
|
@@ -73,21 +59,17 @@ var RouterWithLogging = /*#__PURE__*/function (_Router) {
|
|
|
73
59
|
error: error,
|
|
74
60
|
database: database
|
|
75
61
|
});
|
|
76
|
-
|
|
77
62
|
if (error) {
|
|
78
63
|
throw error;
|
|
79
64
|
} else {
|
|
80
65
|
return response;
|
|
81
66
|
}
|
|
82
67
|
};
|
|
83
|
-
|
|
84
68
|
return _get(_getPrototypeOf(RouterWithLogging.prototype), "register", this).call(this, method, path, handler);
|
|
85
69
|
}
|
|
86
70
|
}]);
|
|
87
|
-
|
|
88
71
|
return RouterWithLogging;
|
|
89
72
|
}(Router);
|
|
90
|
-
|
|
91
73
|
export function createApiRouter(isSlowServer, urlsReturnErrorsTo) {
|
|
92
74
|
var requestDelay = isSlowServer ? 200 : 10;
|
|
93
75
|
var router = new RouterWithLogging({
|
|
@@ -98,25 +80,25 @@ export function createApiRouter(isSlowServer, urlsReturnErrorsTo) {
|
|
|
98
80
|
});
|
|
99
81
|
router.post('/collection', function (_ref, database) {
|
|
100
82
|
var body = _ref.body;
|
|
101
|
-
|
|
102
83
|
var _JSON$parse = JSON.parse(body),
|
|
103
|
-
|
|
104
|
-
|
|
84
|
+
name = _JSON$parse.name;
|
|
105
85
|
var collection = createCollection(name);
|
|
106
86
|
database.push('collection', collection);
|
|
107
87
|
return {
|
|
108
88
|
data: collection
|
|
109
89
|
};
|
|
110
|
-
});
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
// TODO [EDM-1151]: Implement router.get('/file/binary') for videos
|
|
111
93
|
|
|
112
94
|
router.post('/file/binary', function (_ref2, database) {
|
|
113
95
|
var headers = _ref2.headers,
|
|
114
|
-
|
|
115
|
-
|
|
96
|
+
body = _ref2.body,
|
|
97
|
+
query = _ref2.query;
|
|
116
98
|
var mimeType = headers['Content-Type'];
|
|
117
99
|
var collection = query.collection,
|
|
118
|
-
|
|
119
|
-
|
|
100
|
+
name = query.name,
|
|
101
|
+
occurrenceKey = query.occurrenceKey;
|
|
120
102
|
var item = createCollectionItem({
|
|
121
103
|
collectionName: collection,
|
|
122
104
|
name: name,
|
|
@@ -133,9 +115,9 @@ export function createApiRouter(isSlowServer, urlsReturnErrorsTo) {
|
|
|
133
115
|
});
|
|
134
116
|
router.get('/collection/:collectionName/items', function (_ref3, database) {
|
|
135
117
|
var params = _ref3.params,
|
|
136
|
-
|
|
118
|
+
query = _ref3.query;
|
|
137
119
|
var limit = query.limit,
|
|
138
|
-
|
|
120
|
+
inclusiveStartKey = query.inclusiveStartKey;
|
|
139
121
|
var collectionName = params.collectionName;
|
|
140
122
|
var startIndex = inclusiveStartKey && parseInt(inclusiveStartKey, 10) || 0;
|
|
141
123
|
var endIndex = startIndex + parseInt(limit, 10);
|
|
@@ -152,24 +134,21 @@ export function createApiRouter(isSlowServer, urlsReturnErrorsTo) {
|
|
|
152
134
|
}
|
|
153
135
|
};
|
|
154
136
|
});
|
|
155
|
-
|
|
156
137
|
var isSvgFile = function isSvgFile(record) {
|
|
157
138
|
return !!(record.data.blob && record.data.blob.type === 'image/svg+xml');
|
|
158
139
|
};
|
|
159
|
-
|
|
160
140
|
router.get('/file/:fileId/image', function (_ref4, database) {
|
|
161
141
|
var params = _ref4.params,
|
|
162
|
-
|
|
142
|
+
query = _ref4.query;
|
|
163
143
|
var fileId = params.fileId;
|
|
164
144
|
var width = query.width,
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
145
|
+
height = query.height,
|
|
146
|
+
_query$maxAge = query['max-age'],
|
|
147
|
+
maxAge = _query$maxAge === void 0 ? 3600 : _query$maxAge;
|
|
168
148
|
var record = database.findOne('collectionItem', {
|
|
169
149
|
id: fileId
|
|
170
150
|
});
|
|
171
151
|
var blob;
|
|
172
|
-
|
|
173
152
|
if (!record || !record.data.blob || isSvgFile(record)) {
|
|
174
153
|
var dataUri = mockDataUri(width, height);
|
|
175
154
|
blob = mapDataUriToBlob(dataUri);
|
|
@@ -178,7 +157,6 @@ export function createApiRouter(isSlowServer, urlsReturnErrorsTo) {
|
|
|
178
157
|
} else {
|
|
179
158
|
blob = record.data.blob;
|
|
180
159
|
}
|
|
181
|
-
|
|
182
160
|
return new KakapoResponse(200, blob, {
|
|
183
161
|
'content-type': blob.type,
|
|
184
162
|
'content-length': blob.size.toString(),
|
|
@@ -202,12 +180,10 @@ export function createApiRouter(isSlowServer, urlsReturnErrorsTo) {
|
|
|
202
180
|
width: 4096
|
|
203
181
|
};
|
|
204
182
|
dimensions = Promise.resolve(defaultDimensions);
|
|
205
|
-
|
|
206
183
|
if (record && record.data.blob && !isSvgFile(record)) {
|
|
207
184
|
dimensions = new Promise(function (resolve) {
|
|
208
185
|
var image = new Image();
|
|
209
186
|
image.src = URL.createObjectURL(record.data.blob);
|
|
210
|
-
|
|
211
187
|
image.onload = function () {
|
|
212
188
|
return resolve({
|
|
213
189
|
height: image.height,
|
|
@@ -216,11 +192,9 @@ export function createApiRouter(isSlowServer, urlsReturnErrorsTo) {
|
|
|
216
192
|
};
|
|
217
193
|
});
|
|
218
194
|
}
|
|
219
|
-
|
|
220
195
|
_context.t0 = {};
|
|
221
196
|
_context.next = 9;
|
|
222
197
|
return dimensions;
|
|
223
|
-
|
|
224
198
|
case 9:
|
|
225
199
|
_context.t1 = _context.sent;
|
|
226
200
|
_context.t2 = {
|
|
@@ -231,7 +205,6 @@ export function createApiRouter(isSlowServer, urlsReturnErrorsTo) {
|
|
|
231
205
|
return _context.abrupt("return", {
|
|
232
206
|
metadata: _context.t2
|
|
233
207
|
});
|
|
234
|
-
|
|
235
208
|
case 12:
|
|
236
209
|
case "end":
|
|
237
210
|
return _context.stop();
|
|
@@ -239,7 +212,6 @@ export function createApiRouter(isSlowServer, urlsReturnErrorsTo) {
|
|
|
239
212
|
}
|
|
240
213
|
}, _callee);
|
|
241
214
|
}));
|
|
242
|
-
|
|
243
215
|
return function (_x, _x2) {
|
|
244
216
|
return _ref6.apply(this, arguments);
|
|
245
217
|
};
|
|
@@ -252,7 +224,6 @@ export function createApiRouter(isSlowServer, urlsReturnErrorsTo) {
|
|
|
252
224
|
router.head('/chunk/:chunkId', function (_ref7, database) {
|
|
253
225
|
var params = _ref7.params;
|
|
254
226
|
var chunkId = params.chunkId;
|
|
255
|
-
|
|
256
227
|
if (database.findOne('chunk', {
|
|
257
228
|
id: chunkId
|
|
258
229
|
})) {
|
|
@@ -263,7 +234,7 @@ export function createApiRouter(isSlowServer, urlsReturnErrorsTo) {
|
|
|
263
234
|
});
|
|
264
235
|
router.put('/chunk/:chunkId', function (_ref8, database) {
|
|
265
236
|
var params = _ref8.params,
|
|
266
|
-
|
|
237
|
+
body = _ref8.body;
|
|
267
238
|
var chunkId = params.chunkId;
|
|
268
239
|
database.push('chunk', {
|
|
269
240
|
id: chunkId,
|
|
@@ -271,13 +242,12 @@ export function createApiRouter(isSlowServer, urlsReturnErrorsTo) {
|
|
|
271
242
|
});
|
|
272
243
|
return new KakapoResponse(201, undefined, {});
|
|
273
244
|
});
|
|
245
|
+
|
|
274
246
|
/** This function waits for shouldWaitUpload to be false before it resolves the promise.
|
|
275
247
|
* Otherwise it recursively calls itself with a 10ms timeout until it is false.*/
|
|
276
|
-
|
|
277
248
|
function awaitUpload(_x3) {
|
|
278
249
|
return _awaitUpload.apply(this, arguments);
|
|
279
250
|
}
|
|
280
|
-
|
|
281
251
|
function _awaitUpload() {
|
|
282
252
|
_awaitUpload = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(resolver) {
|
|
283
253
|
return _regeneratorRuntime.wrap(function _callee3$(_context3) {
|
|
@@ -291,14 +261,11 @@ export function createApiRouter(isSlowServer, urlsReturnErrorsTo) {
|
|
|
291
261
|
}, 10);
|
|
292
262
|
return;
|
|
293
263
|
}
|
|
294
|
-
|
|
295
264
|
if (resolver && !window.mediaMockControlsBackdoor.shouldWaitUpload) {
|
|
296
265
|
resolver();
|
|
297
266
|
}
|
|
298
|
-
|
|
299
267
|
resolve();
|
|
300
268
|
}));
|
|
301
|
-
|
|
302
269
|
case 1:
|
|
303
270
|
case "end":
|
|
304
271
|
return _context3.stop();
|
|
@@ -308,11 +275,9 @@ export function createApiRouter(isSlowServer, urlsReturnErrorsTo) {
|
|
|
308
275
|
}));
|
|
309
276
|
return _awaitUpload.apply(this, arguments);
|
|
310
277
|
}
|
|
311
|
-
|
|
312
278
|
router.post('/chunk/probe', /*#__PURE__*/function () {
|
|
313
279
|
var _ref10 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(_ref9, database) {
|
|
314
280
|
var body, _JSON$parse2, chunks, allChunks, existingChunks, nonExistingChunks;
|
|
315
|
-
|
|
316
281
|
return _regeneratorRuntime.wrap(function _callee2$(_context2) {
|
|
317
282
|
while (1) {
|
|
318
283
|
switch (_context2.prev = _context2.next) {
|
|
@@ -324,7 +289,6 @@ export function createApiRouter(isSlowServer, urlsReturnErrorsTo) {
|
|
|
324
289
|
nonExistingChunks = [];
|
|
325
290
|
allChunks.forEach(function (_ref11) {
|
|
326
291
|
var id = _ref11.data.id;
|
|
327
|
-
|
|
328
292
|
if (chunks.indexOf(id) > -1) {
|
|
329
293
|
existingChunks.push(id);
|
|
330
294
|
} else {
|
|
@@ -333,7 +297,6 @@ export function createApiRouter(isSlowServer, urlsReturnErrorsTo) {
|
|
|
333
297
|
});
|
|
334
298
|
_context2.next = 8;
|
|
335
299
|
return awaitUpload();
|
|
336
|
-
|
|
337
300
|
case 8:
|
|
338
301
|
return _context2.abrupt("return", {
|
|
339
302
|
data: {
|
|
@@ -348,7 +311,6 @@ export function createApiRouter(isSlowServer, urlsReturnErrorsTo) {
|
|
|
348
311
|
})))
|
|
349
312
|
}
|
|
350
313
|
});
|
|
351
|
-
|
|
352
314
|
case 9:
|
|
353
315
|
case "end":
|
|
354
316
|
return _context2.stop();
|
|
@@ -356,7 +318,6 @@ export function createApiRouter(isSlowServer, urlsReturnErrorsTo) {
|
|
|
356
318
|
}
|
|
357
319
|
}, _callee2);
|
|
358
320
|
}));
|
|
359
|
-
|
|
360
321
|
return function (_x4, _x5) {
|
|
361
322
|
return _ref10.apply(this, arguments);
|
|
362
323
|
};
|
|
@@ -364,7 +325,7 @@ export function createApiRouter(isSlowServer, urlsReturnErrorsTo) {
|
|
|
364
325
|
router.post('/upload', function (_ref12, database) {
|
|
365
326
|
var query = _ref12.query;
|
|
366
327
|
var _query$createUpTo = query.createUpTo,
|
|
367
|
-
|
|
328
|
+
createUpTo = _query$createUpTo === void 0 ? '1' : _query$createUpTo;
|
|
368
329
|
var records = database.create('upload', Number.parseInt(createUpTo, 10));
|
|
369
330
|
var data = records.map(function (record) {
|
|
370
331
|
return record.data;
|
|
@@ -375,16 +336,13 @@ export function createApiRouter(isSlowServer, urlsReturnErrorsTo) {
|
|
|
375
336
|
});
|
|
376
337
|
router.put('/upload/:uploadId/chunks', function (_ref13, database) {
|
|
377
338
|
var params = _ref13.params,
|
|
378
|
-
|
|
339
|
+
body = _ref13.body;
|
|
379
340
|
var uploadId = params.uploadId;
|
|
380
|
-
|
|
381
341
|
var _JSON$parse3 = JSON.parse(body),
|
|
382
|
-
|
|
383
|
-
|
|
342
|
+
chunks = _JSON$parse3.chunks;
|
|
384
343
|
var record = database.findOne('upload', {
|
|
385
344
|
id: uploadId
|
|
386
345
|
});
|
|
387
|
-
|
|
388
346
|
if (record) {
|
|
389
347
|
database.update('upload', record.id, {
|
|
390
348
|
chunks: [].concat(_toConsumableArray(record.data.chunks), _toConsumableArray(chunks))
|
|
@@ -410,44 +368,36 @@ export function createApiRouter(isSlowServer, urlsReturnErrorsTo) {
|
|
|
410
368
|
});
|
|
411
369
|
router.post('/file/upload', function (_ref15, database) {
|
|
412
370
|
var query = _ref15.query,
|
|
413
|
-
|
|
371
|
+
body = _ref15.body;
|
|
414
372
|
var collection = query.collection,
|
|
415
|
-
|
|
416
|
-
|
|
373
|
+
replaceFileId = query.replaceFileId;
|
|
417
374
|
var _JSON$parse4 = JSON.parse(body),
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
375
|
+
name = _JSON$parse4.name,
|
|
376
|
+
mimeType = _JSON$parse4.mimeType,
|
|
377
|
+
uploadId = _JSON$parse4.uploadId;
|
|
422
378
|
var uploadRecord = database.findOne('upload', {
|
|
423
379
|
id: uploadId
|
|
424
380
|
});
|
|
425
|
-
|
|
426
381
|
if (!uploadRecord) {
|
|
427
382
|
return new KakapoResponse(404, {
|
|
428
383
|
message: "upload ".concat(uploadId, " is not found")
|
|
429
384
|
}, {});
|
|
430
385
|
}
|
|
431
|
-
|
|
432
386
|
var fileRecord = database.findOne('collectionItem', {
|
|
433
387
|
id: replaceFileId
|
|
434
388
|
});
|
|
435
|
-
|
|
436
389
|
if (fileRecord === undefined) {
|
|
437
390
|
return new KakapoResponse(404, {
|
|
438
391
|
message: "file ".concat(replaceFileId, " is not found")
|
|
439
392
|
}, {});
|
|
440
393
|
}
|
|
441
|
-
|
|
442
394
|
var totalBlob = uploadRecord.data.chunks.reduce(function (memo, chunkId) {
|
|
443
395
|
var chunkRecord = database.findOne('chunk', {
|
|
444
396
|
id: chunkId
|
|
445
397
|
});
|
|
446
|
-
|
|
447
398
|
if (!chunkRecord || !chunkRecord.data.blob) {
|
|
448
399
|
return memo;
|
|
449
400
|
}
|
|
450
|
-
|
|
451
401
|
return new Blob([memo, chunkRecord.data.blob], {
|
|
452
402
|
type: memo.type
|
|
453
403
|
});
|
|
@@ -455,7 +405,6 @@ export function createApiRouter(isSlowServer, urlsReturnErrorsTo) {
|
|
|
455
405
|
type: mimeType
|
|
456
406
|
}));
|
|
457
407
|
var mediaType = getMediaTypeFromMimeType(mimeType);
|
|
458
|
-
|
|
459
408
|
var newDetails = _objectSpread(_objectSpread({}, fileRecord.data.details || {}), {}, {
|
|
460
409
|
name: name,
|
|
461
410
|
mimeType: mimeType,
|
|
@@ -468,7 +417,6 @@ export function createApiRouter(isSlowServer, urlsReturnErrorsTo) {
|
|
|
468
417
|
// This is to make MediaViewer work with newly uploaded video files
|
|
469
418
|
processingStatus: mediaType === 'video' ? 'pending' : 'succeeded'
|
|
470
419
|
});
|
|
471
|
-
|
|
472
420
|
database.update('collectionItem', fileRecord.id, {
|
|
473
421
|
collectionName: collection,
|
|
474
422
|
blob: totalBlob,
|
|
@@ -482,14 +430,13 @@ export function createApiRouter(isSlowServer, urlsReturnErrorsTo) {
|
|
|
482
430
|
});
|
|
483
431
|
router.get('/file/:fileId', function (_ref16, database) {
|
|
484
432
|
var params = _ref16.params,
|
|
485
|
-
|
|
433
|
+
query = _ref16.query;
|
|
486
434
|
var fileId = params.fileId;
|
|
487
435
|
var collection = query.collection;
|
|
488
436
|
var record = database.findOne('collectionItem', {
|
|
489
437
|
id: fileId,
|
|
490
438
|
collectionName: collection
|
|
491
439
|
});
|
|
492
|
-
|
|
493
440
|
if (record) {
|
|
494
441
|
return {
|
|
495
442
|
data: _objectSpread({
|
|
@@ -502,14 +449,12 @@ export function createApiRouter(isSlowServer, urlsReturnErrorsTo) {
|
|
|
502
449
|
});
|
|
503
450
|
router.post('/items', function (_ref17, database) {
|
|
504
451
|
var body = _ref17.body;
|
|
505
|
-
|
|
506
452
|
var _ref18 = JSON.parse(body),
|
|
507
|
-
|
|
508
|
-
|
|
453
|
+
descriptors = _ref18.descriptors;
|
|
509
454
|
var fileItems = descriptors.map(function (descriptor) {
|
|
510
455
|
var record = database.findOne('collectionItem', {
|
|
511
|
-
id: descriptor.id
|
|
512
|
-
|
|
456
|
+
id: descriptor.id
|
|
457
|
+
// TODO [MS-2249]: add collectionName: descriptor.collection check
|
|
513
458
|
});
|
|
514
459
|
|
|
515
460
|
if (record) {
|
|
@@ -520,7 +465,6 @@ export function createApiRouter(isSlowServer, urlsReturnErrorsTo) {
|
|
|
520
465
|
details: record.data.details
|
|
521
466
|
};
|
|
522
467
|
}
|
|
523
|
-
|
|
524
468
|
return null;
|
|
525
469
|
}).filter(function (fileItem) {
|
|
526
470
|
return fileItem !== null;
|
|
@@ -533,24 +477,19 @@ export function createApiRouter(isSlowServer, urlsReturnErrorsTo) {
|
|
|
533
477
|
});
|
|
534
478
|
router.post('/file/copy/withToken', function (request, database) {
|
|
535
479
|
var body = request.body,
|
|
536
|
-
|
|
537
|
-
|
|
480
|
+
query = request.query;
|
|
538
481
|
var _JSON$parse5 = JSON.parse(body),
|
|
539
|
-
|
|
540
|
-
|
|
482
|
+
sourceFile = _JSON$parse5.sourceFile;
|
|
541
483
|
var destinationCollection = query.collection,
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
484
|
+
replaceFileId = query.replaceFileId,
|
|
485
|
+
occurrenceKey = query.occurrenceKey;
|
|
545
486
|
if (replaceFileId && !occurrenceKey || !replaceFileId && occurrenceKey) {
|
|
546
487
|
return new KakapoResponse(404, undefined, {});
|
|
547
488
|
}
|
|
548
|
-
|
|
549
489
|
var sourceRecord = database.findOne('collectionItem', {
|
|
550
490
|
id: sourceFile.id,
|
|
551
491
|
collectionName: sourceFile.collection
|
|
552
492
|
});
|
|
553
|
-
|
|
554
493
|
if (!replaceFileId && !occurrenceKey) {
|
|
555
494
|
replaceFileId = uuid();
|
|
556
495
|
occurrenceKey = uuid();
|
|
@@ -560,65 +499,61 @@ export function createApiRouter(isSlowServer, urlsReturnErrorsTo) {
|
|
|
560
499
|
occurrenceKey: occurrenceKey
|
|
561
500
|
}));
|
|
562
501
|
}
|
|
563
|
-
|
|
564
502
|
var existingRecord = database.findOne('collectionItem', {
|
|
565
503
|
id: replaceFileId,
|
|
566
504
|
collectionName: destinationCollection,
|
|
567
505
|
occurrenceKey: occurrenceKey
|
|
568
506
|
});
|
|
569
|
-
|
|
570
507
|
if (sourceRecord && existingRecord) {
|
|
571
508
|
var extension = getTextFileType();
|
|
572
509
|
var _sourceRecord$data = sourceRecord.data,
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
510
|
+
id = _sourceRecord$data.id,
|
|
511
|
+
details = _sourceRecord$data.details,
|
|
512
|
+
blob = _sourceRecord$data.blob;
|
|
577
513
|
var _ref19 = isMediaCollectionItemFullDetails(details) ? details : {},
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
514
|
+
_ref19$name = _ref19.name,
|
|
515
|
+
name = _ref19$name === void 0 ? getFakeFileName(extension) : _ref19$name,
|
|
516
|
+
_ref19$size = _ref19.size,
|
|
517
|
+
size = _ref19$size === void 0 ? blob && blob.size || 0 : _ref19$size,
|
|
518
|
+
_ref19$mediaType = _ref19.mediaType,
|
|
519
|
+
mediaType = _ref19$mediaType === void 0 ? 'image' : _ref19$mediaType,
|
|
520
|
+
_ref19$mimeType = _ref19.mimeType,
|
|
521
|
+
mimeType = _ref19$mimeType === void 0 ? 'image/jpeg' : _ref19$mimeType,
|
|
522
|
+
_ref19$processingStat = _ref19.processingStatus,
|
|
523
|
+
processingStatus = _ref19$processingStat === void 0 ? 'succeeded' : _ref19$processingStat,
|
|
524
|
+
_ref19$artifacts = _ref19.artifacts,
|
|
525
|
+
artifacts = _ref19$artifacts === void 0 ? {
|
|
526
|
+
'thumb_320.jpg': {
|
|
527
|
+
url: "/file/".concat(id, "/artifact/thumb_320.jpg/binary"),
|
|
528
|
+
processingStatus: 'succeeded'
|
|
529
|
+
},
|
|
530
|
+
'thumb_large.jpg': {
|
|
531
|
+
url: "/file/".concat(id, "/artifact/thumb_320.jpg/binary"),
|
|
532
|
+
processingStatus: 'succeeded'
|
|
533
|
+
},
|
|
534
|
+
'thumb_120.jpg': {
|
|
535
|
+
url: "/file/".concat(id, "/artifact/thumb_120.jpg/binary"),
|
|
536
|
+
processingStatus: 'succeeded'
|
|
537
|
+
},
|
|
538
|
+
'thumb.jpg': {
|
|
539
|
+
url: "/file/".concat(id, "/artifact/thumb_120.jpg/binary"),
|
|
540
|
+
processingStatus: 'succeeded'
|
|
541
|
+
},
|
|
542
|
+
'meta.json': {
|
|
543
|
+
url: "/file/".concat(id, "/artifact/meta.json/binary"),
|
|
544
|
+
processingStatus: 'succeeded'
|
|
545
|
+
},
|
|
546
|
+
'image.jpg': {
|
|
547
|
+
url: "/file/".concat(id, "/artifact/image.jpg/binary"),
|
|
548
|
+
processingStatus: 'succeeded'
|
|
549
|
+
}
|
|
550
|
+
} : _ref19$artifacts,
|
|
551
|
+
_ref19$representation = _ref19.representations,
|
|
552
|
+
representations = _ref19$representation === void 0 ? {
|
|
553
|
+
image: {}
|
|
554
|
+
} : _ref19$representation,
|
|
555
|
+
_ref19$createdAt = _ref19.createdAt,
|
|
556
|
+
createdAt = _ref19$createdAt === void 0 ? -1 : _ref19$createdAt;
|
|
622
557
|
database.update('collectionItem', existingRecord.id, {
|
|
623
558
|
id: replaceFileId,
|
|
624
559
|
insertedAt: sourceRecord.data.insertedAt,
|
|
@@ -673,7 +608,6 @@ export function createApiRouter(isSlowServer, urlsReturnErrorsTo) {
|
|
|
673
608
|
message: 'As you wish, master!'
|
|
674
609
|
});
|
|
675
610
|
};
|
|
676
|
-
|
|
677
611
|
router.delete(url, return500);
|
|
678
612
|
router.get(url, return500);
|
|
679
613
|
router.post(url, return500);
|