@atlaskit/media-client 39.3.13 → 39.4.1

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/AGENTS.md CHANGED
@@ -54,3 +54,14 @@ first, edit, then `kg.py edit <path> --message "<reason>"`.
54
54
  `platform_media_auth_provider_analytics`, `platform_media_unique_external_upload_name`
55
55
  - All new behaviour changes must be behind a feature gate (`fg()` from
56
56
  `@atlaskit/platform-feature-flags`)
57
+
58
+ ## Uploads without collection read access
59
+
60
+ With `platform_media_upload_without_read` enabled, pass `skipRemoteFileState: true` on an
61
+ `UploadableFile` to complete from the successful `/file/upload` response. The client publishes that
62
+ response into the file-state store and completes the upload stream without requesting `/items` or
63
+ polling processing status. `processing` still means that preview processing is pending; it does not
64
+ mean the upload failed. Upload errors and cancellation still use the existing error path. Consumers
65
+ must also avoid components that fetch previews or download files.
66
+
67
+ The default upload flow continues to fetch remote file state.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,20 @@
1
1
  # @atlaskit/media-client
2
2
 
3
+ ## 39.4.1
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies
8
+
9
+ ## 39.4.0
10
+
11
+ ### Minor Changes
12
+
13
+ - [`9826a3254f648`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/9826a3254f648) -
14
+ Add `UploadableFile.skipRemoteFileState` and an optional upload response argument to
15
+ `onUploadFinish` behind `platform_media_upload_without_read`. Opted-in uploads complete from the
16
+ upload response without fetching remote metadata.
17
+
3
18
  ## 39.3.13
4
19
 
5
20
  ### Patch Changes
