From f47e542322b31d701efd9b63b171906e7ac58b37 Mon Sep 17 00:00:00 2001 From: Antoine du Hamel Date: Thu, 14 Dec 2023 19:56:21 +0100 Subject: [PATCH 1/2] @uppy/core: resolve some (breaking) TODOs --- packages/@uppy/core/src/Uppy.ts | 13 ++++++------- packages/@uppy/utils/src/FileProgress.ts | 3 +-- packages/@uppy/utils/src/getSpeed.ts | 5 ++--- 3 files changed, 9 insertions(+), 12 deletions(-) diff --git a/packages/@uppy/core/src/Uppy.ts b/packages/@uppy/core/src/Uppy.ts index 76fed05a45..a983640a9f 100644 --- a/packages/@uppy/core/src/Uppy.ts +++ b/packages/@uppy/core/src/Uppy.ts @@ -574,7 +574,7 @@ export class Uppy { resetProgress(): void { const defaultProgress: Omit = { percentage: 0, - bytesUploaded: 0, + bytesUploaded: false, uploadComplete: false, uploadStarted: null, } @@ -896,7 +896,8 @@ export class Uppy { meta.type = fileType // `null` means the size is unknown. - const size = Number.isFinite(file.data.size) ? file.data.size : null + const size = + Number.isFinite(file.data.size) ? file.data.size : (null as never) return { source: file.source || '', @@ -911,17 +912,15 @@ export class Uppy { data: file.data, progress: { percentage: 0, - bytesUploaded: 0, + bytesUploaded: false, bytesTotal: size, uploadComplete: false, uploadStarted: null, - } satisfies FileProgressNotStarted, + }, size, isGhost: false, isRemote: file.isRemote || false, - // TODO: this should not be a string - // @ts-expect-error wrong - remote: file.remote || '', + remote: file.remote, preview: file.preview, } } diff --git a/packages/@uppy/utils/src/FileProgress.ts b/packages/@uppy/utils/src/FileProgress.ts index d71f0731a8..3ddb96abe7 100644 --- a/packages/@uppy/utils/src/FileProgress.ts +++ b/packages/@uppy/utils/src/FileProgress.ts @@ -28,7 +28,6 @@ export type FileProgressStarted = FileProgressBase & { } export type FileProgressNotStarted = FileProgressBase & { uploadStarted: null - // TODO: remove `|0` (or maybe `false|`?) - bytesUploaded: false | 0 + bytesUploaded: false } export type FileProgress = FileProgressStarted | FileProgressNotStarted diff --git a/packages/@uppy/utils/src/getSpeed.ts b/packages/@uppy/utils/src/getSpeed.ts index 667f92ee62..9520f0f007 100644 --- a/packages/@uppy/utils/src/getSpeed.ts +++ b/packages/@uppy/utils/src/getSpeed.ts @@ -1,10 +1,9 @@ -import type { FileProgress, FileProgressStarted } from './FileProgress.js' +import type { FileProgress } from './FileProgress.js' export default function getSpeed(fileProgress: FileProgress): number { if (!fileProgress.bytesUploaded) return 0 - const timeElapsed = - Date.now() - (fileProgress as FileProgressStarted).uploadStarted + const timeElapsed = Date.now() - fileProgress.uploadStarted const uploadSpeed = fileProgress.bytesUploaded / (timeElapsed / 1000) return uploadSpeed } From 2f843adee1116b8239a9666edc0aa8ba1fb52f38 Mon Sep 17 00:00:00 2001 From: Antoine du Hamel Date: Fri, 29 Dec 2023 11:51:41 +0100 Subject: [PATCH 2/2] fix tests --- packages/@uppy/core/src/Uppy.test.ts | 16 ++++++++-------- .../core/src/__snapshots__/Uppy.test.ts.snap | 8 ++++---- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/packages/@uppy/core/src/Uppy.test.ts b/packages/@uppy/core/src/Uppy.test.ts index f126be11fc..8ba1c149f2 100644 --- a/packages/@uppy/core/src/Uppy.test.ts +++ b/packages/@uppy/core/src/Uppy.test.ts @@ -692,7 +692,7 @@ describe('src/Core', () => { }) expect(core.getFile(fileId).progress).toEqual({ percentage: 0, - bytesUploaded: 0, + bytesUploaded: false, bytesTotal: 17175, uploadComplete: false, uploadStarted: null, @@ -719,7 +719,7 @@ describe('src/Core', () => { }) expect(core.getFile(fileID).progress).toEqual({ percentage: 0, - bytesUploaded: 0, + bytesUploaded: false, bytesTotal: 17175, uploadComplete: false, uploadStarted: null, @@ -788,7 +788,7 @@ describe('src/Core', () => { }) expect(core.getFile(fileId).progress).toEqual({ percentage: 0, - bytesUploaded: 0, + bytesUploaded: false, bytesTotal: 17175, uploadComplete: false, uploadStarted: null, @@ -815,7 +815,7 @@ describe('src/Core', () => { }) expect(core.getFile(fileId).progress).toEqual({ percentage: 0, - bytesUploaded: 0, + bytesUploaded: false, bytesTotal: 17175, uploadComplete: false, uploadStarted: null, @@ -919,12 +919,12 @@ describe('src/Core', () => { isGhost: false, progress: { bytesTotal: 17175, - bytesUploaded: 0, + bytesUploaded: false, percentage: 0, uploadComplete: false, uploadStarted: null, }, - remote: '', + remote: undefined, size: 17175, source: 'vi', type: 'image/jpeg', @@ -1951,14 +1951,14 @@ describe('src/Core', () => { expect(core.getFile(file1.id).progress).toEqual({ percentage: 0, - bytesUploaded: 0, + bytesUploaded: false, bytesTotal: 17175, uploadComplete: false, uploadStarted: null, }) expect(core.getFile(file2.id).progress).toEqual({ percentage: 0, - bytesUploaded: 0, + bytesUploaded: false, bytesTotal: 17175, uploadComplete: false, uploadStarted: null, diff --git a/packages/@uppy/core/src/__snapshots__/Uppy.test.ts.snap b/packages/@uppy/core/src/__snapshots__/Uppy.test.ts.snap index b8215fae1f..c9094b96c7 100644 --- a/packages/@uppy/core/src/__snapshots__/Uppy.test.ts.snap +++ b/packages/@uppy/core/src/__snapshots__/Uppy.test.ts.snap @@ -29,12 +29,12 @@ exports[`src/Core > uploading a file > should only upload files that are not alr "preview": undefined, "progress": { "bytesTotal": null, - "bytesUploaded": 0, + "bytesUploaded": false, "percentage": 0, "uploadComplete": false, "uploadStarted": null, }, - "remote": "", + "remote": undefined, "size": null, "source": "vi", "type": "image/jpeg", @@ -53,12 +53,12 @@ exports[`src/Core > uploading a file > should only upload files that are not alr "preview": undefined, "progress": { "bytesTotal": null, - "bytesUploaded": 0, + "bytesUploaded": false, "percentage": 0, "uploadComplete": false, "uploadStarted": null, }, - "remote": "", + "remote": undefined, "size": null, "source": "vi", "type": "image/jpeg",