mirror of
https://github.com/transloadit/uppy.git
synced 2026-07-17 16:50:22 +00:00
Supersedes #6178. This branch keeps the exact same final content as #6178, but splits history for reviewability: 1. `chore(companion): rename source and test files from .js to .ts` (pure `git mv`, no content changes) 2. `feat(companion): port Companion to TypeScript` (actual content/type/schema/build updates) Validation note: - Final tree is byte-for-byte identical to `ts-companion` (`7b5b16a298690b0492de4cc4fab744f998b45570`). --------- Co-authored-by: Mikael Finstad <finstaden@gmail.com>
42 lines
882 B
TypeScript
42 lines
882 B
TypeScript
type UploadOptions = {
|
|
uploadSize: number
|
|
onProgress: (bytesUploaded: number, bytesTotal: number) => void
|
|
onSuccess: () => void
|
|
} & Record<string, unknown>
|
|
|
|
let lastUploadFile: unknown
|
|
|
|
export function __getLastUploadFile(): unknown {
|
|
return lastUploadFile
|
|
}
|
|
|
|
export function __resetTusMockState(): void {
|
|
lastUploadFile = undefined
|
|
}
|
|
|
|
export class Upload {
|
|
url: string
|
|
|
|
options: UploadOptions
|
|
|
|
constructor(file: unknown, options: UploadOptions) {
|
|
lastUploadFile = file
|
|
this.url = 'https://tus.endpoint/files/foo-bar'
|
|
this.options = options
|
|
}
|
|
|
|
_triggerProgressThenSuccess() {
|
|
this.options.onProgress(this.options.uploadSize, this.options.uploadSize)
|
|
setTimeout(() => this.options.onSuccess(), 100)
|
|
}
|
|
|
|
start() {
|
|
setTimeout(this._triggerProgressThenSuccess.bind(this), 100)
|
|
}
|
|
|
|
abort() {
|
|
// noop
|
|
}
|
|
}
|
|
|
|
export default { Upload }
|