{"version":3,"file":"Uploader.mjs","sources":["../../../lib/upload/uploader/Uploader.ts"],"sourcesContent":["/*!\n * SPDX-FileCopyrightText: 2022 Nextcloud GmbH and Nextcloud contributors\n * SPDX-License-Identifier: AGPL-3.0-or-later\n */\n\nimport type { IFolder } from '../../node/folder.ts'\nimport type { IUpload } from './Upload.ts'\nimport type { ConflictsCallback } from './UploadFileTree.ts'\n\nimport { getCurrentUser } from '@nextcloud/auth'\nimport PQueue from 'p-queue'\nimport { TypedEventTarget } from 'typescript-event-target'\nimport { defaultRemoteURL, defaultRootPath } from '../../dav/dav.ts'\nimport { FileType, Folder } from '../../node/index.ts'\nimport { Permission } from '../../permissions.ts'\nimport logger from '../../utils/logger.ts'\nimport { getMaxChunksSize, getMaxParallelUploads } from '../utils/config.ts'\nimport { Directory } from '../utils/fileTree.ts'\nimport { Eta } from './Eta.ts'\nimport { UploadStatus } from './Upload.ts'\nimport { UploadFile } from './UploadFile.ts'\nimport { UploadFileTree } from './UploadFileTree.ts'\n\nexport const UploaderStatus = Object.freeze({\n\tIDLE: 0,\n\tUPLOADING: 1,\n\tPAUSED: 2,\n})\n\ntype TUploaderStatus = typeof UploaderStatus[keyof typeof UploaderStatus]\n\nexport interface IUploaderStatistics {\n\t/**\n\t * Estimated time in seconds. If the time is not yet estimated, it will return `Infinity`.\n\t */\n\teta: number\n\t/**\n\t * The progress in percentage (0-100) done.\n\t */\n\tprogress: number\n\t/**\n\t * Transfer speed in bytes per second. Returns `-1` if not yet estimated.\n\t */\n\tspeed: number\n\t/**\n\t * Get the speed in human readable format using file sizes like 10KB/s. Returns the empty string if not yet estimated.\n\t */\n\tspeedReadable: string\n}\n\ninterface BaseOptions {\n\t/**\n\t * Abort signal to cancel the upload\n\t */\n\tsignal?: AbortSignal\n}\n\ninterface UploadOptions extends BaseOptions {\n\t/**\n\t * The root folder where to upload, as an absolute WebDAV source URL.\n\t * Allows to override the current destination of the uploader for this upload,\n\t * without changing the destination for any other upload.\n\t */\n\troot?: string\n\n\t/**\n\t * Number of retries for the upload\n\t *\n\t * @default 5\n\t */\n\tretries?: number\n}\n\ninterface BatchUploadOptions extends UploadOptions {\n\tcallback?: ConflictsCallback\n}\n\ninterface UploaderEventsMap {\n\t/**\n\t * Dispatched when the uploader is paused\n\t */\n\tpaused: CustomEvent\n\t/**\n\t * Dispatched when the uploader is resumed\n\t */\n\tresumed: CustomEvent\n\t/**\n\t * Dispatched when the uploader has finished all uploads (successfully, failed or cancelled)\n\t */\n\tfinished: CustomEvent\n\t/**\n\t * Dispatched when the uploader has been reset\n\t */\n\treset: CustomEvent\n\n\t/**\n\t * Dispatched when a new upload has been started.\n\t */\n\tuploadStarted: CustomEvent<IUpload>\n\t/**\n\t * Dispatched when an upload has made progress (e.g. a chunk has been uploaded).\n\t */\n\tuploadProgress: CustomEvent<IUpload>\n\t/**\n\t * Dispatched when an upload has finished (successfully, failed or cancelled).\n\t */\n\tuploadFinished: CustomEvent<IUpload>\n}\n\nexport class Uploader extends TypedEventTarget<UploaderEventsMap> {\n\t#eta = new Eta()\n\t#destinationFolder: IFolder\n\t#customHeaders: Map<string, string> = new Map()\n\t#uploadQueue: IUpload[] = []\n\t#jobQueue: PQueue = new PQueue({\n\t\tconcurrency: getMaxParallelUploads(),\n\t})\n\n\t/**\n\t * Initialize uploader\n\t *\n\t * @param isPublic are we in public mode ?\n\t * @param destinationFolder the context folder to operate, relative to the root folder\n\t */\n\tconstructor(\n\t\tisPublic = false,\n\t\tdestinationFolder?: IFolder,\n\t) {\n\t\tsuper()\n\t\tif (!destinationFolder) {\n\t\t\tconst source = `${defaultRemoteURL}${defaultRootPath}`\n\t\t\tlet owner: string\n\n\t\t\tif (isPublic) {\n\t\t\t\towner = 'anonymous'\n\t\t\t} else {\n\t\t\t\tconst user = getCurrentUser()?.uid\n\t\t\t\tif (!user) {\n\t\t\t\t\tthrow new Error('User is not logged in')\n\t\t\t\t}\n\t\t\t\towner = user\n\t\t\t}\n\n\t\t\tdestinationFolder = new Folder({\n\t\t\t\tid: 0,\n\t\t\t\towner,\n\t\t\t\tpermissions: Permission.ALL,\n\t\t\t\troot: defaultRootPath,\n\t\t\t\tsource,\n\t\t\t})\n\t\t}\n\t\tthis.#destinationFolder = destinationFolder\n\n\t\tlogger.debug('Upload workspace initialized', {\n\t\t\troot: this.#destinationFolder.source,\n\t\t\tisPublic,\n\t\t\tmaxChunksSize: getMaxChunksSize(),\n\t\t})\n\t}\n\n\tpublic get status(): TUploaderStatus {\n\t\tif (this.#jobQueue.isPaused) {\n\t\t\treturn UploaderStatus.PAUSED\n\t\t}\n\t\tif (this.#jobQueue.pending > 0 || this.#jobQueue.size > 0) {\n\t\t\treturn UploaderStatus.UPLOADING\n\t\t}\n\t\treturn UploaderStatus.IDLE\n\t}\n\n\t/**\n\t * Get the upload destination folder\n\t */\n\tpublic get destination(): IFolder {\n\t\treturn this.#destinationFolder\n\t}\n\n\t/**\n\t * Set the upload destination path relative to the root folder\n\t */\n\tpublic set destination(folder: IFolder) {\n\t\tif (!folder || folder.type !== FileType.Folder || !folder.source) {\n\t\t\tthrow new Error('Invalid destination folder')\n\t\t}\n\n\t\tlogger.debug('Destination set', { folder })\n\t\tthis.#destinationFolder = folder\n\t}\n\n\t/**\n\t * Get registered custom headers for uploads\n\t */\n\tpublic get customHeaders(): Map<string, string> {\n\t\treturn structuredClone(this.#customHeaders)\n\t}\n\n\t/**\n\t * Set a custom header\n\t *\n\t * @param name The header to set\n\t * @param value The string value\n\t */\n\tpublic setCustomHeader(name: string, value: string = ''): void {\n\t\tthis.#customHeaders.set(name, value)\n\t}\n\n\t/**\n\t * Unset a custom header\n\t *\n\t * @param name The header to unset\n\t */\n\tpublic deleteCustomerHeader(name: string): void {\n\t\tthis.#customHeaders.delete(name)\n\t}\n\n\t/**\n\t * Get the upload queue\n\t */\n\tpublic get queue(): IUpload[] {\n\t\treturn [...this.#uploadQueue]\n\t}\n\n\t/**\n\t * Get current statistics of the uploader.\n\t */\n\tpublic get statistics(): IUploaderStatistics {\n\t\treturn {\n\t\t\teta: this.#eta.time,\n\t\t\tprogress: this.#eta.progress,\n\t\t\tspeed: this.#eta.speed,\n\t\t\tspeedReadable: this.#eta.speedReadable,\n\t\t}\n\t}\n\n\t/**\n\t * Pause the uploader.\n\t * Already started uploads will continue, but all other (not yet started) uploads\n\t * will be paused until `start()` is called.\n\t */\n\tpublic async pause() {\n\t\tthis.#jobQueue.pause()\n\t\tthis.#eta.pause()\n\t\tawait this.#jobQueue.onPendingZero()\n\t\tthis.dispatchTypedEvent('paused', new CustomEvent('paused'))\n\t\tlogger.debug('Uploader paused')\n\t}\n\n\t/**\n\t * Resume any pending upload(s)\n\t */\n\tpublic start() {\n\t\tthis.#jobQueue.start()\n\t\tthis.#eta.resume()\n\t\tthis.dispatchTypedEvent('resumed', new CustomEvent('resumed'))\n\t\tlogger.debug('Uploader resumed')\n\t}\n\n\tpublic reset() {\n\t\tfor (const upload of this.#uploadQueue) {\n\t\t\tif (upload.status !== UploadStatus.FINISHED && upload.status !== UploadStatus.FAILED) {\n\t\t\t\tupload.cancel()\n\t\t\t}\n\t\t}\n\n\t\tthis.#uploadQueue = []\n\t\tthis.#jobQueue.clear()\n\t\t// Resume the (now empty) job queue so a reset always returns to the IDLE\n\t\t// state — otherwise a reset while paused would leave the uploader stuck\n\t\t// reporting PAUSED and block any subsequent upload.\n\t\tthis.#jobQueue.start()\n\t\tthis.#eta.reset()\n\t\tthis.dispatchTypedEvent('reset', new CustomEvent('reset'))\n\t\tlogger.debug('Uploader reset')\n\t}\n\n\t/**\n\t * Uploads multiple files or folders while preserving the relative path (if available)\n\t *\n\t * @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\")\n\t * @param files The files and/or folders to upload\n\t * @param options - optional parameters\n\t * @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)\n\t * @throws {UploadCancelledError} - If the upload was canceled by the user via the abort signal\n\t *\n\t * @example\n\t * ```ts\n\t * // For example this is from handling the onchange event of an input[type=file]\n\t * async handleFiles(files: File[]) {\n\t *   this.uploads = await this.uploader.batchUpload('uploads', files, { callback: this.handleConflicts })\n\t * }\n\t *\n\t * async handleConflicts(nodes: File[], currentPath: string) {\n\t *   const conflicts = getConflicts(nodes, this.fetchContent(currentPath))\n\t *   if (conflicts.length === 0) {\n\t *     // No conflicts so upload all\n\t *     return nodes\n\t *   } else {\n\t *     // Open the conflict picker to resolve conflicts\n\t *     try {\n\t *       const { selected, renamed } = await openConflictPicker(currentPath, conflicts, this.fetchContent(currentPath), { recursive: true })\n\t *       return [...selected, ...renamed]\n\t *     } catch (e) {\n\t *       return false\n\t *     }\n\t *   }\n\t * }\n\t * ```\n\t */\n\tpublic async batchUpload(\n\t\tdestination: string,\n\t\tfiles: (File | FileSystemEntry)[],\n\t\toptions?: BatchUploadOptions,\n\t): Promise<IUpload[]> {\n\t\tconst rootFolder = new Directory('')\n\t\tawait rootFolder.addChildren(files)\n\t\t// create a meta upload to ensure all ongoing child requests are listed\n\t\tconst target = this.#resolveTarget(destination, options?.root)\n\t\tconst headers = Object.fromEntries(this.#customHeaders.entries())\n\t\tconst _callback = options?.callback\n\t\t// The callback is adjusted to be called with the path relative to the upload target\n\t\t// instead of the full absolute URL.\n\t\tconst callback = _callback && ((nodes: string[], path: string) => _callback(nodes, path.substring(target.length).replace(/^\\//, '')))\n\t\tconst upload = new UploadFileTree(\n\t\t\ttarget,\n\t\t\trootFolder,\n\t\t\t{ ...options, callback, headers },\n\t\t)\n\t\tif (options?.signal) {\n\t\t\tthis.#attachAbortSignal(options.signal, upload)\n\t\t}\n\n\t\tconst uploads = [...upload.initialize(), upload]\n\t\tfor (const upload of uploads) {\n\t\t\tthis.#attachEventListeners(upload)\n\t\t}\n\t\tthis.#uploadQueue.push(...uploads)\n\t\tthis.#startTracking()\n\t\tthis.dispatchTypedEvent('uploadStarted', new CustomEvent('uploadStarted', { detail: upload }))\n\t\tawait upload.start(this.#jobQueue)\n\t\treturn uploads\n\t}\n\n\t/**\n\t * Upload a file to the given path\n\t *\n\t * @param destination - The destination path relative to the root folder. e.g. /foo/bar.txt\n\t * @param fileHandle - The file to upload\n\t * @param options - Optional parameters\n\t */\n\tpublic async upload(destination: string, fileHandle: File | FileSystemFileEntry, options?: UploadOptions): Promise<IUpload> {\n\t\tconst target = this.#resolveTarget(destination, options?.root)\n\t\tconst headers = Object.fromEntries(this.#customHeaders.entries())\n\t\tconst upload = new UploadFile(target, fileHandle, { ...options, headers })\n\t\tif (options?.signal) {\n\t\t\tthis.#attachAbortSignal(options.signal, upload)\n\t\t}\n\n\t\tthis.#attachEventListeners(upload)\n\t\tthis.#uploadQueue.push(upload)\n\t\tthis.#startTracking()\n\t\tthis.dispatchTypedEvent('uploadStarted', new CustomEvent('uploadStarted', { detail: upload }))\n\t\tawait upload.start(this.#jobQueue)\n\t\treturn upload\n\t}\n\n\t/**\n\t * Cancel the upload when the caller provided abort signal is aborted.\n\t *\n\t * @param signal - The abort signal provided by the caller\n\t * @param upload - The upload to cancel when the signal is aborted\n\t */\n\t#attachAbortSignal(signal: AbortSignal, upload: IUpload): void {\n\t\tif (signal.aborted) {\n\t\t\tupload.cancel()\n\t\t\treturn\n\t\t}\n\t\tsignal.addEventListener('abort', () => upload.cancel(), { once: true })\n\t}\n\n\t/**\n\t * Resolve the absolute upload target for a destination relative to the root folder.\n\t *\n\t * @param destination - The destination path relative to the root folder\n\t * @param root - Optional root to use instead of the current uploader destination\n\t */\n\t#resolveTarget(destination: string, root?: string): string {\n\t\tconst base = root ?? this.#destinationFolder.source\n\t\treturn `${base.replace(/\\/$/, '')}/${destination.replace(/^\\//, '')}`\n\t}\n\n\t/**\n\t * Start the statistics tracking for a newly queued upload.\n\t * The ETA is only resumed when the uploader is not paused,\n\t * so that uploads added while paused do not skew the speed estimation.\n\t */\n\t#startTracking() {\n\t\tif (this.status !== UploaderStatus.PAUSED) {\n\t\t\tthis.#eta.resume()\n\t\t}\n\t}\n\n\t/**\n\t * Handle the progress event of an upload.\n\t * Update the ETA and dispatch a progress event for the uploader.\n\t *\n\t * @param event - The progress event of an upload\n\t */\n\t#onProgress(event: CustomEvent<IUpload>) {\n\t\tconst totalBytes = this.#uploadQueue.reduce((acc, upload) => acc + upload.totalBytes, 0)\n\t\tconst uploadedBytes = this.#uploadQueue.reduce((acc, upload) => acc + upload.uploadedBytes, 0)\n\t\tthis.#eta.update(uploadedBytes, totalBytes)\n\t\tthis.dispatchTypedEvent('uploadProgress', new CustomEvent('uploadProgress', { detail: event.detail }))\n\t}\n\n\t/**\n\t * Handle the finished event of an upload.\n\t *\n\t * 1. Update the progress\n\t * 2. if all uploads are finished dispatch a finished event for the uploader and clear the queue\n\t *\n\t * @param event - The finished event of an upload\n\t */\n\tasync #onFinished(event: CustomEvent<IUpload>) {\n\t\tthis.#onProgress(event)\n\t\tthis.dispatchTypedEvent('uploadFinished', new CustomEvent('uploadFinished', { detail: event.detail }))\n\n\t\tconst finalStates = [\n\t\t\tUploadStatus.FINISHED,\n\t\t\tUploadStatus.CANCELLED,\n\t\t\tUploadStatus.FAILED,\n\t\t] as number[]\n\t\tif (this.#uploadQueue.every((upload) => finalStates.includes(upload.status))) {\n\t\t\tawait this.#jobQueue.onIdle()\n\t\t\tthis.dispatchTypedEvent('finished', new CustomEvent('finished'))\n\t\t\tthis.reset()\n\t\t}\n\t}\n\n\t/**\n\t * Attach progress listeners to an upload.\n\t *\n\t * @param upload - The upload to attach listeners to\n\t */\n\t#attachEventListeners(upload: IUpload) {\n\t\tupload.addEventListener('progress', this.#onProgress.bind(this))\n\t\tupload.addEventListener('finished', this.#onFinished.bind(this))\n\t}\n}\n"],"names":["upload"],"mappings":";;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAuBO,MAAM,iBAAiB,OAAO,OAAO;AAAA,EAC3C,MAAM;AAAA,EACN,WAAW;AAAA,EACX,QAAQ;AACT,CAAC;AAkFM,MAAM,iBAAiB,iB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