Skip to content

Commit

Permalink
fix(uploader): fallback for content_modified_at in ie11 and edge (#710)
Browse files Browse the repository at this point in the history
  • Loading branch information
DanDeMicco authored Dec 14, 2018
1 parent fa2e950 commit 0154737
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 22 deletions.
15 changes: 5 additions & 10 deletions flow-typed/box-ui-elements.js
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ type MetadataTemplateField = {
hidden?: boolean,
key: string,
type: string,
}
};

type MetadataEditorTemplate = {
id: string,
Expand Down Expand Up @@ -395,7 +395,7 @@ type FolderUploadItem = {
status: UploadStatus,
options?: UploadItemAPIOptions,
isFolder?: boolean,
}
};

type UploadItem = {
api: PlainUploadAPI | MultiputUploadAPI,
Expand Down Expand Up @@ -649,7 +649,7 @@ type UploadDataTransferItemWithAPIOptions = {
options?: UploadItemAPIOptions,
};

type UploadFile = File & { webkitRelativePath?: string };
type UploadFile = File & { webkitRelativePath?: string, lastModifiedDate?: Date };

type DirectoryReader = {
readEntries: (Function, Function) => void,
Expand Down Expand Up @@ -691,16 +691,11 @@ type ElementsError = {
};

type ErrorContextProps = {
onError: (
error: ElementsXhrError | Error,
code: string,
contextInfo?: Object,
origin: ErrorOrigins,
) => void,
onError: (error: ElementsXhrError | Error, code: string, contextInfo?: Object, origin: ErrorOrigins) => void,
};

type ElementsErrorCallback = (e: ElementsXhrError, code: string, contextInfo?: Object) => void;

type ClassificationInfo = {
Box__Security__Classification__Key?: string
Box__Security__Classification__Key?: string,
} & MetadataInstance;
17 changes: 11 additions & 6 deletions src/util/__tests__/uploads-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,17 @@ describe('util/uploads', () => {
// file with non-numeric lastModified (invalid Date)
// file no lastModified
test.each`
file | expectedResult
${{ lastModified: 1483326245678 }} | ${'2017-01-02T03:04:05Z'}
${{ lastModified: 'not a number' }} | ${null}
${{ lastModified: new Date('2017-01-02T03:04:05.678Z') }} | ${'2017-01-02T03:04:05Z'}
${{ lastModified: new Date('not valid') }} | ${null}
${{}} | ${null}
file | expectedResult
${{ lastModified: 1483326245678 }} | ${'2017-01-02T03:04:05Z'}
${{ lastModified: 'not a number' }} | ${null}
${{ lastModified: new Date('2017-01-02T03:04:05.678Z') }} | ${'2017-01-02T03:04:05Z'}
${{ lastModified: new Date('not valid') }} | ${null}
${{}} | ${null}
${{ lastModifiedDate: 1483326245678 }} | ${'2017-01-02T03:04:05Z'}
${{ lastModifiedDate: 'not a number' }} | ${null}
${{ lastModifiedDate: new Date('2017-01-02T03:04:05.678Z') }} | ${'2017-01-02T03:04:05Z'}
${{ lastModifiedDate: new Date('not valid') }} | ${null}
${{}} | ${null}
`(
'should return the properly formatted date when possible and return null otherwise',
({ file, expectedResult }) => {
Expand Down
12 changes: 6 additions & 6 deletions src/util/uploads.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,14 +120,14 @@ function toISOStringNoMS(date: Date): string {
* @return {?string}
*/
function getFileLastModifiedAsISONoMSIfPossible(file: UploadFile): ?string {
// The compatibility chart at https://developer.mozilla.org/en-US/docs/Web/API/File/lastModified#Browser_compatibility
// is not up to date as of 12-13-2018. Edge & ie11 do not support lastModified, but support lastModifiedDate.
const lastModified = file.lastModified || file.lastModifiedDate;
if (
// $FlowFixMe https://github.com/facebook/flow/issues/6131
file.lastModified &&
(typeof file.lastModified === 'string' ||
typeof file.lastModified === 'number' ||
file.lastModified instanceof Date)
lastModified &&
(typeof lastModified === 'string' || typeof lastModified === 'number' || lastModified instanceof Date)
) {
const lastModifiedDate = new Date(file.lastModified);
const lastModifiedDate = new Date(lastModified);
if (isValidDateObject(lastModifiedDate)) {
return toISOStringNoMS(lastModifiedDate);
}
Expand Down

0 comments on commit 0154737

Please sign in to comment.