import { IFolder } from '../../node/folder.ts'; import { IUpload } from './Upload.ts'; import { ConflictsCallback } from './UploadFileTree.ts'; import { TypedEventTarget } from 'typescript-event-target'; export declare const UploaderStatus: Readonly<{ IDLE: 0; UPLOADING: 1; PAUSED: 2; }>; type TUploaderStatus = typeof UploaderStatus[keyof typeof UploaderStatus]; export interface IUploaderStatistics { /** * Estimated time in seconds. If the time is not yet estimated, it will return `Infinity`. */ eta: number; /** * The progress in percentage (0-100) done. */ progress: number; /** * Transfer speed in bytes per second. Returns `-1` if not yet estimated. */ speed: number; /** * Get the speed in human readable format using file sizes like 10KB/s. Returns the empty string if not yet estimated. */ speedReadable: string; } interface BaseOptions { /** * Abort signal to cancel the upload */ signal?: AbortSignal; } interface UploadOptions extends BaseOptions { /** * The root folder where to upload, as an absolute WebDAV source URL. * Allows to override the current destination of the uploader for this upload, * without changing the destination for any other upload. */ root?: string; /** * Number of retries for the upload * * @default 5 */ retries?: number; } interface BatchUploadOptions extends UploadOptions { callback?: ConflictsCallback; } interface UploaderEventsMap { /** * Dispatched when the uploader is paused */ paused: CustomEvent; /** * Dispatched when the uploader is resumed */ resumed: CustomEvent; /** * Dispatched when the uploader has finished all uploads (successfully, failed or cancelled) */ finished: CustomEvent; /** * Dispatched when the uploader has been reset */ reset: CustomEvent; /** * Dispatched when a new upload has been started. */ uploadStarted: CustomEvent; /** * Dispatched when an upload has made progress (e.g. a chunk has been uploaded). */ uploadProgress: CustomEvent; /** * Dispatched when an upload has finished (successfully, failed or cancelled). */ uploadFinished: CustomEvent; } export declare class Uploader extends TypedEventTarget { #private; /** * Initialize uploader * * @param isPublic are we in public mode ? * @param destinationFolder the context folder to operate, relative to the root folder */ constructor(isPublic?: boolean, destinationFolder?: IFolder); get status(): TUploaderStatus; /** * Get the upload destination folder */ get destination(): IFolder; /** * Set the upload destination path relative to the root folder */ set destination(folder: IFolder); /** * Get registered custom headers for uploads */ get customHeaders(): Map; /** * Set a custom header * * @param name The header to set * @param value The string value */ setCustomHeader(name: string, value?: string): void; /** * Unset a custom header * * @param name The header to unset */ deleteCustomerHeader(name: string): void; /** * Get the upload queue */ get queue(): IUpload[]; /** * Get current statistics of the uploader. */ get statistics(): IUploaderStatistics; /** * Pause the uploader. * Already started uploads will continue, but all other (not yet started) uploads * will be paused until `start()` is called. */ pause(): Promise; /** * Resume any pending upload(s) */ start(): void; reset(): void; /** * Uploads multiple files or folders while preserving the relative path (if available) * * @param destination The destination path relative to the root folder. e.g. /foo/bar (a file "a.txt" will be uploaded then to "/foo/bar/a.txt") * @param files The files and/or folders to upload * @param options - optional parameters * @param options.callback Callback that receives the nodes in the current folder and the current path to allow resolving conflicts, all nodes that are returned will be uploaded (if a folder does not exist it will be created) * @throws {UploadCancelledError} - If the upload was canceled by the user via the abort signal * * @example * ```ts * // For example this is from handling the onchange event of an input[type=file] * async handleFiles(files: File[]) { * this.uploads = await this.uploader.batchUpload('uploads', files, { callback: this.handleConflicts }) * } * * async handleConflicts(nodes: File[], currentPath: string) { * const conflicts = getConflicts(nodes, this.fetchContent(currentPath)) * if (conflicts.length === 0) { * // No conflicts so upload all * return nodes * } else { * // Open the conflict picker to resolve conflicts * try { * const { selected, renamed } = await openConflictPicker(currentPath, conflicts, this.fetchContent(currentPath), { recursive: true }) * return [...selected, ...renamed] * } catch (e) { * return false * } * } * } * ``` */ batchUpload(destination: string, files: (File | FileSystemEntry)[], options?: BatchUploadOptions): Promise; /** * Upload a file to the given path * * @param destination - The destination path relative to the root folder. e.g. /foo/bar.txt * @param fileHandle - The file to upload * @param options - Optional parameters */ upload(destination: string, fileHandle: File | FileSystemFileEntry, options?: UploadOptions): Promise; } export {};