@@ -748,9 +748,14 @@ var FileFetcherImpl = exports.FileFetcherImpl = /*#__PURE__*/function () {
748
748
  var id = upfrontId.id,
749
749
  occurrenceKey = upfrontId.occurrenceKey;
750
750
  var stateBase = this.getUploadingFileStateBase(file, upfrontId);
751
+ var skipRemoteFileState = (0, _fg.fg)('platform_media_upload_without_read') && file.skipRemoteFileState;
751
752
  var subject = (0, _createMediaSubject.createMediaSubject)();
752
753
  (0, _fileStreamsCache.getFileStreamsCache)().set(id, subject);
754
+ var uploadFinished = false;
753
755
  var onProgress = function onProgress(progress) {
756
+ if (skipRemoteFileState && uploadFinished) {
757
+ return;
758
+ }
754
759
  var fileState = _objectSpread(_objectSpread({
755
760
  status: 'uploading'
756
761
  }, stateBase), {}, {
@@ -760,12 +765,23 @@ var FileFetcherImpl = exports.FileFetcherImpl = /*#__PURE__*/function () {
760
765
  _this4.setFileState(id, fileState);
761
766
  };
762
767
  var processingSubscription = new _Subscription.Subscription();
763
- var onUploadFinish = function onUploadFinish(error) {
768
+ var onUploadFinish = function onUploadFinish(error, response) {
769
+ uploadFinished = true;
764
770
  if (error) {
765
771
  var errorFileState = _this4.getErrorFileState(error, id, occurrenceKey);
766
772
  _this4.setFileState(id, errorFileState);
767
773
  return subject.error(error);
768
774
  }
775
+ if (skipRemoteFileState) {
776
+ var uploadedFileState = response ? (0, _mapMediaFileToFileState.mapMediaFileToFileState)(response) : _objectSpread(_objectSpread({}, stateBase), {}, {
777
+ status: 'processing'
778
+ });
779
+ var fileState = _objectSpread(_objectSpread(_objectSpread({}, stateBase), uploadedFileState), (0, _overrideMediaTypeIfUnknown.overrideMediaTypeIfUnknown)(uploadedFileState, stateBase.mediaType));
780
+ _this4.setFileState(id, fileState);
781
+ subject.next(fileState);
782
+ subject.complete();
783
+ return;
784
+ }
769
785
  processingSubscription = _this4.createDownloadFileStream(id, collection, occurrenceKey).pipe((0, _map.map)(function (remoteFileState) {
770
786
  return _objectSpread(_objectSpread(_objectSpread({}, stateBase), remoteFileState), (0, _overrideMediaTypeIfUnknown.overrideMediaTypeIfUnknown)(remoteFileState, stateBase.mediaType));
771
787
  })).subscribe({
@@ -175,16 +175,20 @@ var uploadFile = exports.uploadFile = function uploadFile(file, store, uploadabl
175
175
  }
176
176
  });
177
177
  var onUploadFinish = callbacks && callbacks.onUploadFinish || function () {};
178
+ var uploadResponse;
178
179
  var subscription = (0, _from.from)(deferredUploadId).pipe((0, _concatMap.concatMap)(function (uploadId) {
179
180
  return chunkinatorObservable.pipe((0, _concatMap.concatMap)(function () {
180
181
  return (0, _from.from)(createFileFromUpload(file, store, uploadableFileUpfrontIds, uploadId, traceContext));
181
182
  }));
182
183
  })).subscribe({
184
+ next: function next(response) {
185
+ uploadResponse = response;
186
+ },
183
187
  error: function error(err) {
184
188
  return onUploadFinish(err);
185
189
  },
186
190
  complete: function complete() {
187
- return onUploadFinish();
191
+ return onUploadFinish(undefined, uploadResponse);
188
192
  }
189
193
  });
190
194
  return {
@@ -488,9 +488,14 @@ export class FileFetcherImpl {
488
488
  occurrenceKey
489
489
  } = upfrontId;
490
490
  const stateBase = this.getUploadingFileStateBase(file, upfrontId);
491
+ const skipRemoteFileState = fg('platform_media_upload_without_read') && file.skipRemoteFileState;
491
492
  const subject = createMediaSubject();
492
493
  getFileStreamsCache().set(id, subject);
494
+ let uploadFinished = false;
493
495
  const onProgress = progress => {
496
+ if (skipRemoteFileState && uploadFinished) {
497
+ return;
498
+ }
494
499
  const fileState = {
495
500
  status: 'uploading',
496
501
  ...stateBase,
@@ -500,12 +505,28 @@ export class FileFetcherImpl {
500
505
  this.setFileState(id, fileState);
501
506
  };
502
507
  let processingSubscription = new Subscription();
503
- const onUploadFinish = error => {
508
+ const onUploadFinish = (error, response) => {
509
+ uploadFinished = true;
504
510
  if (error) {
505
511
  const errorFileState = this.getErrorFileState(error, id, occurrenceKey);
506
512
  this.setFileState(id, errorFileState);
507
513
  return subject.error(error);
508
514
  }
515
+ if (skipRemoteFileState) {
516
+ const uploadedFileState = response ? mapMediaFileToFileState(response) : {
517
+ ...stateBase,
518
+ status: 'processing'
519
+ };
520
+ const fileState = {
521
+ ...stateBase,
522
+ ...uploadedFileState,
523
+ ...overrideMediaTypeIfUnknown(uploadedFileState, stateBase.mediaType)
524
+ };
525
+ this.setFileState(id, fileState);
526
+ subject.next(fileState);
527
+ subject.complete();
528
+ return;
529
+ }
509
530
  processingSubscription = this.createDownloadFileStream(id, collection, occurrenceKey).pipe(map(remoteFileState => ({
510
531
  // merges base state with remote state
511
532
  ...stateBase,
@@ -103,9 +103,13 @@ export const uploadFile = (file, store, uploadableFileUpfrontIds, callbacks, tra
103
103
  }
104
104
  });
105
105
  const onUploadFinish = callbacks && callbacks.onUploadFinish || (() => {});
106
+ let uploadResponse;
106
107
  const subscription = from(deferredUploadId).pipe(concatMap(uploadId => chunkinatorObservable.pipe(concatMap(() => from(createFileFromUpload(file, store, uploadableFileUpfrontIds, uploadId, traceContext)))))).subscribe({
108
+ next: response => {
109
+ uploadResponse = response;
110
+ },
107
111
  error: err => onUploadFinish(err),
108
- complete: () => onUploadFinish()
112
+ complete: () => onUploadFinish(undefined, uploadResponse)
109
113
  });
110
114
  return {
111
115
  cancel: () => {
@@ -734,9 +734,14 @@ export var FileFetcherImpl = /*#__PURE__*/function () {
734
734
  var id = upfrontId.id,
735
735
  occurrenceKey = upfrontId.occurrenceKey;
736
736
  var stateBase = this.getUploadingFileStateBase(file, upfrontId);
737
+ var skipRemoteFileState = fg('platform_media_upload_without_read') && file.skipRemoteFileState;
737
738
  var subject = createMediaSubject();
738
739
  getFileStreamsCache().set(id, subject);
740
+ var uploadFinished = false;
739
741
  var onProgress = function onProgress(progress) {
742
+ if (skipRemoteFileState && uploadFinished) {
743
+ return;
744
+ }
740
745
  var fileState = _objectSpread(_objectSpread({
741
746
  status: 'uploading'
742
747
  }, stateBase), {}, {
@@ -746,12 +751,23 @@ export var FileFetcherImpl = /*#__PURE__*/function () {
746
751
  _this4.setFileState(id, fileState);
747
752
  };
748
753
  var processingSubscription = new Subscription();
749
- var onUploadFinish = function onUploadFinish(error) {
754
+ var onUploadFinish = function onUploadFinish(error, response) {
755
+ uploadFinished = true;
750
756
  if (error) {
751
757
  var errorFileState = _this4.getErrorFileState(error, id, occurrenceKey);
752
758
  _this4.setFileState(id, errorFileState);
753
759
  return subject.error(error);
754
760
  }
761
+ if (skipRemoteFileState) {
762
+ var uploadedFileState = response ? mapMediaFileToFileState(response) : _objectSpread(_objectSpread({}, stateBase), {}, {
763
+ status: 'processing'
764
+ });
765
+ var fileState = _objectSpread(_objectSpread(_objectSpread({}, stateBase), uploadedFileState), overrideMediaTypeIfUnknown(uploadedFileState, stateBase.mediaType));
766
+ _this4.setFileState(id, fileState);
767
+ subject.next(fileState);
768
+ subject.complete();
769
+ return;
770
+ }
755
771
  processingSubscription = _this4.createDownloadFileStream(id, collection, occurrenceKey).pipe(map(function (remoteFileState) {
756
772
  return _objectSpread(_objectSpread(_objectSpread({}, stateBase), remoteFileState), overrideMediaTypeIfUnknown(remoteFileState, stateBase.mediaType));
757
773
  })).subscribe({
@@ -169,16 +169,20 @@ export var uploadFile = function uploadFile(file, store, uploadableFileUpfrontId
169
169
  }
170
170
  });
171
171
  var onUploadFinish = callbacks && callbacks.onUploadFinish || function () {};
172
+ var uploadResponse;
172
173
  var subscription = from(deferredUploadId).pipe(concatMap(function (uploadId) {
173
174
  return chunkinatorObservable.pipe(concatMap(function () {
174
175
  return from(createFileFromUpload(file, store, uploadableFileUpfrontIds, uploadId, traceContext));
175
176
  }));
176
177
  })).subscribe({
178
+ next: function next(response) {
179
+ uploadResponse = response;
180
+ },
177
181
  error: function error(err) {
178
182
  return onUploadFinish(err);
179
183
  },
180
184
  complete: function complete() {
181
- return onUploadFinish();
185
+ return onUploadFinish(undefined, uploadResponse);
182
186
  }
183
187
  });
184
188
  return {
@@ -1,12 +1,16 @@
1
1
  import type { ChunkinatorFile } from '@atlaskit/chunkinator/domain';
2
2
  import type { MediaTraceContext } from '@atlaskit/media-common/analytics/types';
3
3
  import type { MediaStore } from '../client/media-store/MediaStore';
4
+ import type { MediaStoreResponse } from '../client/media-store/types';
5
+ import type { MediaFile } from '../models/media';
4
6
  export type UploadableFile = {
5
7
  content: ChunkinatorFile;
6
8
  name?: string;
7
9
  mimeType?: string;
8
10
  collection?: string;
9
11
  size: number;
12
+ /** Complete from the upload response without fetching remote file metadata. */
13
+ skipRemoteFileState?: boolean;
10
14
  };
11
15
  export type UploadableFileUpfrontIds = {
12
16
  id: string;
@@ -15,7 +19,7 @@ export type UploadableFileUpfrontIds = {
15
19
  };
16
20
  export type UploadFileCallbacks = {
17
21
  onProgress: (progress: number) => void;
18
- onUploadFinish: (error?: any) => void;
22
+ onUploadFinish: (error?: any, response?: MediaStoreResponse<MediaFile>) => void;
19
23
  };
20
24
  export interface UploadFileResult {
21
25
  cancel: () => void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/media-client",
3
- "version": "39.3.13",
3
+ "version": "39.4.1",
4
4
  "description": "Media API Web Client Library",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/"
@@ -25,7 +25,7 @@
25
25
  "@atlaskit/chunkinator": "^8.2.0",
26
26
  "@atlaskit/media-common": "^14.7.0",
27
27
  "@atlaskit/platform-feature-flags": "^2.2.0",
28
- "@atlaskit/tmp-editor-statsig": "^259.0.0",
28
+ "@atlaskit/tmp-editor-statsig": "^260.0.0",
29
29
  "@babel/runtime": "^7.0.0",
30
30
  "dataloader": "^2.1.0",
31
31
  "deep-equal": "^1.0.1",
@@ -48,7 +48,7 @@
48
48
  "@atlaskit/media-core": "^39.0.0",
49
49
  "@atlaskit/media-state": "^4.0.0",
50
50
  "@atlaskit/ssr": "workspace:^",
51
- "@atlaskit/tokens": "^20.9.0",
51
+ "@atlaskit/tokens": "^20.10.0",
52
52
  "@atlassian/a11y-jest-testing": "^0.17.0",
53
53
  "@atlassian/feature-flags-test-utils": "^1.3.0",
54
54
  "@atlassian/workbench": "workspace:^",
@@ -59,6 +59,9 @@
59
59
  "react-dom": "^18.2.0"
60
60
  },
61
61
  "platform-feature-flags": {
62
+ "platform_media_upload_without_read": {
63
+ "type": "boolean"
64
+ },
62
65
  "platform_media_cdn_single_host": {
63
66
  "type": "boolean"
64
67
  },