Skip to content

Commit

Permalink
@uppy/core: resolve some (breaking) TODOs
Browse files Browse the repository at this point in the history
  • Loading branch information
aduh95 committed Dec 14, 2023
1 parent 35314b6 commit 6b94498
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 13 deletions.
14 changes: 7 additions & 7 deletions packages/@uppy/core/src/Uppy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,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 @@ -842,7 +842,9 @@ 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 @@ -857,17 +859,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,
} as 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
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const renderFileName = (props) => {

const renderAuthor = (props) => {
const { author } = props.file.meta
const { providerName } = props.file.remote
const providerName = props.file.remote?.providerName
const dot = `\u00B7`

if (!author) {
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 @@ -16,7 +16,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'
import type { FileProgress } from './FileProgress'

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 6b94498

Please sign in to comment.