uppy/packages/@uppy/utils/src/emitSocketProgress.ts
Murderlon c48aa82a8a
@uppy/core: refactor to TS
Co-authored-by: Antoine du Hamel <antoine@transloadit.com>
2023-12-14 19:39:43 +01:00

24 lines
594 B
TypeScript

import throttle from 'lodash/throttle.js'
import type { UppyFile } from './UppyFile'
import type { FileProgress } from './FileProgress'
function emitSocketProgress(
uploader: any,
progressData: FileProgress,
file: UppyFile<any, any>,
): void {
const { progress, bytesUploaded, bytesTotal } = progressData
if (progress) {
uploader.uppy.log(`Upload progress: ${progress}`)
uploader.uppy.emit('upload-progress', file, {
uploader,
bytesUploaded,
bytesTotal,
})
}
}
export default throttle(emitSocketProgress, 300, {
leading: true,
trailing: true,
})