Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/api/uploads/BaseUpload.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ class BaseUpload extends Base {

isUploadFallbackLogicEnabled: boolean = false;

enableModernizedUploads: boolean = false;

/**
* Sends an upload pre-flight request. If a file ID is available,
* send a pre-flight request to that file version.
Expand Down
21 changes: 20 additions & 1 deletion src/api/uploads/MultiputUpload.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
HTTP_STATUS_CODE_FORBIDDEN,
MS_IN_S,
} from '../../constants';
import { updateQueryParameters } from '../../utils/url';
import MultiputPart, {
PART_STATE_UPLOADED,
PART_STATE_UPLOADING,
Expand All @@ -28,6 +29,7 @@ import BaseMultiput from './BaseMultiput';
import type { MultiputConfig } from '../../common/types/upload';
import type { StringAnyMap } from '../../common/types/core';
import type { APIOptions } from '../../common/types/api';
import { STANDARD_UPLOAD_FIELDS_WITH_VERSION_NUMBER } from '../../utils/fields';

// Constants used for specifying log event types.

Expand Down Expand Up @@ -177,12 +179,14 @@ class MultiputUpload extends BaseMultiput {
overwrite = true,
conflictCallback,
fileId,
enableModernizedUploads = false,
}: {
conflictCallback?: Function,
errorCallback?: Function,
file: File,
fileId: ?string,
folderId: string,
enableModernizedUploads?: boolean,
overwrite?: boolean | 'error',
progressCallback?: Function,
successCallback?: Function,
Expand All @@ -196,6 +200,7 @@ class MultiputUpload extends BaseMultiput {
this.overwrite = overwrite;
this.conflictCallback = conflictCallback;
this.fileId = fileId;
this.enableModernizedUploads = Boolean(enableModernizedUploads);
}

/**
Expand All @@ -222,13 +227,15 @@ class MultiputUpload extends BaseMultiput {
overwrite = true,
conflictCallback,
fileId,
enableModernizedUploads = false,
}: {
conflictCallback?: Function,
errorCallback?: Function,
file: File,
fileDescription: ?string,
fileId: ?string,
folderId: string,
enableModernizedUploads?: boolean,
overwrite?: boolean | 'error',
progressCallback?: Function,
successCallback?: Function,
Expand All @@ -251,6 +258,7 @@ class MultiputUpload extends BaseMultiput {
this.overwrite = overwrite;
this.fileId = fileId;
this.fileDescription = fileDescription;
this.enableModernizedUploads = enableModernizedUploads;

this.makePreflightRequest();
}
Expand Down Expand Up @@ -447,6 +455,7 @@ class MultiputUpload extends BaseMultiput {
overwrite = true,
conflictCallback,
fileId,
enableModernizedUploads = false,
}: {
conflictCallback?: Function,
errorCallback?: Function,
Expand All @@ -457,6 +466,7 @@ class MultiputUpload extends BaseMultiput {
progressCallback?: Function,
sessionId: string,
successCallback?: Function,
enableModernizedUploads?: boolean,
}): void {
this.setFileInfo({
file,
Expand All @@ -467,6 +477,7 @@ class MultiputUpload extends BaseMultiput {
conflictCallback,
overwrite,
fileId,
enableModernizedUploads,
});
this.sessionId = sessionId;

Expand Down Expand Up @@ -571,6 +582,7 @@ class MultiputUpload extends BaseMultiput {
successCallback: this.successCallback,
overwrite: this.overwrite,
fileId: this.fileId,
enableModernizedUploads: this.enableModernizedUploads,
};
this.upload(uploadOptions);
} else {
Expand Down Expand Up @@ -967,8 +979,15 @@ class MultiputUpload extends BaseMultiput {
'X-Box-Client-Event-Info': JSON.stringify(clientEventInfo),
};

let commitUrl = this.sessionEndpoints.commit;
if (this.enableModernizedUploads && !!this.fileId) {
commitUrl = updateQueryParameters(commitUrl, {
fields: STANDARD_UPLOAD_FIELDS_WITH_VERSION_NUMBER.join(','),
});
}

this.xhr
.post({ url: this.sessionEndpoints.commit, data, headers })
.post({ url: commitUrl, data, headers })
.then(this.commitSessionSuccessHandler)
.catch(this.commitSessionErrorHandler);
};
Expand Down
11 changes: 11 additions & 0 deletions src/api/uploads/PlainUpload.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import noop from 'lodash/noop';
import { digest } from '../../utils/webcrypto';
import { getFileLastModifiedAsISONoMSIfPossible } from '../../utils/uploads';
import { STANDARD_UPLOAD_FIELDS_WITH_VERSION_NUMBER } from '../../utils/fields';
import { updateQueryParameters } from '../../utils/url';
import BaseUpload from './BaseUpload';
import type { BoxItem } from '../../common/types/core';

Expand Down Expand Up @@ -74,6 +76,12 @@ class PlainUpload extends BaseUpload {
}
}

if (this.enableModernizedUploads && !!this.fileId) {
uploadUrl = updateQueryParameters(uploadUrl, {
fields: STANDARD_UPLOAD_FIELDS_WITH_VERSION_NUMBER.join(','),
});
}

const attributes = JSON.stringify({
name: this.fileName,
parent: { id: this.folderId },
Expand Down Expand Up @@ -130,13 +138,15 @@ class PlainUpload extends BaseUpload {
conflictCallback,
// $FlowFixMe
overwrite = true,
enableModernizedUploads = false,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we shouldn't use a feature flag in the APIs files. we should write this in a way that the consumers can opt in or out without it being specific to a feature. let's either utilize the existing overwrite option or add fileVersionNumber

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead, maybe call it fields based on the previous comment

}: {
conflictCallback?: Function,
errorCallback: Function,
file: File,
fileDescription: ?string,
fileId: ?string,
folderId: string,
enableModernizedUploads?: boolean,
overwrite: boolean | 'error',
progressCallback: Function,
successCallback: Function,
Expand All @@ -156,6 +166,7 @@ class PlainUpload extends BaseUpload {
this.progressCallback = progressCallback;
this.overwrite = overwrite;
this.conflictCallback = conflictCallback;
this.enableModernizedUploads = enableModernizedUploads;

this.makePreflightRequest();
}
Expand Down
2 changes: 2 additions & 0 deletions src/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ export const FIELD_SIZE: 'size' = 'size';
export const FIELD_PARENT = 'parent';
export const FIELD_EXTENSION = 'extension';
export const FIELD_ITEM_EXPIRATION = 'expires_at';
export const FIELD_ITEM_STATUS = 'item_status';
export const FIELD_PERMISSIONS = 'permissions';
export const FIELD_PERMISSIONS_CAN_SHARE = `${FIELD_PERMISSIONS}.can_share`;
export const FIELD_PERMISSIONS_CAN_UPLOAD = `${FIELD_PERMISSIONS}.can_upload`;
Expand Down Expand Up @@ -136,6 +137,7 @@ export const FIELD_CREATED_BY = 'created_by';
export const FIELD_MODIFIED_BY = 'modified_by';
export const FIELD_OWNED_BY = 'owned_by';
export const FIELD_PROMOTED_BY = 'promoted_by';
export const FIELD_PURGED_AT = 'purged_at';
export const FIELD_RESTORED_BY = 'restored_by';
export const FIELD_TRASHED_BY = 'trashed_by';
export const FIELD_DESCRIPTION = 'description';
Expand Down
6 changes: 4 additions & 2 deletions src/elements/content-uploader/ContentUploader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -815,7 +815,7 @@ class ContentUploader extends Component<ContentUploaderProps, State> {
* @return {void}
*/
uploadFile(item: UploadItem) {
const { overwrite, rootFolderId } = this.props;
const { enableModernizedUploads, overwrite, rootFolderId } = this.props;
const { api, file, options } = item;

const numItemsUploading = this.itemsRef.current.filter(item_t => item_t.status === STATUS_IN_PROGRESS).length;
Expand All @@ -831,6 +831,7 @@ class ContentUploader extends Component<ContentUploaderProps, State> {
progressCallback: event => this.handleUploadProgress(item, event),
successCallback: entries => this.handleUploadSuccess(item, entries),
overwrite,
enableModernizedUploads,
fileId: options && options.fileId ? options.fileId : null,
};

Expand All @@ -850,7 +851,7 @@ class ContentUploader extends Component<ContentUploaderProps, State> {
* @return {void}
*/
resumeFile(item: UploadItem) {
const { onResume, overwrite, rootFolderId } = this.props;
const { enableModernizedUploads, onResume, overwrite, rootFolderId } = this.props;
const { api, file, options } = item;

const numItemsUploading = this.itemsRef.current.filter(item_t => item_t.status === STATUS_IN_PROGRESS).length;
Expand All @@ -866,6 +867,7 @@ class ContentUploader extends Component<ContentUploaderProps, State> {
progressCallback: event => this.handleUploadProgress(item, event),
successCallback: entries => this.handleUploadSuccess(item, entries),
overwrite,
enableModernizedUploads,
sessionId: api && api.sessionId ? api.sessionId : null,
fileId: options && options.fileId ? options.fileId : null,
};
Expand Down
23 changes: 23 additions & 0 deletions src/utils/fields.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
FIELD_PERMISSIONS,
FIELD_ITEM_COLLECTION,
FIELD_ITEM_EXPIRATION,
FIELD_ITEM_STATUS,
FIELD_PATH_COLLECTION,
FIELD_CONTENT_CREATED_AT,
FIELD_CONTENT_MODIFIED_AT,
Expand All @@ -30,6 +31,7 @@ import {
FIELD_OWNED_BY,
FIELD_PROMOTED_BY,
FIELD_RESTORED_BY,
FIELD_PURGED_AT,
FIELD_TRASHED_BY,
FIELD_DESCRIPTION,
FIELD_REPRESENTATIONS,
Expand Down Expand Up @@ -222,6 +224,26 @@ const APP_ACTIVITY_FIELDS_TO_FETCH = [
FIELD_RENDERED_TEXT,
];

const STANDARD_UPLOAD_FIELDS = [
FIELD_DESCRIPTION,
FIELD_SIZE,
FIELD_PATH_COLLECTION,
FIELD_CREATED_AT,
FIELD_MODIFIED_AT,
FIELD_TRASHED_AT,
FIELD_PURGED_AT,
FIELD_CONTENT_CREATED_AT,
FIELD_CONTENT_MODIFIED_AT,
FIELD_CREATED_BY,
FIELD_MODIFIED_BY,
FIELD_OWNED_BY,
FIELD_SHARED_LINK,
FIELD_PARENT,
FIELD_ITEM_STATUS,
];

const STANDARD_UPLOAD_FIELDS_WITH_VERSION_NUMBER = [...STANDARD_UPLOAD_FIELDS, FIELD_VERSION_NUMBER];
Comment thread
tjuanitas marked this conversation as resolved.
Comment on lines +227 to +245
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

following the patterns in this file, I think have one array called UPLOAD_FIELDS_TO_FETCH which has the necessary fields necessary for your feature and then use this just in ContentUploader


/**
* Finds properties missing in an object
*
Expand Down Expand Up @@ -294,6 +316,7 @@ export {
PREVIEW_FIELDS_TO_FETCH,
SIDEBAR_FIELDS_TO_FETCH,
SIDEBAR_FIELDS_TO_FETCH_ARCHIVE,
STANDARD_UPLOAD_FIELDS_WITH_VERSION_NUMBER,
TASK_ASSIGNMENTS_FIELDS_TO_FETCH,
TASKS_FIELDS_TO_FETCH,
USER_FIELDS,
Expand Down
Loading