Skip to content

Commit

Permalink
@uppy/core: resolve some (breaking) TODOs (#4824)
Browse files Browse the repository at this point in the history
  • Loading branch information
aduh95 authored May 21, 2024
1 parent 8315c16 commit b9bd7a5
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 24 deletions.
16 changes: 8 additions & 8 deletions packages/@uppy/core/src/Uppy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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,
Expand Down
13 changes: 6 additions & 7 deletions packages/@uppy/core/src/Uppy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand Down Expand Up @@ -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 || '',
Expand All @@ -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,
}
}
Expand Down
8 changes: 4 additions & 4 deletions packages/@uppy/core/src/__snapshots__/Uppy.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down
3 changes: 1 addition & 2 deletions packages/@uppy/utils/src/FileProgress.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
5 changes: 2 additions & 3 deletions packages/@uppy/utils/src/getSpeed.ts
Original file line number Diff line number Diff line change
@@ -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
}

0 comments on commit b9bd7a5

Please sign in to comment.