@atlaskit/media-client 36.1.1 → 36.2.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 CHANGED
@@ -1,5 +1,13 @@
1
1
  # @atlaskit/media-client
2
2
 
3
+ ## 36.2.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [`21abd28a7966a`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/21abd28a7966a) -
8
+ Adds x-expected-size header to multipart chunk uploads to prevent corrupted file entries in the
9
+ object store.
10
+
3
11
  ## 36.1.1
4
12
 
5
13
  ### Patch Changes
@@ -840,8 +840,8 @@ var MediaStore = exports.MediaStore = /*#__PURE__*/function () {
840
840
  }, {
841
841
  key: "appendChunksToUpload",
842
842
  value: function () {
843
- var _appendChunksToUpload = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee15(uploadId, body, collectionName, traceContext) {
844
- var metadata, options;
843
+ var _appendChunksToUpload = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee15(uploadId, body, collectionName, traceContext, options) {
844
+ var metadata, headers, requestOptions;
845
845
  return _regenerator.default.wrap(function _callee15$(_context15) {
846
846
  while (1) switch (_context15.prev = _context15.next) {
847
847
  case 0:
@@ -849,23 +849,27 @@ var MediaStore = exports.MediaStore = /*#__PURE__*/function () {
849
849
  method: 'PUT',
850
850
  endpoint: '/upload/{uploadId}/chunks'
851
851
  };
852
- options = _objectSpread(_objectSpread({}, metadata), {}, {
852
+ headers = _objectSpread({}, jsonHeaders);
853
+ if ((options === null || options === void 0 ? void 0 : options.expectedFileSize) !== undefined && (0, _platformFeatureFlags.fg)('platform_media_upload_expected_size_header')) {
854
+ headers['x-expected-size'] = options.expectedFileSize.toString();
855
+ }
856
+ requestOptions = _objectSpread(_objectSpread({}, metadata), {}, {
853
857
  authContext: {
854
858
  collectionName: collectionName
855
859
  },
856
- headers: jsonHeaders,
860
+ headers: headers,
857
861
  body: JSON.stringify(body),
858
862
  traceContext: traceContext
859
863
  });
860
- _context15.next = 4;
861
- return this.request("/upload/".concat(uploadId, "/chunks"), options);
862
- case 4:
864
+ _context15.next = 6;
865
+ return this.request("/upload/".concat(uploadId, "/chunks"), requestOptions);
866
+ case 6:
863
867
  case "end":
864
868
  return _context15.stop();
865
869
  }
866
870
  }, _callee15, this);
867
871
  }));
868
- function appendChunksToUpload(_x51, _x52, _x53, _x54) {
872
+ function appendChunksToUpload(_x51, _x52, _x53, _x54, _x55) {
869
873
  return _appendChunksToUpload.apply(this, arguments);
870
874
  }
871
875
  return appendChunksToUpload;
@@ -948,7 +952,7 @@ var MediaStore = exports.MediaStore = /*#__PURE__*/function () {
948
952
  }
949
953
  }, _callee16, this);
950
954
  }));
951
- function registerCopyIntents(_x55, _x56, _x57) {
955
+ function registerCopyIntents(_x56, _x57, _x58) {
952
956
  return _registerCopyIntents.apply(this, arguments);
953
957
  }
954
958
  return registerCopyIntents;
@@ -1036,7 +1040,7 @@ var MediaStore = exports.MediaStore = /*#__PURE__*/function () {
1036
1040
  }
1037
1041
  }, _callee17, this);
1038
1042
  }));
1039
- function request(_x58) {
1043
+ function request(_x59) {
1040
1044
  return _request2.apply(this, arguments);
1041
1045
  }
1042
1046
  return request;
@@ -1069,7 +1073,7 @@ var MediaStore = exports.MediaStore = /*#__PURE__*/function () {
1069
1073
  }
1070
1074
  }, _callee18);
1071
1075
  }));
1072
- function testUrl(_x59) {
1076
+ function testUrl(_x60) {
1073
1077
  return _testUrl.apply(this, arguments);
1074
1078
  }
1075
1079
  return testUrl;
@@ -68,7 +68,7 @@ var createUploadingFunction = function createUploadingFunction(store, deferredUp
68
68
  };
69
69
  }();
