UNPKG

tus-js-client-stall-detection

Version:

A pure JavaScript client for the tus resumable upload protocol (fork with stall detection)

61 lines (54 loc) 1.98 kB
import { DetailedError } from '../DetailedError.js' import { NoopUrlStorage } from '../NoopUrlStorage.js' import { enableDebugLog } from '../logger.js' import type { UploadInput, UploadOptions } from '../options.js' import { BaseUpload, defaultOptions as baseDefaultOptions, terminate } from '../upload.js' import { canStoreURLs } from './FileUrlStorage.js' import { NodeFileReader } from './NodeFileReader.js' import { NodeHttpStack as DefaultHttpStack } from './NodeHttpStack.js' import { fingerprint } from './fileSignature.js' const defaultOptions = { ...baseDefaultOptions, httpStack: new DefaultHttpStack(), fileReader: new NodeFileReader(), urlStorage: new NoopUrlStorage(), fingerprint, } class Upload extends BaseUpload { constructor(file: UploadInput, options: Partial<UploadOptions> = {}) { const allOpts = { ...defaultOptions, ...options, // Deep merge stallDetection options if provided ...(options.stallDetection && { stallDetection: { ...defaultOptions.stallDetection, ...options.stallDetection, }, }), } super(file, allOpts) } static terminate(url: string, options: Partial<UploadOptions> = {}) { const allOpts = { ...defaultOptions, ...options, // Deep merge stallDetection options if provided ...(options.stallDetection && { stallDetection: { ...defaultOptions.stallDetection, ...options.stallDetection, }, }), } return terminate(url, allOpts) } } // The Node.js environment does not have restrictions which may cause // tus-js-client not to function. const isSupported = true // Note: The exported interface must be the same as in lib/browser/index.ts. // Any changes should be reflected in both files. export { Upload, defaultOptions, isSupported, canStoreURLs, enableDebugLog, DetailedError } export { NodeHttpStack } from './NodeHttpStack.js' export type * from '../options.js'