Преглед изворни кода

@uppy/core: resolve some (breaking) TODOs (#4824)

Antoine du Hamel пре 11 месеци
родитељ
комит
b9bd7a5b19

+ 8 - 8
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,

+ 6 - 7
packages/@uppy/core/src/Uppy.ts

@@ -574,7 +574,7 @@ export class Uppy<M extends Meta, B extends Body> {
   resetProgress(): void {
     const defaultProgress: Omit<FileProgressNotStarted, 'bytesTotal'> = {
       percentage: 0,
-      bytesUploaded: 0,
+      bytesUploaded: false,
       uploadComplete: false,
       uploadStarted: null,
     }
@@ -896,7 +896,8 @@ export class Uppy<M extends Meta, B extends Body> {
     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<M extends Meta, B extends Body> {
       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,
     }
   }

+ 4 - 4
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",

+ 1 - 2
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

+ 2 - 3
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
 }