70
70
  };
71
- var createProcessingFunction = function createProcessingFunction(store, deferredUploadId, collection, traceContext) {
71
+ var createProcessingFunction = function createProcessingFunction(store, deferredUploadId, collection, traceContext, size) {
72
72
  var offset = 0;
73
73
  return /*#__PURE__*/function () {
74
74
  var _ref3 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee3(chunks) {
@@ -86,11 +86,14 @@ var createProcessingFunction = function createProcessingFunction(store, deferred
86
86
  };
87
87
  _context3.t3 = collection;
88
88
  _context3.t4 = traceContext;
89
- _context3.next = 9;
90
- return _context3.t0.appendChunksToUpload.call(_context3.t0, _context3.t1, _context3.t2, _context3.t3, _context3.t4);
91
- case 9:
92
- offset += chunks.length;
89
+ _context3.t5 = {
90
+ expectedFileSize: size
91
+ };
92
+ _context3.next = 10;
93
+ return _context3.t0.appendChunksToUpload.call(_context3.t0, _context3.t1, _context3.t2, _context3.t3, _context3.t4, _context3.t5);
93
94
  case 10:
95
+ offset += chunks.length;
96
+ case 11:
94
97
  case "end":
95
98
  return _context3.stop();
96
99
  }
@@ -170,7 +173,7 @@ var uploadFile = exports.uploadFile = function uploadFile(file, store, uploadabl
170
173
  uploadingConcurrency: 3,
171
174
  uploadingFunction: createUploadingFunction(store, deferredUploadId, collection, traceContext),
172
175
  processingBatchSize: _constants.PROCESSING_BATCH_SIZE,
173
- processingFunction: createProcessingFunction(store, deferredUploadId, collection, traceContext)
176
+ processingFunction: createProcessingFunction(store, deferredUploadId, collection, traceContext, file.size)
174
177
  }, {
175
178
  onProgress: function onProgress(progress) {
176
179
  if (callbacks) {
@@ -523,21 +523,27 @@ export class MediaStore {
523
523
  };
524
524
  return this.request(`/file/${id}/document/${endpoint}`, requestOptions).then(createMapResponseToBlob(metadata));
525
525
  }
526
- async appendChunksToUpload(uploadId, body, collectionName, traceContext) {
526
+ async appendChunksToUpload(uploadId, body, collectionName, traceContext, options) {
527
527
  const metadata = {
528
528
  method: 'PUT',
529
529
  endpoint: '/upload/{uploadId}/chunks'
530
530
  };
531
- const options = {
531
+ const headers = {
532
+ ...jsonHeaders
533
+ };
534
+ if ((options === null || options === void 0 ? void 0 : options.expectedFileSize) !== undefined && fg('platform_media_upload_expected_size_header')) {
535
+ headers['x-expected-size'] = options.expectedFileSize.toString();
536
+ }
537
+ const requestOptions = {
532
538
  ...metadata,
533
539
  authContext: {
534
540
  collectionName
535
541
  },
536
- headers: jsonHeaders,
542
+ headers,
537
543
  body: JSON.stringify(body),
538
544
  traceContext
539
545
  };
540
- await this.request(`/upload/${uploadId}/chunks`, options);
546
+ await this.request(`/upload/${uploadId}/chunks`, requestOptions);
541
547
  }
542
548
  copyFileWithToken(body, params, traceContext) {
543
549
  const metadata = {
@@ -15,13 +15,15 @@ const hashingFunction = async (blob, hashAlgorithm) => {
15
15
  const createUploadingFunction = (store, deferredUploadId, collectionName, traceContext) => async chunk => {
16
16
  return await store.uploadChunk(chunk.hash, chunk.blob, await deferredUploadId, chunk.partNumber, collectionName, traceContext);
17
17
  };
18
- const createProcessingFunction = (store, deferredUploadId, collection, traceContext) => {
18
+ const createProcessingFunction = (store, deferredUploadId, collection, traceContext, size) => {
19
19
  let offset = 0;
20
20
  return async chunks => {
21
21
  await store.appendChunksToUpload(await deferredUploadId, {
22
22
  chunks: hashedChunks(chunks),
23
23
  offset
24
- }, collection, traceContext);
24
+ }, collection, traceContext, {
25
+ expectedFileSize: size
26
+ });
25
27
  offset += chunks.length;
26
28
  };
27
29
  };
@@ -89,7 +91,7 @@ export const uploadFile = (file, store, uploadableFileUpfrontIds, callbacks, tra
89
91
  uploadingConcurrency: 3,
90
92
  uploadingFunction: createUploadingFunction(store, deferredUploadId, collection, traceContext),
91
93
  processingBatchSize: PROCESSING_BATCH_SIZE,
92
- processingFunction: createProcessingFunction(store, deferredUploadId, collection, traceContext)
94
+ processingFunction: createProcessingFunction(store, deferredUploadId, collection, traceContext, file.size)
93
95
  }, {
94
96
  onProgress(progress) {
95
97
  if (callbacks) {
@@ -834,8 +834,8 @@ export var MediaStore = /*#__PURE__*/function () {
834
834
  }, {
835
835
  key: "appendChunksToUpload",
836
836
  value: function () {
837
- var _appendChunksToUpload = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee15(uploadId, body, collectionName, traceContext) {
838
- var metadata, options;
837
+ var _appendChunksToUpload = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee15(uploadId, body, collectionName, traceContext, options) {
838
+ var metadata, headers, requestOptions;
839
839
  return _regeneratorRuntime.wrap(function _callee15$(_context15) {
840
840
  while (1) switch (_context15.prev = _context15.next) {
841
841
  case 0:
@@ -843,23 +843,27 @@ export var MediaStore = /*#__PURE__*/function () {
843
843
  method: 'PUT',
844
844
  endpoint: '/upload/{uploadId}/chunks'
845
845
  };
846
- options = _objectSpread(_objectSpread({}, metadata), {}, {
846
+ headers = _objectSpread({}, jsonHeaders);
847
+ if ((options === null || options === void 0 ? void 0 : options.expectedFileSize) !== undefined && fg('platform_media_upload_expected_size_header')) {
848
+ headers['x-expected-size'] = options.expectedFileSize.toString();
849
+ }
850
+ requestOptions = _objectSpread(_objectSpread({}, metadata), {}, {
847
851
  authContext: {
848
852
  collectionName: collectionName
849
853
  },
850
- headers: jsonHeaders,
854
+ headers: headers,
851
855
  body: JSON.stringify(body),
852
856
  traceContext: traceContext
853
857
  });
854
- _context15.next = 4;
855
- return this.request("/upload/".concat(uploadId, "/chunks"), options);
856
- case 4:
858
+ _context15.next = 6;
859
+ return this.request("/upload/".concat(uploadId, "/chunks"), requestOptions);
860
+ case 6:
857
861
  case "end":
858
862
  return _context15.stop();
859
863
  }
860
864
  }, _callee15, this);
861
865
  }));
862
- function appendChunksToUpload(_x51, _x52, _x53, _x54) {
866
+ function appendChunksToUpload(_x51, _x52, _x53, _x54, _x55) {
863
867
  return _appendChunksToUpload.apply(this, arguments);
864
868
  }
865
869
  return appendChunksToUpload;
@@ -942,7 +946,7 @@ export var MediaStore = /*#__PURE__*/function () {
942
946
  }
943
947
  }, _callee16, this);
944
948
  }));
945
- function registerCopyIntents(_x55, _x56, _x57) {
949
+ function registerCopyIntents(_x56, _x57, _x58) {
946
950
  return _registerCopyIntents.apply(this, arguments);
947
951
  }
948
952
  return registerCopyIntents;
@@ -1030,7 +1034,7 @@ export var MediaStore = /*#__PURE__*/function () {
1030
1034
  }
1031
1035
  }, _callee17, this);
1032
1036
  }));
1033
- function request(_x58) {
1037
+ function request(_x59) {
1034
1038
  return _request2.apply(this, arguments);
1035
1039
  }
1036
1040
  return request;
@@ -1063,7 +1067,7 @@ export var MediaStore = /*#__PURE__*/function () {
1063
1067
  }
1064
1068
  }, _callee18);
1065
1069
  }));
1066
- function testUrl(_x59) {
1070
+ function testUrl(_x60) {
1067
1071
  return _testUrl.apply(this, arguments);
1068
1072
  }
1069
1073
  return testUrl;
@@ -62,7 +62,7 @@ var createUploadingFunction = function createUploadingFunction(store, deferredUp
62
62
  };
63
63
  }();
64
64
  };
65
- var createProcessingFunction = function createProcessingFunction(store, deferredUploadId, collection, traceContext) {
65
+ var createProcessingFunction = function createProcessingFunction(store, deferredUploadId, collection, traceContext, size) {
66
66
  var offset = 0;
67
67
  return /*#__PURE__*/function () {
68
68
  var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(chunks) {
@@ -80,11 +80,14 @@ var createProcessingFunction = function createProcessingFunction(store, deferred
80
80
  };
81
81
  _context3.t3 = collection;
82
82
  _context3.t4 = traceContext;
83
- _context3.next = 9;
84
- return _context3.t0.appendChunksToUpload.call(_context3.t0, _context3.t1, _context3.t2, _context3.t3, _context3.t4);
85
- case 9:
86
- offset += chunks.length;
83
+ _context3.t5 = {
84
+ expectedFileSize: size
85
+ };
86
+ _context3.next = 10;
87
+ return _context3.t0.appendChunksToUpload.call(_context3.t0, _context3.t1, _context3.t2, _context3.t3, _context3.t4, _context3.t5);
87
88
  case 10:
89
+ offset += chunks.length;
90
+ case 11:
88
91
  case "end":
89
92
  return _context3.stop();
90
93
  }
@@ -164,7 +167,7 @@ export var uploadFile = function uploadFile(file, store, uploadableFileUpfrontId
164
167
  uploadingConcurrency: 3,
165
168
  uploadingFunction: createUploadingFunction(store, deferredUploadId, collection, traceContext),
166
169
  processingBatchSize: PROCESSING_BATCH_SIZE,
167
- processingFunction: createProcessingFunction(store, deferredUploadId, collection, traceContext)
170
+ processingFunction: createProcessingFunction(store, deferredUploadId, collection, traceContext, file.size)
168
171
  }, {
169
172
  onProgress: function onProgress(progress) {
170
173
  if (callbacks) {
@@ -35,7 +35,9 @@ export declare class MediaStore implements MediaApi {
35
35
  }>;
36
36
  getDocumentContent(id: string, options: GetDocumentContentOptions, traceContext?: MediaTraceContext): Promise<DocumentPageRangeContent>;
37
37
  getDocumentPageImage(id: string, options: GetDocumentPageImage, traceContext?: MediaTraceContext): Promise<Blob>;
38
- appendChunksToUpload(uploadId: string, body: AppendChunksToUploadRequestBody, collectionName?: string, traceContext?: MediaTraceContext): Promise<void>;
38
+ appendChunksToUpload(uploadId: string, body: AppendChunksToUploadRequestBody, collectionName?: string, traceContext?: MediaTraceContext, options?: {
39
+ expectedFileSize?: number;
40
+ }): Promise<void>;
39
41
  copyFileWithToken(body: MediaStoreCopyFileWithTokenBody, params: MediaStoreCopyFileWithTokenParams, traceContext?: MediaTraceContext): Promise<MediaStoreResponse<MediaFile>>;
40
42
  copyFile(id: string, params: CopyFileParams, traceContext?: MediaTraceContext, clientId?: string): Promise<MediaStoreResponse<MediaFile>>;
41
43
  registerCopyIntents(files: Array<{
@@ -185,7 +185,9 @@ export interface MediaApi {
185
185
  getImageMetadata: (id: string, params?: MediaStoreGetFileImageParams, traceContext?: MediaTraceContext) => Promise<{
186
186
  metadata: ImageMetadata;
187
187
  }>;
188
- appendChunksToUpload: (uploadId: string, body: AppendChunksToUploadRequestBody, collectionName?: string, traceContext?: MediaTraceContext) => Promise<void>;
188
+ appendChunksToUpload: (uploadId: string, body: AppendChunksToUploadRequestBody, collectionName?: string, traceContext?: MediaTraceContext, options?: {
189
+ expectedFileSize?: number;
190
+ }) => Promise<void>;
189
191
  copyFileWithToken: (body: MediaStoreCopyFileWithTokenBody, params: MediaStoreCopyFileWithTokenParams, traceContext?: MediaTraceContext) => Promise<MediaStoreResponse<MediaFile>>;
190
192
  copyFile: (id: string, params: CopyFileParams) => Promise<MediaStoreResponse<MediaFile>>;
191
193
  registerCopyIntents: (files: Array<{
@@ -35,7 +35,9 @@ export declare class MediaStore implements MediaApi {
35
35
  }>;
36
36
  getDocumentContent(id: string, options: GetDocumentContentOptions, traceContext?: MediaTraceContext): Promise<DocumentPageRangeContent>;
37
37
  getDocumentPageImage(id: string, options: GetDocumentPageImage, traceContext?: MediaTraceContext): Promise<Blob>;
38
- appendChunksToUpload(uploadId: string, body: AppendChunksToUploadRequestBody, collectionName?: string, traceContext?: MediaTraceContext): Promise<void>;
38
+ appendChunksToUpload(uploadId: string, body: AppendChunksToUploadRequestBody, collectionName?: string, traceContext?: MediaTraceContext, options?: {
39
+ expectedFileSize?: number;
40
+ }): Promise<void>;
39
41
  copyFileWithToken(body: MediaStoreCopyFileWithTokenBody, params: MediaStoreCopyFileWithTokenParams, traceContext?: MediaTraceContext): Promise<MediaStoreResponse<MediaFile>>;
40
42
  copyFile(id: string, params: CopyFileParams, traceContext?: MediaTraceContext, clientId?: string): Promise<MediaStoreResponse<MediaFile>>;
41
43
  registerCopyIntents(files: Array<{
@@ -185,7 +185,9 @@ export interface MediaApi {
185
185
  getImageMetadata: (id: string, params?: MediaStoreGetFileImageParams, traceContext?: MediaTraceContext) => Promise<{
186
186
  metadata: ImageMetadata;
187
187
  }>;
188
- appendChunksToUpload: (uploadId: string, body: AppendChunksToUploadRequestBody, collectionName?: string, traceContext?: MediaTraceContext) => Promise<void>;
188
+ appendChunksToUpload: (uploadId: string, body: AppendChunksToUploadRequestBody, collectionName?: string, traceContext?: MediaTraceContext, options?: {
189
+ expectedFileSize?: number;
190
+ }) => Promise<void>;
189
191
  copyFileWithToken: (body: MediaStoreCopyFileWithTokenBody, params: MediaStoreCopyFileWithTokenParams, traceContext?: MediaTraceContext) => Promise<MediaStoreResponse<MediaFile>>;
190
192
  copyFile: (id: string, params: CopyFileParams) => Promise<MediaStoreResponse<MediaFile>>;
191
193
  registerCopyIntents: (files: Array<{
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/media-client",
3
- "version": "36.1.1",
3
+ "version": "36.2.0",
4
4
  "description": "Media API Web Client Library",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/"
@@ -31,7 +31,7 @@
31
31
  "dependencies": {
32
32
  "@atlaskit/atlassian-context": "^0.8.0",
33
33
  "@atlaskit/chunkinator": "^7.1.0",
34
- "@atlaskit/media-common": "^13.2.0",
34
+ "@atlaskit/media-common": "^13.3.0",
35
35
  "@atlaskit/platform-feature-flags": "^1.1.0",
36
36
  "@babel/runtime": "^7.0.0",
37
37
  "dataloader": "^2.1.0",
@@ -95,6 +95,9 @@
95
95
  },
96
96
  "confluence_watermark_admin_ui": {
97
97
  "type": "boolean"
98
+ },
99
+ "platform_media_upload_expected_size_header": {
100
+ "type": "boolean"
98
101
  }
99
102
  }
100
103
  }