@wlindabla/file_uploader 1.0.0 → 2.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +54 -28
- package/dist/cjs/cache/index.d.ts +198 -0
- package/dist/cjs/cache/index.js +318 -0
- package/dist/cjs/cache/index.js.map +1 -0
- package/dist/cjs/core/index.d.ts +271 -0
- package/dist/cjs/core/index.js +762 -0
- package/dist/cjs/core/index.js.map +1 -0
- package/dist/cjs/events/chunk/index.d.ts +27 -0
- package/dist/cjs/events/chunk/index.js +70 -0
- package/dist/cjs/events/chunk/index.js.map +1 -0
- package/dist/cjs/events/complete/index.d.ts +64 -0
- package/dist/cjs/events/complete/index.js +152 -0
- package/dist/cjs/events/complete/index.js.map +1 -0
- package/dist/cjs/events/index.d.ts +95 -0
- package/dist/cjs/events/index.js +85 -0
- package/dist/cjs/events/index.js.map +1 -0
- package/dist/cjs/events/initialize/index.d.ts +45 -0
- package/dist/cjs/events/initialize/index.js +105 -0
- package/dist/cjs/events/initialize/index.js.map +1 -0
- package/dist/cjs/events/state/index.d.ts +67 -0
- package/dist/cjs/events/state/index.js +145 -0
- package/dist/cjs/events/state/index.js.map +1 -0
- package/dist/cjs/exceptions/index.d.ts +84 -0
- package/dist/{exceptions → cjs/exceptions}/index.js +38 -18
- package/dist/cjs/exceptions/index.js.map +1 -0
- package/dist/cjs/index.d.ts +14 -0
- package/dist/cjs/index.js +33 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/subscribers/index.d.ts +34 -0
- package/dist/cjs/subscribers/index.js +187 -0
- package/dist/cjs/subscribers/index.js.map +1 -0
- package/dist/cjs/types/index.d.ts +110 -0
- package/dist/cjs/types/index.js +53 -0
- package/dist/cjs/types/index.js.map +1 -0
- package/dist/cjs/utils/index.d.ts +72 -0
- package/dist/cjs/utils/index.js +208 -0
- package/dist/cjs/utils/index.js.map +1 -0
- package/dist/esm/cache/index.d.mts +198 -0
- package/dist/esm/cache/index.js +4 -0
- package/dist/{index.js.map → esm/cache/index.js.map} +1 -1
- package/dist/{events/initialize/index.js → esm/chunk-3JTTZCSQ.js} +25 -19
- package/dist/esm/chunk-3JTTZCSQ.js.map +1 -0
- package/dist/{events/state/index.js → esm/chunk-6225YMFE.js} +38 -20
- package/dist/esm/chunk-6225YMFE.js.map +1 -0
- package/dist/esm/chunk-7QVYU63E.js +6 -0
- package/dist/esm/chunk-7QVYU63E.js.map +1 -0
- package/dist/{events/complete/index.js → esm/chunk-BNMI7DW3.js} +25 -19
- package/dist/esm/chunk-BNMI7DW3.js.map +1 -0
- package/dist/{subscribers/index.js → esm/chunk-HYNJBWW5.js} +36 -34
- package/dist/esm/chunk-HYNJBWW5.js.map +1 -0
- package/dist/{events/index.js → esm/chunk-JDL3U4OX.js} +7 -37
- package/dist/esm/chunk-JDL3U4OX.js.map +1 -0
- package/dist/{events/chunk/index.js → esm/chunk-LD2DWZRJ.js} +14 -11
- package/dist/esm/chunk-LD2DWZRJ.js.map +1 -0
- package/dist/{utils/index.js → esm/chunk-MFYC4PBP.js} +15 -22
- package/dist/esm/chunk-MFYC4PBP.js.map +1 -0
- package/dist/esm/chunk-NXYS73I4.js +125 -0
- package/dist/esm/chunk-NXYS73I4.js.map +1 -0
- package/dist/{cache/index.js → esm/chunk-PFALORWQ.js} +10 -11
- package/dist/esm/chunk-PFALORWQ.js.map +1 -0
- package/dist/{core/index.js → esm/chunk-TONVXBLH.js} +239 -231
- package/dist/esm/chunk-TONVXBLH.js.map +1 -0
- package/dist/{types/index.js → esm/chunk-X757PBC5.js} +5 -7
- package/dist/esm/chunk-X757PBC5.js.map +1 -0
- package/dist/esm/core/index.d.mts +271 -0
- package/dist/esm/core/index.js +12 -0
- package/dist/esm/core/index.js.map +1 -0
- package/dist/esm/events/chunk/index.d.mts +27 -0
- package/dist/esm/events/chunk/index.js +4 -0
- package/dist/esm/events/chunk/index.js.map +1 -0
- package/dist/esm/events/complete/index.d.mts +64 -0
- package/dist/esm/events/complete/index.js +4 -0
- package/dist/esm/events/complete/index.js.map +1 -0
- package/dist/esm/events/index.d.mts +95 -0
- package/dist/esm/events/index.js +8 -0
- package/dist/esm/events/index.js.map +1 -0
- package/dist/esm/events/initialize/index.d.mts +45 -0
- package/dist/esm/events/initialize/index.js +4 -0
- package/dist/esm/events/initialize/index.js.map +1 -0
- package/dist/esm/events/state/index.d.mts +67 -0
- package/dist/esm/events/state/index.js +4 -0
- package/dist/esm/events/state/index.js.map +1 -0
- package/dist/esm/exceptions/index.d.mts +84 -0
- package/dist/esm/exceptions/index.js +4 -0
- package/dist/esm/exceptions/index.js.map +1 -0
- package/dist/esm/index.d.mts +14 -0
- package/dist/esm/index.js +14 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/subscribers/index.d.mts +34 -0
- package/dist/esm/subscribers/index.js +10 -0
- package/dist/esm/subscribers/index.js.map +1 -0
- package/dist/esm/types/index.d.mts +110 -0
- package/dist/esm/types/index.js +4 -0
- package/dist/esm/types/index.js.map +1 -0
- package/dist/esm/utils/index.d.mts +72 -0
- package/dist/esm/utils/index.js +5 -0
- package/dist/esm/utils/index.js.map +1 -0
- package/package.json +165 -14
- package/dist/cache/index.js.map +0 -1
- package/dist/core/index.js.map +0 -1
- package/dist/events/chunk/index.js.map +0 -1
- package/dist/events/complete/index.js.map +0 -1
- package/dist/events/index.js.map +0 -1
- package/dist/events/initialize/index.js.map +0 -1
- package/dist/events/state/index.js.map +0 -1
- package/dist/exceptions/index.js.map +0 -1
- package/dist/index.js +0 -49
- package/dist/subscribers/index.js.map +0 -1
- package/dist/types/index.js.map +0 -1
- package/dist/utils/index.js.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/core/index.ts"],"sourcesContent":["/*\n * This file is part of the project by AGBOKOUDJO Franck.\n *\n * (c) AGBOKOUDJO Franck <internationaleswebservices@gmail.com>\n * Phone: +229 0167 25 18 86\n * LinkedIn: https://www.linkedin.com/in/internationales-web-apps-services-120520193/\n * Company: INTERNATIONALES WEB APPS & SERVICES\n *\n * For more information, please feel free to contact the author.\n */\n\nimport {\n EventDispatcherInterface\n} from \"@wlindabla/event_dispatcher\";\n\nimport {\n FetchResponseInterface\n} from \"@wlindabla/http_client/contracts\";\n\nimport {\n safeFetch,\n HttpFetchError\n} from \"@wlindabla/http_client/core\";\n\nimport {\n ChunkError,\n ChunkInfo,\n ResumeData,\n UploadEndpoints,\n UploadOptions,\n UploadProgress,\n UploadResult,\n UploadState\n} from \"../types\";\n\nimport { UploadResumeCacheInterface } from \"../cache\";\nimport {\n FileUtils,\n createChunkFormData\n} from \"../utils\";\n\nimport {\n ChunkUploadHttpErrorResponseEvent,\n HttpFileUploaderEvents,\n InitializingUploadEvent,\n UploadCancelledEvent,\n UploadProgressEvent,\n UploadStateChangedEvent,\n UploadChunkStartedEvent,\n UploadPausedEvent,\n UploadResumedEvent,\n ResumeUploadEvent,\n FinalizeUploadEvent,\n UploadMediaCompleteEvent\n} from \"../events\";\n\nimport { ChunkUploadHttpErrorException, FileUploadChunkError } from \"../exceptions\";\n\nimport pLimit from 'p-limit';\n\n\n/**\n * ChunkedFileUploader\n *\n * A production-ready, event-driven chunked file upload engine for Browser and Node.js.\n *\n * Designed and developed by **AGBOKOUDJO Franck** at\n * **INTERNATIONALES WEB APPS & SERVICES**, this class provides a robust,\n * framework-agnostic solution for uploading large files to a remote server\n * by splitting them into smaller chunks and sending them in parallel with\n * configurable concurrency control.\n *\n * ---\n *\n * ### How It Works\n *\n * The upload process follows a strict three-phase lifecycle:\n *\n * 1. **Initialization** — A session is opened with the server via the `init` endpoint.\n * The file is identified by its name, size, type, and a SHA-256 hash of its\n * first megabyte. The server returns a unique `mediaId` that identifies the session.\n *\n * 2. **Chunk Upload** — The file is sliced into fixed-size chunks and uploaded\n * concurrently using `p-limit`. Each chunk carries its index, the total number\n * of chunks, and the session `mediaId`. Failed chunks are retried automatically\n * with exponential backoff up to `maxRetries` attempts.\n *\n * 3. **Finalization** — Once all chunks are successfully uploaded, the `finalize`\n * endpoint is called to instruct the server to assemble the chunks into the\n * final file.\n *\n * ---\n *\n * ### Event-Driven Architecture\n *\n * This class follows the **Symfony EventDispatcher pattern** via\n * `@wlindabla/event_dispatcher`. Every meaningful moment in the upload\n * lifecycle emits a typed event that your application can listen to:\n *\n * ```\n * IDLE → INITIALIZING → UPLOADING → FINALIZING → COMPLETED\n * ↓ ↓\n * FAILED PAUSED ↔ UPLOADING\n * ↓\n * CANCELLED\n * ```\n *\n * All event name constants are centralized in {@link HttpFileUploaderEvents}.\n *\n * ---\n *\n * ### Subscriber Registration (Required)\n *\n * Before calling `.upload()`, you **must** register the two built-in subscribers\n * on your dispatcher. They handle the HTTP communication for the init and finalize phases:\n *\n * ```typescript\n * // Browser\n * const dispatcher = new BrowserEventDispatcher(document);\n * dispatcher.addSubscriber(new InitializeUploadSubscriber(dispatcher));\n * dispatcher.addSubscriber(new FinalizeUploadSubscriber(dispatcher));\n *\n * // Node.js\n * const dispatcher = new NodeEventDispatcher();\n * dispatcher.addSubscriber(new InitializeUploadSubscriber(dispatcher));\n * dispatcher.addSubscriber(new FinalizeUploadSubscriber(dispatcher));\n * ```\n *\n * ---\n *\n * ### Fluent Builder API\n *\n * The class exposes a fluent API to configure the upload before starting:\n *\n * ```typescript\n * const uploader = new ChunkedFileUploader(dispatcher, cache, options);\n *\n * await uploader\n * .withFile(file)\n * .withEndpoints({\n * init: 'https://api.example.com/upload/init',\n * upload: 'https://api.example.com/upload/chunk',\n * finalize: 'https://api.example.com/upload/finalize'\n * })\n * .upload();\n * ```\n *\n * ---\n *\n * ### Resumable Uploads\n *\n * When `autoSave: true` is set in options, the upload progress is persisted\n * after each successful chunk via the {@link UploadResumeCacheInterface}.\n * A failed or interrupted upload can be resumed later:\n *\n * ```typescript\n * const resumeData = await uploader.loadResumeData(file.name);\n *\n * if (resumeData) {\n * await uploader\n * .withFile(file)\n * .withEndpoints(endpoints)\n * .resumeUpload(resumeData);\n * }\n * ```\n *\n * ---\n *\n * ### Concurrency\n *\n * Multiple chunks can be uploaded simultaneously. The `concurrency` option\n * controls how many parallel uploads are active at any given time.\n * The default value is `3`, which provides a good balance between speed\n * and server/network load:\n *\n * ```typescript\n * // Upload 5 chunks in parallel\n * new ChunkedFileUploader(dispatcher, cache, { concurrency: 5 });\n * ```\n *\n * ---\n *\n * ### Pause, Resume and Cancel\n *\n * The upload can be paused, resumed, or cancelled at any time:\n *\n * ```typescript\n * uploader.pause(); // Pauses after the current chunk finishes\n * uploader.resume(); // Resumes from where it was paused\n * uploader.cancel(); // Aborts immediately via AbortController\n * ```\n *\n * ---\n *\n * ### Cache\n *\n * The library does **not** provide a built-in cache implementation to stay\n * lightweight and environment-agnostic. You must implement\n * {@link UploadResumeCacheInterface} with your preferred storage backend\n * (localStorage, IndexedDB, Redis, filesystem, etc.).\n *\n * ---\n *\n * @author AGBOKOUDJO Franck <internationaleswebservices@gmail.com>\n * @company INTERNATIONALES WEB APPS & SERVICES\n * @phone +229 0167 25 18 86\n * @linkedin https://www.linkedin.com/in/internationales-web-apps-services-120520193/\n * @github https://github.com/Agbokoudjo/file_uploader\n *\n * @version 2.0.1\n * @since 1.0.0\n * @license MIT\n *\n * @see {@link HttpFileUploaderEvents} All event name constants\n * @see {@link UploadResumeCacheInterface} Cache interface to implement\n * @see {@link InitializeUploadSubscriber} Handles the init HTTP phase\n * @see {@link FinalizeUploadSubscriber} Handles the finalize HTTP phase\n * @see {@link UploadOptions} Full configuration reference\n * @see {@link https://github.com/Agbokoudjo/file_uploader | GitHub Repository}\n */\nexport class ChunkedFileUploader {\n private _file: File |null;\n private _endpoints: UploadEndpoints|null;\n \n private isPaused: boolean;\n private startTime: number;\n private uploadedBytes: number;\n private abortController: AbortController;\n private state: UploadState;\n private totalChunks: number;\n private percentage: number;\n private uploadedChunks: number;\n private lastUploadedChunkIndex: number; \n\n /**\n * @param _uploadEventDispatcher: new BrowserEventDispatcher(), //or new NodeJSEventDispatcher() if you have an environment NodeJs\n * @param uploadResumeData: UploadResumeCacheInterface\n * @param options: UploadOptions\n */\n public constructor(\n private readonly _uploadEventDispatcher: EventDispatcherInterface,\n private readonly uploadResumeData: UploadResumeCacheInterface,\n private options: UploadOptions\n ) {\n \n this._file = null;\n this._endpoints = null;\n this.isPaused = false;\n this.startTime = 0;\n this.uploadedBytes = 0;\n this.abortController = new AbortController();\n this.state = UploadState.IDLE;\n this.totalChunks = 0;\n this.percentage = 0;\n this.uploadedChunks = 0;\n this.lastUploadedChunkIndex = -1; \n }\n\n /**\n * Starts the chunked file upload process.\n * \n * @throws {Error} If file or endpoints are not set\n * @throws {InitializeUploadFailureException} If server initialization fails\n * @throws {FileUploadChunkError} If a chunk fails after all retries\n * \n * @example\n * ```typescript\n * const uploader = new ChunkedFileUploader(dispatcher, cache, options);\n * \n * uploader\n * .withFile(file)\n * .withEndpoints({ init, upload, finalize });\n * \n * await uploader.upload();\n * ```\n */\n public async upload(): Promise<void>{\n this.setState(UploadState.INITIALIZING);\n\n const { maxRetries = 3, config, speedMbps, metadata,\n headerInitialzingUpload, concurrency = 3\n } = this.options;\n\n let file: File;\n try {\n file = this.file;\n } catch (error) {\n throw error;\n }\n \n // Generate file hash for integrity check\n const fileHash = await FileUtils.generateFileHash(this.file); \n let fileId: string;\n try {\n const initializationEvent = await this._uploadEventDispatcher.dispatchAsync(\n new InitializingUploadEvent(\n {\n fileHash: fileHash,\n fileName: file.name,\n fileSize: file.size,\n fileType: file.type,\n metadata: metadata,\n endpointInit: this.endPointOptions.init,\n headers: headerInitialzingUpload\n }),\n HttpFileUploaderEvents.INITIALIZE_UPLOAD\n )\n\n fileId = initializationEvent.mediaId;\n } catch (error) {\n this.setState(UploadState.FAILED);\n throw error;\n }\n\n this.setState(UploadState.UPLOADING);\n this.startTime = Date.now();\n this.uploadedBytes = 0;\n this.uploadedChunks = 0;\n this.lastUploadedChunkIndex = -1;\n\n const chunkSize = this.options.chunkSize || FileUtils.calculateChunkSize(file.size, speedMbps, config);\n this.totalChunks = Math.ceil(file.size / chunkSize);\n try {\n await this.uploadChunksWithConcurrency(\n file,\n chunkSize,\n fileId,\n fileHash,\n maxRetries,\n concurrency,\n 0\n );\n\n await this.finalizeUpload(fileId, fileHash);\n \n } catch (error) {\n this.handleUploadFailure(error as Error);\n throw error;\n }\n }\n\n public withFile(file: File): this {\n if (!file) {\n throw new Error('File is required');\n }\n if (file.size === 0) {\n throw new Error('Cannot upload empty file');\n }\n if (!(file instanceof File) || !(file instanceof Blob)) {\n throw new TypeError('Expected File or Blob instance');\n }\n this._file = file;\n return this;\n }\n\n public withEndpoints(endpoints: UploadEndpoints): this {\n if (!endpoints.init || !endpoints.upload || !endpoints.finalize) {\n throw new Error('All endpoints (init, upload, finalize) are required');\n }\n this._endpoints = endpoints;\n return this;\n }\n\n private get endPointOptions():UploadEndpoints {\n if (!this._endpoints) {\n throw new Error('Endpoint URL is required');\n }\n\n return this._endpoints;\n }\n\n private get file(): File{ \n if (!this._file) {\n throw new Error(`\n This operation requires a mandatory file.Did you forget to upload the file? \n Use the withFile(file: File|Blob) function of the ChunkedFileUploader ${this} class that you instantiated.\n `)\n }\n\n return this._file;\n }\n\n /**\n * Upload all chunks with concurrency control using p-limit\n * \n * @param file - File to upload\n * @param chunkSize - Size of each chunk\n * @param fileId - Server file ID\n * @param fileHash - File hash\n * @param maxRetries - Max retry attempts per chunk\n * @param concurrency - Number of concurrent uploads (default: 3)\n */\n private async uploadChunksWithConcurrency(\n file: File,\n chunkSize: number,\n fileId: string,\n fileHash: string,\n maxRetries: number,\n concurrency: number,\n startIndex:number=0\n ): Promise<void> {\n try {\n const limit = pLimit(concurrency);\n\n // Créer toutes les promesses avec limite\n const uploadPromises: Promise<void>[] = [];\n\n for (let chunkIndex = startIndex; chunkIndex < this.totalChunks; chunkIndex++) {\n // Wrapper chaque upload dans le limiteur\n const limitedUpload = limit(() =>\n this.processChunk(\n file,\n chunkIndex,\n chunkSize,\n fileId,\n fileHash,\n maxRetries\n )\n );\n\n uploadPromises.push(limitedUpload);\n }\n\n // Attendre que tous les chunks soient uploadés\n await Promise.all(uploadPromises);\n } catch (error) {\n throw error;\n }\n }\n\n /**\n * Process a single chunk: slice, upload with retry, and save progress.\n * \n * @param file - The file being uploaded\n * @param currentChunkIndex - Index of the current chunk (0-based)\n * @param chunkSize - Size of each chunk in bytes\n * @param fileId - Server-provided file/session ID\n * @param fileHash - SHA-256 hash of the file\n * @param maxRetries - Maximum number of retry attempts\n * \n * @throws {UploadCancelledException} If upload is cancelled\n * @throws {FileUploadChunkError} If chunk upload fails after all retries\n */\n private async processChunk(\n file:File,\n currentChunkIndex: number,\n chunkSize:number,\n fileId: string,\n fileHash:string,\n maxRetries:number\n ): Promise<void>{\n try {\n if (this.abortController.signal.aborted) {\n this._uploadEventDispatcher.dispatch(\n new UploadCancelledEvent(\n file.name,\n this.totalChunks,\n this.uploadedBytes,\n this.percentage,\n currentChunkIndex,\n 'Upload cancelled by user',\n Date.now()\n ),\n HttpFileUploaderEvents.UPLOAD_CANCELLED\n )\n \n return;\n }\n\n while (this.isPaused) {\n await this.sleep(100);\n }\n // Calcule où commencer dans le fichier\n const start = currentChunkIndex * chunkSize;\n // chunkIndex=0 → start=0\n // chunkIndex=1 → start=300\n // chunkIndex=2 → start=600\n // chunkIndex=3 → start=900\n\n // Calcule où finir (sans depasser la fin du fichier)\n const end = Math.min(file.size, start + chunkSize);\n // chunkIndex=0 → end=min(1000, 300)=300\n // chunkIndex=1 → end=min(1000, 600)=600\n // chunkIndex=2 → end=min(1000, 900)=900\n // chunkIndex=3 → end=min(1000, 1200)=1000 ← Limité !\n\n // Découpe le morceau\n const chunk = file.slice(start, end);\n // chunkIndex=0 → slice(0, 300) → 300 bytes\n // chunkIndex=1 → slice(300, 600) → 300 bytes\n // chunkIndex=2 → slice(600, 900) → 300 bytes\n // chunkIndex=3 → slice(900, 1000)→ 100 bytes ← Plus petit !\n const chunkInfo: ChunkInfo = {\n index: currentChunkIndex,\n start,\n end,\n size: chunk.size,\n attempt: 0,\n status: 'pending'\n };\n\n this._uploadEventDispatcher.dispatch(\n new UploadChunkStartedEvent(chunkInfo),\n HttpFileUploaderEvents.MEDIA_CHUNK_UPLOAD_STARTED\n );\n // Upload with retry\n await this.uploadChunkWithRetry(\n chunk,\n chunkInfo,\n fileId,\n fileHash,\n this.totalChunks,\n maxRetries\n );\n\n // Auto-save progress\n if (this.options.autoSave) {\n await this.saveResumeData(fileId,chunkSize);\n }\n } catch (error) {\n throw error;\n \n }\n }\n\n private async uploadChunkWithRetry(\n chunk: Blob,\n chunkInfo: ChunkInfo,\n fileId: string,\n fileHash: string,\n totalChunks: number,\n maxRetries: number\n ): Promise<void> {\n let success = false;\n let lastError: Error | null = null;\n\n for (let attempt = 0; attempt < maxRetries && !success; attempt++) {\n chunkInfo.attempt = attempt + 1;\n chunkInfo.status = 'uploading';\n\n try {\n const response = await this.uploadChunk(chunk, chunkInfo, fileId, fileHash, totalChunks);\n success = true;\n chunkInfo.status = 'success';\n\n this.updateProgress(chunk.size, chunkInfo.index)\n\n this.notifyProgress(\n this.uploadedChunks,\n totalChunks,\n this.file.size,\n response\n );\n return;\n } catch (error) {\n if (error instanceof ChunkUploadHttpErrorException) {\n this._uploadEventDispatcher.dispatch(\n new ChunkUploadHttpErrorResponseEvent(\n error.errorPayload,\n error.statusResponse,\n this.endPointOptions.upload,\n chunkInfo),\n HttpFileUploaderEvents.MEDIA_CHUNK_UPLOAD_HTTP_ERROR_RESPONSE\n )\n }\n\n lastError = error as Error;\n chunkInfo.status = 'error';\n\n const chunkError: ChunkError= {\n chunk: chunkInfo,\n error: lastError,\n attempt: attempt + 1,\n willRetry: attempt < maxRetries - 1\n };\n\n if(error instanceof HttpFetchError){\n this._uploadEventDispatcher.dispatch(chunkError,HttpFileUploaderEvents.MEDIA_CHUNK_UPLOAD_FAILED)\n }\n\n if (attempt < maxRetries - 1) {\n const delay = Math.pow(2, attempt) * 1000;\n await this.sleep(delay);\n\n console.info(`Retry #${attempt + 2} in ${delay / 1000}s...`);\n }\n }\n }\n\n if (!success) {\n const fileUploadChunkError = new FileUploadChunkError(\n `Failed to upload chunk ${chunkInfo.index} after ${maxRetries} attempts`,\n {\n chunk: chunkInfo,\n error: lastError!,\n attempt: maxRetries,\n willRetry: false\n }\n );\n\n this._uploadEventDispatcher.dispatch(\n fileUploadChunkError,\n HttpFileUploaderEvents.MEDIA_CHUNK_UPLOAD_MAXRETRY_EXPIRE\n )\n \n throw fileUploadChunkError;\n }\n\n }\n\n private async uploadChunk(\n chunk: Blob,\n chunkInfo: ChunkInfo,\n mediaIdFromServer: string,\n fileHash: string,\n totalChunks: number\n ): Promise<FetchResponseInterface> {\n const media = this.file;\n const chunkFormData = createChunkFormData(\n chunk,\n {\n chunkIndex: chunkInfo.index,\n mediaId: mediaIdFromServer,\n fileSize: media.size,\n fileName: media.name,\n fileHash: fileHash,\n totalChunks: totalChunks\n }\n );\n\n try {\n const response_of_server = await safeFetch({\n url: this.endPointOptions.upload,\n headers: this.options.headers,\n data: chunkFormData,\n methodSend: \"POST\",\n responseType: \"json\",\n timeout: this.options.timeout ?? 60000,\n retryCount: 2,\n retryOnStatusCode: false,\n signal: this.createChunkAbortSignal()\n })\n const statusResponse = response_of_server.status;\n //if the server send a response which not success with status code(>=4XX ou >=5XX)\n if (response_of_server.failed) {\n throw new ChunkUploadHttpErrorException(response_of_server.data, statusResponse)\n }\n\n return response_of_server;\n } catch (error) {\n throw error;\n }\n\n }\n\n private createChunkAbortSignal(): AbortSignal {\n const chunkController = new AbortController();\n\n this.abortController.signal.addEventListener('abort', () => {\n chunkController.abort();\n });\n\n return chunkController.signal;\n }\n\n private notifyProgress(\n uploadedChunks: number,\n totalChunks: number,\n totalBytes: number,\n httpResponse: FetchResponseInterface): void {\n // Temps écoulé (minimum 0.1s pour éviter division par zéro)\n const elapsed = Math.max((Date.now() - this.startTime) / 1000, 0.1);\n const speed = this.uploadedBytes / elapsed; // Vitesse instantanée\n const remainingBytes = totalBytes - this.uploadedBytes; // Bytes restants\n // Temps restant (null si pas assez de données)\n const estimatedTimeRemaining = uploadedChunks < 2 ? null : remainingBytes / speed;\n\n this.percentage = Math.round((this.uploadedBytes / totalBytes) * 100);\n\n const progress: UploadProgress = {\n uploadedChunks,\n totalChunks,\n uploadedBytes: this.uploadedBytes,\n totalBytes,\n percentage: this.percentage,\n currentChunk: uploadedChunks,\n speed, // bytes/seconde\n estimatedTimeRemaining, // secondes (ou null)\n elapsed // secondes écoulées\n };\n\n this._uploadEventDispatcher.dispatch(\n new UploadProgressEvent(\n progress,\n httpResponse.data,\n httpResponse.status\n )\n )\n \n console.info(\n `Progress: ${this.percentage}% | ` +\n `Speed: ${FileUtils.formatBytes(speed)}/s | ` +\n `ETA: ${estimatedTimeRemaining ? FileUtils.formatDuration(estimatedTimeRemaining) : 'Calculating...'}`\n );\n }\n\n private sleep(ms: number): Promise<void> {\n return new Promise(resolve => setTimeout(resolve, ms));\n }\n\n /**\n * Save current upload progress to cache for resume capability\n * \n * @param fileId - Server-provided file/session ID\n * @param chunkSize - Size of each chunk in bytes\n * @returns Saved resume data\n */\n private async saveResumeData(fileId: string, chunkSize: number): Promise<ResumeData> {\n const data: ResumeData = {\n fileId: fileId,\n fileName: this.file.name,\n fileSize: this.file.size,\n uploadedChunks: this.uploadedChunks,\n lastChunkIndex: this.lastUploadedChunkIndex,\n lastBytePosition: this.uploadedBytes,\n chunkSize: chunkSize,\n concurrency:this.options.concurrency || 3\n };\n\n await this.uploadResumeData.setItem(`upload_${this.file.name}`, data);\n\n console.info(\n `Resume data saved: ${this.uploadedChunks}/${Math.ceil(this.file.size / chunkSize)} chunks, ` +\n `last chunk index: ${this.lastUploadedChunkIndex}`\n );\n\n return data;\n }\n\n private setState(newState: UploadState): void {\n const oldState = this.state;\n this.state = newState;\n\n this._uploadEventDispatcher.dispatch(\n new UploadStateChangedEvent(\n oldState,\n newState,\n Date.now()\n ),\n HttpFileUploaderEvents.UPLOAD_STATE_CHANGED\n )\n \n }\n\n public getState(): UploadState {\n return this.state;\n }\n\n private handleUploadFailure(error: Error): void {\n this.setState(UploadState.FAILED);\n\n this._uploadEventDispatcher.dispatch(error, HttpFileUploaderEvents.DOWNLOAD_MEDIA_FAILURE);\n console.error('Upload failed:', error);\n }\n\n public cancel(): void {\n this.abortController.abort();\n this.setState(UploadState.CANCELLED);\n }\n\n public pause(): void {\n this.isPaused = true;\n this.setState(UploadState.PAUSED);\n this._uploadEventDispatcher.dispatch(\n new UploadPausedEvent(\n this.file.name,\n this.totalChunks,\n this.uploadedBytes,\n this.percentage,\n Date.now()\n ),\n HttpFileUploaderEvents.UPLOAD_PAUSED\n );\n }\n\n\n public resume(): void {\n this.isPaused = false;\n this.setState(UploadState.UPLOADING);\n this._uploadEventDispatcher.dispatch(\n new UploadResumedEvent(\n this.file.name,\n this.totalChunks,\n this.uploadedBytes, \n this.percentage),\n HttpFileUploaderEvents.UPLOAD_RESUMED,\n );\n }\n\n /**\n * Load previously saved resume data\n * \n * @param fileName - Name of the file to resume\n * @returns Resume data or null if not found\n */\n async loadResumeData(fileName: string): Promise<ResumeData | null> {\n try {\n const data = await this.uploadResumeData.getItem(`upload_${fileName}`);\n\n if (data) {\n console.info(\n `Resume data loaded: ${data.uploadedChunks} chunks uploaded, ` +\n `last index: ${data.lastChunkIndex}`\n );\n }\n return data;\n } catch (error) {\n console.warn(`No resume data found for ${fileName}`);\n return null;\n }\n }\n\n /**\n * Resume upload from saved state\n * \n * @param resumeData - Previously saved resume data\n * @returns Upload result\n */\n public async resumeUpload(resumeData: ResumeData): Promise<void> {\n const __message = `Resuming upload from chunk ${resumeData.lastChunkIndex + 1} ` +\n `(${resumeData.uploadedChunks} chunks already uploaded)`;\n\n // Restore state\n this.uploadedBytes = resumeData.lastBytePosition;\n this.uploadedChunks = resumeData.uploadedChunks;\n this.lastUploadedChunkIndex = resumeData.lastChunkIndex;\n\n // Calculate adjusted start time for accurate speed calculation\n const assumedSpeed = 500000; // 500 KB/s assumed\n const timeAlreadySpent = resumeData.lastBytePosition / assumedSpeed;\n this.startTime = Date.now() - (timeAlreadySpent * 1000);\n\n const { maxRetries = 3 } = this.options;\n const fileHash = await FileUtils.generateFileHash(this.file);\n const chunkSize = resumeData.chunkSize;\n this.totalChunks = Math.ceil(this.file.size / chunkSize);\n\n try {\n this._uploadEventDispatcher.dispatch(\n new ResumeUploadEvent(resumeData,__message),\n HttpFileUploaderEvents.MEDIA_CHUNK_UPLOAD_RESUME\n )\n await this.uploadChunksWithConcurrency(\n this.file,\n chunkSize,\n resumeData.fileId,\n fileHash,\n maxRetries,\n resumeData.concurrency,\n resumeData.lastChunkIndex + 1\n )\n ;\n await this.finalizeUpload(resumeData.fileId, fileHash);\n\n } catch (error) {\n this.handleUploadFailure(error as Error);\n throw error;\n }\n }\n\n private updateProgress(chunkSize: number, chunkIndex: number): void {\n this.uploadedBytes += chunkSize;\n this.uploadedChunks++;\n this.lastUploadedChunkIndex = Math.max(this.lastUploadedChunkIndex,chunkIndex);\n }\n \n private async finalizeUpload(mediaId: string, fileHash: string): Promise<void> {\n try {\n \n const finalizeUploadEvent = await this._uploadEventDispatcher.dispatchAsync(\n new FinalizeUploadEvent(\n this.endPointOptions.finalize,\n mediaId,\n fileHash,\n this.options.headerFinalezingUpload)\n ,\n HttpFileUploaderEvents.FINALIZE_UPLOAD\n )\n\n this.setState(UploadState.FINALIZING);\n\n\n const duration = (Date.now() - this.startTime) / 1000;\n\n const uploadResult: UploadResult = {\n success: true,\n finalizeUploadResponse: finalizeUploadEvent.hasResponse() ? finalizeUploadEvent.getResponse() : null ,\n totalChunks: this.totalChunks,\n totalBytes: this.file.size,\n duration,\n averageSpeed: this.file.size / duration,\n fileId: mediaId\n };\n\n this.setState(UploadState.COMPLETED);\n\n this._uploadEventDispatcher.dispatch(\n new UploadMediaCompleteEvent(uploadResult),HttpFileUploaderEvents.DOWNLOAD_MEDIA_COMPLETE\n )\n\n } catch (error) {\n throw error;\n }\n }\n}"],"mappings":";;;;;;;;;;;;;;;;;;;;;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AEzD,SAAS,OAAO;AACZ,WAAK,oBAAoB,KAAc;AACvC,YAAM;AAAA,IACV;AAAA,EACJ;AAAA,EAEQ,eAAe,WAAmB,YAA0B;AAChE,SAAK,iBAAiB;AACtB,SAAK;AACL,SAAK,yBAAyB,KAAK,IAAI,KAAK,wBAAuB,UAAU;AAAA,EACjF;AAAA,EAEA,MAAc,eAAe,SAAiB,UAAkC;AAC5E,QAAI;AAEA,YAAM,sBAAsB,MAAM,KAAK,uBAAuB;AAAA,QAC1D,IAAI;AAAA,UACA,KAAK,gBAAgB;AAAA,UACrB;AAAA,UACA;AAAA,UACH,KAAK,QAAQ;AAAA,QAAsB;AAAA,QAEpC,qCAAuB;AAAA,MAC3B;AAEA,WAAK,SAAS,yBAAY,UAAU;AAGpC,YAAM,YAAY,KAAK,IAAI,IAAI,KAAK,aAAa;AAEjD,YAAM,eAA6B;AAAA,QAC/B,SAAS;AAAA,QACT,wBAAwB,oBAAoB,YAAY,IAAI,oBAAoB,YAAY,IAAI;AAAA,QAChG,aAAa,KAAK;AAAA,QAClB,YAAY,KAAK,KAAK;AAAA,QACtB;AAAA,QACA,cAAc,KAAK,KAAK,OAAO;AAAA,QAC/B,QAAQ;AAAA,MACZ;AAEA,WAAK,SAAS,yBAAY,SAAS;AAEnC,WAAK,uBAAuB;AAAA,QACxB,IAAI,uCAAyB,YAAY;AAAA,QAAE,qCAAuB;AAAA,MACtE;AAAA,IAEJ,SAAS,OAAO;AACZ,YAAM;AAAA,IACV;AAAA,EACJ;AACJ;","names":["pLimit"]}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { ChunkInfo, UploadStatus } from '../../types/index.js';
|
|
2
|
+
import '@wlindabla/http_client';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Event data for MEDIA_CHUNK_UPLOAD_HTTP_ERROR_RESPONSE
|
|
6
|
+
*/
|
|
7
|
+
declare class ChunkUploadHttpErrorResponseEvent {
|
|
8
|
+
readonly errorPayload: string | Record<string, string | unknown> | unknown;
|
|
9
|
+
readonly statusResponse: number;
|
|
10
|
+
readonly urlEndpoint: string | URL | Request;
|
|
11
|
+
readonly chunkInfo: ChunkInfo;
|
|
12
|
+
constructor(errorPayload: string | Record<string, string | unknown> | unknown, statusResponse: number, urlEndpoint: string | URL | Request, chunkInfo: ChunkInfo);
|
|
13
|
+
get chunkIndex(): number;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Event data for MEDIA_CHUNK_UPLOAD_STARTED
|
|
17
|
+
*/
|
|
18
|
+
declare class UploadChunkStartedEvent {
|
|
19
|
+
private readonly _chunkInfo;
|
|
20
|
+
constructor(_chunkInfo: ChunkInfo);
|
|
21
|
+
get start(): number;
|
|
22
|
+
get end(): number;
|
|
23
|
+
get uploadStatus(): UploadStatus;
|
|
24
|
+
get chunkIndex(): number;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export { ChunkUploadHttpErrorResponseEvent, UploadChunkStartedEvent };
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
|
+
var chunk_exports = {};
|
|
21
|
+
__export(chunk_exports, {
|
|
22
|
+
ChunkUploadHttpErrorResponseEvent: () => ChunkUploadHttpErrorResponseEvent,
|
|
23
|
+
UploadChunkStartedEvent: () => UploadChunkStartedEvent
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(chunk_exports);
|
|
26
|
+
class ChunkUploadHttpErrorResponseEvent {
|
|
27
|
+
constructor(errorPayload, statusResponse, urlEndpoint, chunkInfo) {
|
|
28
|
+
this.errorPayload = errorPayload;
|
|
29
|
+
this.statusResponse = statusResponse;
|
|
30
|
+
this.urlEndpoint = urlEndpoint;
|
|
31
|
+
this.chunkInfo = chunkInfo;
|
|
32
|
+
}
|
|
33
|
+
errorPayload;
|
|
34
|
+
statusResponse;
|
|
35
|
+
urlEndpoint;
|
|
36
|
+
chunkInfo;
|
|
37
|
+
static {
|
|
38
|
+
__name(this, "ChunkUploadHttpErrorResponseEvent");
|
|
39
|
+
}
|
|
40
|
+
get chunkIndex() {
|
|
41
|
+
return this.chunkInfo.index;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
class UploadChunkStartedEvent {
|
|
45
|
+
constructor(_chunkInfo) {
|
|
46
|
+
this._chunkInfo = _chunkInfo;
|
|
47
|
+
}
|
|
48
|
+
_chunkInfo;
|
|
49
|
+
static {
|
|
50
|
+
__name(this, "UploadChunkStartedEvent");
|
|
51
|
+
}
|
|
52
|
+
get start() {
|
|
53
|
+
return this._chunkInfo.start;
|
|
54
|
+
}
|
|
55
|
+
get end() {
|
|
56
|
+
return this._chunkInfo.end;
|
|
57
|
+
}
|
|
58
|
+
get uploadStatus() {
|
|
59
|
+
return this._chunkInfo.status;
|
|
60
|
+
}
|
|
61
|
+
get chunkIndex() {
|
|
62
|
+
return this._chunkInfo.index;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
66
|
+
0 && (module.exports = {
|
|
67
|
+
ChunkUploadHttpErrorResponseEvent,
|
|
68
|
+
UploadChunkStartedEvent
|
|
69
|
+
});
|
|
70
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/events/chunk/index.ts"],"sourcesContent":["/*\n * This file is part of the project by AGBOKOUDJO Franck.\n *\n * (c) AGBOKOUDJO Franck <internationaleswebservices@gmail.com>\n * Phone: +229 0167 25 18 86\n * LinkedIn: https://www.linkedin.com/in/internationales-web-apps-services-120520193/\n * Company: INTERNATIONALES WEB APPS & SERVICES\n *\n * For more information, please feel free to contact the author.\n */\nimport { ChunkInfo, UploadStatus } from \"../../types\";\n\n/**\n * Event data for MEDIA_CHUNK_UPLOAD_HTTP_ERROR_RESPONSE\n */\nexport class ChunkUploadHttpErrorResponseEvent {\n constructor(\n public readonly errorPayload: string | Record<string, string | unknown> | unknown,\n public readonly statusResponse: number,\n public readonly urlEndpoint: string | URL | Request,\n public readonly chunkInfo: ChunkInfo\n ) { }\n\n public get chunkIndex(): number { return this.chunkInfo.index; }\n}\n\n/**\n * Event data for MEDIA_CHUNK_UPLOAD_STARTED\n */\nexport class UploadChunkStartedEvent {\n constructor(private readonly _chunkInfo: ChunkInfo) { }\n\n public get start(): number { return this._chunkInfo.start; }\n\n public get end(): number { return this._chunkInfo.end; }\n\n public get uploadStatus(): UploadStatus { return this._chunkInfo.status; }\n\n public get chunkIndex(): number { return this._chunkInfo.index; }\n}"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAeO,MAAM,kCAAkC;AAAA,EAC3C,YACoB,cACA,gBACA,aACA,WAClB;AAJkB;AACA;AACA;AACA;AAAA,EAChB;AAAA,EAJgB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EApBxB,OAe+C;AAAA;AAAA;AAAA,EAQ3C,IAAW,aAAqB;AAAE,WAAO,KAAK,UAAU;AAAA,EAAO;AACnE;AAKO,MAAM,wBAAwB;AAAA,EACjC,YAA6B,YAAuB;AAAvB;AAAA,EAAyB;AAAA,EAAzB;AAAA,EA9BjC,OA6BqC;AAAA;AAAA;AAAA,EAGjC,IAAW,QAAgB;AAAE,WAAO,KAAK,WAAW;AAAA,EAAO;AAAA,EAE3D,IAAW,MAAc;AAAE,WAAO,KAAK,WAAW;AAAA,EAAK;AAAA,EAEvD,IAAW,eAA6B;AAAE,WAAO,KAAK,WAAW;AAAA,EAAQ;AAAA,EAEzE,IAAW,aAAqB;AAAE,WAAO,KAAK,WAAW;AAAA,EAAO;AACpE;","names":[]}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { BaseEvent } from '@wlindabla/event_dispatcher';
|
|
2
|
+
import { ResumeData, UploadResult } from '../../types/index.js';
|
|
3
|
+
import { ResponseEventInterface } from '@wlindabla/http_client/events';
|
|
4
|
+
import { FetchResponseInterface } from '@wlindabla/http_client';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Event data for MEDIA_CHUNK_UPLOAD_RESUME
|
|
8
|
+
*/
|
|
9
|
+
declare class ResumeUploadEvent {
|
|
10
|
+
private readonly __resumeData;
|
|
11
|
+
readonly message: string;
|
|
12
|
+
constructor(__resumeData: ResumeData, message: string);
|
|
13
|
+
get mediaId(): string | number;
|
|
14
|
+
get fileName(): string;
|
|
15
|
+
get uploadedChunks(): number;
|
|
16
|
+
get lastChunkIndex(): number;
|
|
17
|
+
get lastBytePosition(): number;
|
|
18
|
+
get chunkSize(): number;
|
|
19
|
+
get fileSize(): number;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Event data for DOWNLOAD_MEDIA_COMPLETE
|
|
23
|
+
*/
|
|
24
|
+
declare class UploadMediaCompleteEvent {
|
|
25
|
+
private readonly _uploadResult;
|
|
26
|
+
constructor(_uploadResult: UploadResult);
|
|
27
|
+
get success(): boolean;
|
|
28
|
+
get mediaId(): string | number;
|
|
29
|
+
get totalBytes(): number;
|
|
30
|
+
get totalChunks(): number;
|
|
31
|
+
get finalizeUploadHttpResponse(): any;
|
|
32
|
+
get operationDuration(): number;
|
|
33
|
+
get averageSpeed(): number;
|
|
34
|
+
}
|
|
35
|
+
declare class FinalizeUploadFailureEvent extends BaseEvent {
|
|
36
|
+
readonly error: Error;
|
|
37
|
+
readonly status?: number | undefined;
|
|
38
|
+
readonly errorData?: any | undefined;
|
|
39
|
+
readonly responseData?: any | undefined;
|
|
40
|
+
readonly isNetworkError?: boolean | undefined;
|
|
41
|
+
constructor(error: Error, status?: number | undefined, errorData?: any | undefined, responseData?: any | undefined, isNetworkError?: boolean | undefined);
|
|
42
|
+
}
|
|
43
|
+
declare class FinalizeUploadEvent extends BaseEvent implements ResponseEventInterface {
|
|
44
|
+
readonly endPoint: string | URL;
|
|
45
|
+
readonly mediaId: string;
|
|
46
|
+
readonly mediaHash: string;
|
|
47
|
+
readonly headers?: HeadersInit | undefined;
|
|
48
|
+
private fetchResponse;
|
|
49
|
+
constructor(endPoint: string | URL, mediaId: string, mediaHash: string, headers?: HeadersInit | undefined);
|
|
50
|
+
/**
|
|
51
|
+
* Returns the response
|
|
52
|
+
*/
|
|
53
|
+
getResponse(): FetchResponseInterface | null;
|
|
54
|
+
/**
|
|
55
|
+
* Sets the response
|
|
56
|
+
*/
|
|
57
|
+
setResponse(response: FetchResponseInterface): void;
|
|
58
|
+
/**
|
|
59
|
+
* Returns whether a response was set
|
|
60
|
+
*/
|
|
61
|
+
hasResponse(): boolean;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export { FinalizeUploadEvent, FinalizeUploadFailureEvent, ResumeUploadEvent, UploadMediaCompleteEvent };
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
|
+
var complete_exports = {};
|
|
21
|
+
__export(complete_exports, {
|
|
22
|
+
FinalizeUploadEvent: () => FinalizeUploadEvent,
|
|
23
|
+
FinalizeUploadFailureEvent: () => FinalizeUploadFailureEvent,
|
|
24
|
+
ResumeUploadEvent: () => ResumeUploadEvent,
|
|
25
|
+
UploadMediaCompleteEvent: () => UploadMediaCompleteEvent
|
|
26
|
+
});
|
|
27
|
+
module.exports = __toCommonJS(complete_exports);
|
|
28
|
+
var import_event_dispatcher = require("@wlindabla/event_dispatcher");
|
|
29
|
+
class ResumeUploadEvent {
|
|
30
|
+
constructor(__resumeData, message) {
|
|
31
|
+
this.__resumeData = __resumeData;
|
|
32
|
+
this.message = message;
|
|
33
|
+
}
|
|
34
|
+
__resumeData;
|
|
35
|
+
message;
|
|
36
|
+
static {
|
|
37
|
+
__name(this, "ResumeUploadEvent");
|
|
38
|
+
}
|
|
39
|
+
get mediaId() {
|
|
40
|
+
return this.__resumeData.fileId;
|
|
41
|
+
}
|
|
42
|
+
get fileName() {
|
|
43
|
+
return this.__resumeData.fileName;
|
|
44
|
+
}
|
|
45
|
+
get uploadedChunks() {
|
|
46
|
+
return this.__resumeData.uploadedChunks;
|
|
47
|
+
}
|
|
48
|
+
get lastChunkIndex() {
|
|
49
|
+
return this.__resumeData.lastChunkIndex;
|
|
50
|
+
}
|
|
51
|
+
get lastBytePosition() {
|
|
52
|
+
return this.__resumeData.lastBytePosition;
|
|
53
|
+
}
|
|
54
|
+
get chunkSize() {
|
|
55
|
+
return this.__resumeData.chunkSize;
|
|
56
|
+
}
|
|
57
|
+
get fileSize() {
|
|
58
|
+
return this.__resumeData.fileSize;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
class UploadMediaCompleteEvent {
|
|
62
|
+
constructor(_uploadResult) {
|
|
63
|
+
this._uploadResult = _uploadResult;
|
|
64
|
+
}
|
|
65
|
+
_uploadResult;
|
|
66
|
+
static {
|
|
67
|
+
__name(this, "UploadMediaCompleteEvent");
|
|
68
|
+
}
|
|
69
|
+
get success() {
|
|
70
|
+
return this._uploadResult.success;
|
|
71
|
+
}
|
|
72
|
+
get mediaId() {
|
|
73
|
+
return this._uploadResult.fileId;
|
|
74
|
+
}
|
|
75
|
+
get totalBytes() {
|
|
76
|
+
return this._uploadResult.totalBytes;
|
|
77
|
+
}
|
|
78
|
+
get totalChunks() {
|
|
79
|
+
return this._uploadResult.totalChunks;
|
|
80
|
+
}
|
|
81
|
+
get finalizeUploadHttpResponse() {
|
|
82
|
+
return this._uploadResult.finalizeUploadResponse;
|
|
83
|
+
}
|
|
84
|
+
get operationDuration() {
|
|
85
|
+
return this._uploadResult.duration;
|
|
86
|
+
}
|
|
87
|
+
get averageSpeed() {
|
|
88
|
+
return this._uploadResult.averageSpeed;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
class FinalizeUploadFailureEvent extends import_event_dispatcher.BaseEvent {
|
|
92
|
+
constructor(error, status, errorData, responseData, isNetworkError) {
|
|
93
|
+
super();
|
|
94
|
+
this.error = error;
|
|
95
|
+
this.status = status;
|
|
96
|
+
this.errorData = errorData;
|
|
97
|
+
this.responseData = responseData;
|
|
98
|
+
this.isNetworkError = isNetworkError;
|
|
99
|
+
}
|
|
100
|
+
error;
|
|
101
|
+
status;
|
|
102
|
+
errorData;
|
|
103
|
+
responseData;
|
|
104
|
+
isNetworkError;
|
|
105
|
+
static {
|
|
106
|
+
__name(this, "FinalizeUploadFailureEvent");
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
class FinalizeUploadEvent extends import_event_dispatcher.BaseEvent {
|
|
110
|
+
constructor(endPoint, mediaId, mediaHash, headers) {
|
|
111
|
+
super();
|
|
112
|
+
this.endPoint = endPoint;
|
|
113
|
+
this.mediaId = mediaId;
|
|
114
|
+
this.mediaHash = mediaHash;
|
|
115
|
+
this.headers = headers;
|
|
116
|
+
this.fetchResponse = null;
|
|
117
|
+
}
|
|
118
|
+
endPoint;
|
|
119
|
+
mediaId;
|
|
120
|
+
mediaHash;
|
|
121
|
+
headers;
|
|
122
|
+
static {
|
|
123
|
+
__name(this, "FinalizeUploadEvent");
|
|
124
|
+
}
|
|
125
|
+
fetchResponse;
|
|
126
|
+
/**
|
|
127
|
+
* Returns the response
|
|
128
|
+
*/
|
|
129
|
+
getResponse() {
|
|
130
|
+
return this.fetchResponse;
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Sets the response
|
|
134
|
+
*/
|
|
135
|
+
setResponse(response) {
|
|
136
|
+
this.fetchResponse = response;
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Returns whether a response was set
|
|
140
|
+
*/
|
|
141
|
+
hasResponse() {
|
|
142
|
+
return this.fetchResponse !== null;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
146
|
+
0 && (module.exports = {
|
|
147
|
+
FinalizeUploadEvent,
|
|
148
|
+
FinalizeUploadFailureEvent,
|
|
149
|
+
ResumeUploadEvent,
|
|
150
|
+
UploadMediaCompleteEvent
|
|
151
|
+
});
|
|
152
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/events/complete/index.ts"],"sourcesContent":["/*\n * This file is part of the project by AGBOKOUDJO Franck.\n *\n * (c) AGBOKOUDJO Franck <internationaleswebservices@gmail.com>\n * Phone: +229 0167 25 18 86\n * LinkedIn: https://www.linkedin.com/in/internationales-web-apps-services-120520193/\n * Company: INTERNATIONALES WEB APPS & SERVICES\n *\n * For more information, please feel free to contact the author.\n */\nimport { BaseEvent } from \"@wlindabla/event_dispatcher\";\nimport { ResumeData, UploadResult } from \"../../types\";\n\nimport type {\n ResponseEventInterface\n} from \"@wlindabla/http_client/events\";\n\nimport type {\n FetchResponseInterface\n} from \"@wlindabla/http_client\";\n\n/**\n * Event data for MEDIA_CHUNK_UPLOAD_RESUME\n */\nexport class ResumeUploadEvent {\n constructor(\n private readonly __resumeData: ResumeData,\n public readonly message: string) { }\n\n public get mediaId(): string | number { return this.__resumeData.fileId; }\n\n public get fileName(): string { return this.__resumeData.fileName; }\n\n public get uploadedChunks(): number { return this.__resumeData.uploadedChunks; }\n\n public get lastChunkIndex(): number { return this.__resumeData.lastChunkIndex; }\n\n public get lastBytePosition(): number { return this.__resumeData.lastBytePosition; }\n\n public get chunkSize(): number { return this.__resumeData.chunkSize; }\n\n public get fileSize(): number { return this.__resumeData.fileSize; }\n}\n\n/**\n * Event data for DOWNLOAD_MEDIA_COMPLETE\n */\nexport class UploadMediaCompleteEvent {\n constructor(private readonly _uploadResult: UploadResult) { }\n\n public get success(): boolean { return this._uploadResult.success; }\n\n public get mediaId(): string | number { return this._uploadResult.fileId! }\n\n public get totalBytes(): number { return this._uploadResult.totalBytes; }\n\n public get totalChunks(): number { return this._uploadResult.totalChunks; }\n\n public get finalizeUploadHttpResponse(): any { return this._uploadResult.finalizeUploadResponse; }\n\n public get operationDuration(): number { return this._uploadResult.duration; }\n\n public get averageSpeed(): number { return this._uploadResult.averageSpeed; }\n}\n\nexport class FinalizeUploadFailureEvent extends BaseEvent{\n constructor(\n public readonly error: Error,\n public readonly status?: number,\n public readonly errorData?: any,\n public readonly responseData?: any,\n public readonly isNetworkError?: boolean\n ) { super(); }\n}\n\nexport class FinalizeUploadEvent extends BaseEvent implements ResponseEventInterface{\n private fetchResponse: FetchResponseInterface|null;\n\n constructor(\n public readonly endPoint:string|URL,\n public readonly mediaId: string,\n public readonly mediaHash: string,\n public readonly headers?: HeadersInit\n ) {\n super();\n this.fetchResponse = null;\n }\n\n /**\n * Returns the response\n */\n public getResponse(): FetchResponseInterface | null {\n return this.fetchResponse;\n }\n\n /**\n * Sets the response\n */\n public setResponse(response: FetchResponseInterface): void {\n this.fetchResponse = response;\n }\n\n /**\n * Returns whether a response was set\n */\n public hasResponse(): boolean {\n return this.fetchResponse !== null;\n }\n}"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAUA,8BAA0B;AAcnB,MAAM,kBAAkB;AAAA,EAC3B,YACqB,cACD,SAAiB;AADhB;AACD;AAAA,EAAmB;AAAA,EADlB;AAAA,EACD;AAAA,EA3BxB,OAwB+B;AAAA;AAAA;AAAA,EAK3B,IAAW,UAA2B;AAAE,WAAO,KAAK,aAAa;AAAA,EAAQ;AAAA,EAEzE,IAAW,WAAmB;AAAE,WAAO,KAAK,aAAa;AAAA,EAAU;AAAA,EAEnE,IAAW,iBAAyB;AAAE,WAAO,KAAK,aAAa;AAAA,EAAgB;AAAA,EAE/E,IAAW,iBAAyB;AAAE,WAAO,KAAK,aAAa;AAAA,EAAgB;AAAA,EAE/E,IAAW,mBAA2B;AAAE,WAAO,KAAK,aAAa;AAAA,EAAkB;AAAA,EAEnF,IAAW,YAAoB;AAAE,WAAO,KAAK,aAAa;AAAA,EAAW;AAAA,EAErE,IAAW,WAAmB;AAAE,WAAO,KAAK,aAAa;AAAA,EAAU;AACvE;AAKO,MAAM,yBAAyB;AAAA,EAClC,YAA6B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|
+
export { InitializeUploadFailureEvent, InitializeUploadStartedEvent, InitializeUploadSuccessEvent, InitializingUploadEvent } from './initialize/index.js';
|
|
2
|
+
export { UploadCancelledEvent, UploadPausedEvent, UploadProgressEvent, UploadResumedEvent, UploadStateChangedEvent } from './state/index.js';
|
|
3
|
+
export { ChunkUploadHttpErrorResponseEvent, UploadChunkStartedEvent } from './chunk/index.js';
|
|
4
|
+
export { FinalizeUploadEvent, FinalizeUploadFailureEvent, ResumeUploadEvent, UploadMediaCompleteEvent } from './complete/index.js';
|
|
5
|
+
import '../types/index.js';
|
|
6
|
+
import '@wlindabla/http_client';
|
|
7
|
+
import '@wlindabla/event_dispatcher';
|
|
8
|
+
import '@wlindabla/http_client/events';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* HttpFileUploaderEvents - Event Constants for File Upload Operations
|
|
12
|
+
*
|
|
13
|
+
* This abstract class provides a centralized collection of event name constants
|
|
14
|
+
* used throughout the file upload lifecycle. It follows the Symfony event
|
|
15
|
+
* dispatcher pattern, providing a type-safe way to reference events.
|
|
16
|
+
*
|
|
17
|
+
* The events are organized into five categories:
|
|
18
|
+
* - **Initialize Events**: Events related to upload session initialization
|
|
19
|
+
* - **Chunk Upload Events**: Events fired during individual chunk uploads
|
|
20
|
+
* - **Upload State Events**: Events tracking upload state changes (pause, resume, cancel)
|
|
21
|
+
* - **Completion Events**: Events fired when upload completes or fails
|
|
22
|
+
* - **Metadata Events**: Events related to media metadata operations
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```typescript
|
|
26
|
+
* import { HttpFileUploaderEvents } from '@wlindabla/file_uploader';
|
|
27
|
+
*
|
|
28
|
+
* // Listen to chunk upload success
|
|
29
|
+
* dispatcher.addListener(
|
|
30
|
+
* HttpFileUploaderEvents.MEDIA_CHUNK_UPLOAD_SUCCESS,
|
|
31
|
+
* (event: ChunkUploadSuccessEvent) => {
|
|
32
|
+
* console.log('Chunk uploaded:', event.progress);
|
|
33
|
+
* }
|
|
34
|
+
* );
|
|
35
|
+
*
|
|
36
|
+
* // Listen to upload state changes
|
|
37
|
+
* dispatcher.addListener(
|
|
38
|
+
* HttpFileUploaderEvents.UPLOAD_STATE_CHANGED,
|
|
39
|
+
* (event: UploadStateChangedEvent) => {
|
|
40
|
+
* console.log(`State changed: ${event.oldState} → ${event.newState}`);
|
|
41
|
+
* }
|
|
42
|
+
* );
|
|
43
|
+
* ```
|
|
44
|
+
*
|
|
45
|
+
* @author AGBOKOUDJO Franck <internationaleswebservices@gmail.com>
|
|
46
|
+
* @version 1.0.0
|
|
47
|
+
* @since 1.0.0
|
|
48
|
+
*
|
|
49
|
+
* @see {@link https://github.com/Agbokoudjo/file_uploader | GitHub Repository}
|
|
50
|
+
* @see {@link EventDispatcherInterface} for event dispatcher usage
|
|
51
|
+
*/
|
|
52
|
+
declare abstract class HttpFileUploaderEvents {
|
|
53
|
+
static readonly INITIALIZE_UPLOAD = "initializingUpload";
|
|
54
|
+
/** Dispatched when upload initialization starts */
|
|
55
|
+
static readonly INITIALIZE_UPLOAD_STARTED = "initializeUploadStarted";
|
|
56
|
+
/** Dispatched when upload initialization succeeds */
|
|
57
|
+
static readonly INITIALIZE_UPLOAD_SUCCESS = "initializeUploadSuccess";
|
|
58
|
+
/** Dispatched when upload initialization fails */
|
|
59
|
+
static readonly INITIALIZE_UPLOAD_FAILURE = "initializeUploadFailure";
|
|
60
|
+
/** Dispatched when a chunk upload starts */
|
|
61
|
+
static readonly MEDIA_CHUNK_UPLOAD_STARTED = "mediaChunkUploadStarted";
|
|
62
|
+
/** Dispatched when a chunk is uploaded successfully */
|
|
63
|
+
static readonly MEDIA_CHUNK_UPLOAD_SUCCESS = "mediaChunkUploadSuccess";
|
|
64
|
+
/** Dispatched when a chunk upload fails */
|
|
65
|
+
static readonly MEDIA_CHUNK_UPLOAD_FAILED = "mediaChunkUploadFailed";
|
|
66
|
+
/** Dispatched when the server returns an HTTP error for a chunk */
|
|
67
|
+
static readonly MEDIA_CHUNK_UPLOAD_HTTP_ERROR_RESPONSE = "mediaChunkUploadHttpErrorResponse";
|
|
68
|
+
/** Dispatched to provide the status of a chunk */
|
|
69
|
+
static readonly MEDIA_CHUNK_UPLOAD_STATUS = "mediaChunkUploadStatus";
|
|
70
|
+
/** Dispatched when maximum retry attempts are exceeded for a chunk */
|
|
71
|
+
static readonly MEDIA_CHUNK_UPLOAD_MAXRETRY_EXPIRE = "mediaChunkUploadMaxRetryExpire";
|
|
72
|
+
/** Dispatched when a chunk upload resumes */
|
|
73
|
+
static readonly MEDIA_CHUNK_UPLOAD_RESUME = "mediaChunkUploadResume";
|
|
74
|
+
/** Dispatched when the upload is paused */
|
|
75
|
+
static readonly UPLOAD_PAUSED = "uploadPaused";
|
|
76
|
+
/** Dispatched when the upload resumes after being paused */
|
|
77
|
+
static readonly UPLOAD_RESUMED = "uploadResumed";
|
|
78
|
+
/** Dispatched when the upload is cancelled */
|
|
79
|
+
static readonly UPLOAD_CANCELLED = "uploadCancelled";
|
|
80
|
+
/** Dispatched when the upload state changes */
|
|
81
|
+
static readonly UPLOAD_STATE_CHANGED = "uploadStateChanged";
|
|
82
|
+
/** Dispatched when the upload completes successfully */
|
|
83
|
+
static readonly DOWNLOAD_MEDIA_COMPLETE = "downloadMediaComplete";
|
|
84
|
+
/** Dispatched when the upload fails completely */
|
|
85
|
+
static readonly DOWNLOAD_MEDIA_FAILURE = "downloadMediaFailure";
|
|
86
|
+
/** Dispatched when the upload resumes from a saved state */
|
|
87
|
+
static readonly DOWNLOAD_MEDIA_RESUME = "downloadMediaResume";
|
|
88
|
+
static readonly FINALIZE_UPLOAD = "finalizeUpload";
|
|
89
|
+
static readonly FINALIZE_UPLOAD_FAILURE = "finalizeUploadFailure";
|
|
90
|
+
/** Dispatched when media metadata is saved successfully */
|
|
91
|
+
static readonly MEDIA_METADATA_SAVE_SUCCESS = "mediaMetadataSaveSuccess";
|
|
92
|
+
private constructor();
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export { HttpFileUploaderEvents };
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
20
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
21
|
+
var events_exports = {};
|
|
22
|
+
__export(events_exports, {
|
|
23
|
+
HttpFileUploaderEvents: () => HttpFileUploaderEvents
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(events_exports);
|
|
26
|
+
__reExport(events_exports, require("./initialize"), module.exports);
|
|
27
|
+
__reExport(events_exports, require("./state"), module.exports);
|
|
28
|
+
__reExport(events_exports, require("./chunk"), module.exports);
|
|
29
|
+
__reExport(events_exports, require("./complete"), module.exports);
|
|
30
|
+
class HttpFileUploaderEvents {
|
|
31
|
+
static {
|
|
32
|
+
__name(this, "HttpFileUploaderEvents");
|
|
33
|
+
}
|
|
34
|
+
static INITIALIZE_UPLOAD = "initializingUpload";
|
|
35
|
+
/** Dispatched when upload initialization starts */
|
|
36
|
+
static INITIALIZE_UPLOAD_STARTED = "initializeUploadStarted";
|
|
37
|
+
/** Dispatched when upload initialization succeeds */
|
|
38
|
+
static INITIALIZE_UPLOAD_SUCCESS = "initializeUploadSuccess";
|
|
39
|
+
/** Dispatched when upload initialization fails */
|
|
40
|
+
static INITIALIZE_UPLOAD_FAILURE = "initializeUploadFailure";
|
|
41
|
+
/** Dispatched when a chunk upload starts */
|
|
42
|
+
static MEDIA_CHUNK_UPLOAD_STARTED = "mediaChunkUploadStarted";
|
|
43
|
+
/** Dispatched when a chunk is uploaded successfully */
|
|
44
|
+
static MEDIA_CHUNK_UPLOAD_SUCCESS = "mediaChunkUploadSuccess";
|
|
45
|
+
/** Dispatched when a chunk upload fails */
|
|
46
|
+
static MEDIA_CHUNK_UPLOAD_FAILED = "mediaChunkUploadFailed";
|
|
47
|
+
/** Dispatched when the server returns an HTTP error for a chunk */
|
|
48
|
+
static MEDIA_CHUNK_UPLOAD_HTTP_ERROR_RESPONSE = "mediaChunkUploadHttpErrorResponse";
|
|
49
|
+
/** Dispatched to provide the status of a chunk */
|
|
50
|
+
static MEDIA_CHUNK_UPLOAD_STATUS = "mediaChunkUploadStatus";
|
|
51
|
+
/** Dispatched when maximum retry attempts are exceeded for a chunk */
|
|
52
|
+
static MEDIA_CHUNK_UPLOAD_MAXRETRY_EXPIRE = "mediaChunkUploadMaxRetryExpire";
|
|
53
|
+
/** Dispatched when a chunk upload resumes */
|
|
54
|
+
static MEDIA_CHUNK_UPLOAD_RESUME = "mediaChunkUploadResume";
|
|
55
|
+
/** Dispatched when the upload is paused */
|
|
56
|
+
static UPLOAD_PAUSED = "uploadPaused";
|
|
57
|
+
/** Dispatched when the upload resumes after being paused */
|
|
58
|
+
static UPLOAD_RESUMED = "uploadResumed";
|
|
59
|
+
/** Dispatched when the upload is cancelled */
|
|
60
|
+
static UPLOAD_CANCELLED = "uploadCancelled";
|
|
61
|
+
/** Dispatched when the upload state changes */
|
|
62
|
+
static UPLOAD_STATE_CHANGED = "uploadStateChanged";
|
|
63
|
+
/** Dispatched when the upload completes successfully */
|
|
64
|
+
static DOWNLOAD_MEDIA_COMPLETE = "downloadMediaComplete";
|
|
65
|
+
/** Dispatched when the upload fails completely */
|
|
66
|
+
static DOWNLOAD_MEDIA_FAILURE = "downloadMediaFailure";
|
|
67
|
+
/** Dispatched when the upload resumes from a saved state */
|
|
68
|
+
static DOWNLOAD_MEDIA_RESUME = "downloadMediaResume";
|
|
69
|
+
static FINALIZE_UPLOAD = "finalizeUpload";
|
|
70
|
+
static FINALIZE_UPLOAD_FAILURE = "finalizeUploadFailure";
|
|
71
|
+
/** Dispatched when media metadata is saved successfully */
|
|
72
|
+
static MEDIA_METADATA_SAVE_SUCCESS = "mediaMetadataSaveSuccess";
|
|
73
|
+
constructor() {
|
|
74
|
+
throw new Error("HttpFileUploaderEvents is an abstract class and cannot be instantiated");
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
78
|
+
0 && (module.exports = {
|
|
79
|
+
HttpFileUploaderEvents,
|
|
80
|
+
...require("./initialize"),
|
|
81
|
+
...require("./state"),
|
|
82
|
+
...require("./chunk"),
|
|
83
|
+
...require("./complete")
|
|
84
|
+
});
|
|
85
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/events/index.ts"],"sourcesContent":["/*\n * This file is part of the project by AGBOKOUDJO Franck.\n *\n * (c) AGBOKOUDJO Franck <internationaleswebservices@gmail.com>\n * Phone: +229 0167 25 18 86\n * LinkedIn: https://www.linkedin.com/in/internationales-web-apps-services-120520193/\n * Company: INTERNATIONALES WEB APPS & SERVICES\n *\n * For more information, please feel free to contact the author.\n */\n\n/**\n * HttpFileUploaderEvents - Event Constants for File Upload Operations\n * \n * This abstract class provides a centralized collection of event name constants\n * used throughout the file upload lifecycle. It follows the Symfony event\n * dispatcher pattern, providing a type-safe way to reference events.\n * \n * The events are organized into five categories:\n * - **Initialize Events**: Events related to upload session initialization\n * - **Chunk Upload Events**: Events fired during individual chunk uploads\n * - **Upload State Events**: Events tracking upload state changes (pause, resume, cancel)\n * - **Completion Events**: Events fired when upload completes or fails\n * - **Metadata Events**: Events related to media metadata operations\n * \n * @example\n * ```typescript\n * import { HttpFileUploaderEvents } from '@wlindabla/file_uploader';\n * \n * // Listen to chunk upload success\n * dispatcher.addListener(\n * HttpFileUploaderEvents.MEDIA_CHUNK_UPLOAD_SUCCESS,\n * (event: ChunkUploadSuccessEvent) => {\n * console.log('Chunk uploaded:', event.progress);\n * }\n * );\n * \n * // Listen to upload state changes\n * dispatcher.addListener(\n * HttpFileUploaderEvents.UPLOAD_STATE_CHANGED,\n * (event: UploadStateChangedEvent) => {\n * console.log(`State changed: ${event.oldState} → ${event.newState}`);\n * }\n * );\n * ```\n * \n * @author AGBOKOUDJO Franck <internationaleswebservices@gmail.com>\n * @version 1.0.0\n * @since 1.0.0\n * \n * @see {@link https://github.com/Agbokoudjo/file_uploader | GitHub Repository}\n * @see {@link EventDispatcherInterface} for event dispatcher usage\n */\nexport abstract class HttpFileUploaderEvents {\n\n static readonly INITIALIZE_UPLOAD = \"initializingUpload\"\n \n /** Dispatched when upload initialization starts */\n static readonly INITIALIZE_UPLOAD_STARTED = \"initializeUploadStarted\";\n\n /** Dispatched when upload initialization succeeds */\n static readonly INITIALIZE_UPLOAD_SUCCESS = \"initializeUploadSuccess\";\n\n /** Dispatched when upload initialization fails */\n static readonly INITIALIZE_UPLOAD_FAILURE = \"initializeUploadFailure\";\n\n /** Dispatched when a chunk upload starts */\n static readonly MEDIA_CHUNK_UPLOAD_STARTED = \"mediaChunkUploadStarted\";\n\n /** Dispatched when a chunk is uploaded successfully */\n static readonly MEDIA_CHUNK_UPLOAD_SUCCESS = \"mediaChunkUploadSuccess\";\n\n /** Dispatched when a chunk upload fails */\n static readonly MEDIA_CHUNK_UPLOAD_FAILED = \"mediaChunkUploadFailed\";\n\n /** Dispatched when the server returns an HTTP error for a chunk */\n static readonly MEDIA_CHUNK_UPLOAD_HTTP_ERROR_RESPONSE = \"mediaChunkUploadHttpErrorResponse\";\n\n /** Dispatched to provide the status of a chunk */\n static readonly MEDIA_CHUNK_UPLOAD_STATUS = \"mediaChunkUploadStatus\";\n\n /** Dispatched when maximum retry attempts are exceeded for a chunk */\n static readonly MEDIA_CHUNK_UPLOAD_MAXRETRY_EXPIRE = \"mediaChunkUploadMaxRetryExpire\";\n\n /** Dispatched when a chunk upload resumes */\n static readonly MEDIA_CHUNK_UPLOAD_RESUME = \"mediaChunkUploadResume\";\n\n /** Dispatched when the upload is paused */\n static readonly UPLOAD_PAUSED = \"uploadPaused\";\n\n /** Dispatched when the upload resumes after being paused */\n static readonly UPLOAD_RESUMED = \"uploadResumed\";\n\n /** Dispatched when the upload is cancelled */\n static readonly UPLOAD_CANCELLED = \"uploadCancelled\";\n\n /** Dispatched when the upload state changes */\n static readonly UPLOAD_STATE_CHANGED = \"uploadStateChanged\";\n\n /** Dispatched when the upload completes successfully */\n static readonly DOWNLOAD_MEDIA_COMPLETE = \"downloadMediaComplete\";\n\n /** Dispatched when the upload fails completely */\n static readonly DOWNLOAD_MEDIA_FAILURE = \"downloadMediaFailure\";\n\n /** Dispatched when the upload resumes from a saved state */\n static readonly DOWNLOAD_MEDIA_RESUME = \"downloadMediaResume\";\n\n static readonly FINALIZE_UPLOAD = \"finalizeUpload\";\n\n static readonly FINALIZE_UPLOAD_FAILURE = \"finalizeUploadFailure\";\n\n /** Dispatched when media metadata is saved successfully */\n static readonly MEDIA_METADATA_SAVE_SUCCESS = \"mediaMetadataSaveSuccess\";\n\n private constructor() {\n // This class cannot be instantiated\n throw new Error('HttpFileUploaderEvents is an abstract class and cannot be instantiated');\n }\n}\n\nexport * from \"./initialize\"\nexport * from \"./state\";\nexport * from \"./chunk\";\nexport * from \"./complete\";"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAyHA,2BAAc,yBAzHd;AA0HA,2BAAc,oBA1Hd;AA2HA,2BAAc,oBA3Hd;AA4HA,2BAAc,uBA5Hd;AAqDO,MAAe,uBAAuB;AAAA,EArD7C,OAqD6C;AAAA;AAAA;AAAA,EAEzC,OAAgB,oBAAoB;AAAA;AAAA,EAGpC,OAAgB,4BAA4B;AAAA;AAAA,EAG5C,OAAgB,4BAA4B;AAAA;AAAA,EAG5C,OAAgB,4BAA4B;AAAA;AAAA,EAG5C,OAAgB,6BAA6B;AAAA;AAAA,EAG7C,OAAgB,6BAA6B;AAAA;AAAA,EAG7C,OAAgB,4BAA4B;AAAA;AAAA,EAG5C,OAAgB,yCAAyC;AAAA;AAAA,EAGzD,OAAgB,4BAA4B;AAAA;AAAA,EAG5C,OAAgB,qCAAqC;AAAA;AAAA,EAGrD,OAAgB,4BAA4B;AAAA;AAAA,EAG5C,OAAgB,gBAAgB;AAAA;AAAA,EAGhC,OAAgB,iBAAiB;AAAA;AAAA,EAGjC,OAAgB,mBAAmB;AAAA;AAAA,EAGnC,OAAgB,uBAAuB;AAAA;AAAA,EAGvC,OAAgB,0BAA0B;AAAA;AAAA,EAG1C,OAAgB,yBAAyB;AAAA;AAAA,EAGzC,OAAgB,wBAAwB;AAAA,EAExC,OAAgB,kBAAkB;AAAA,EAElC,OAAgB,0BAA0B;AAAA;AAAA,EAG1C,OAAgB,8BAA8B;AAAA,EAEtC,cAAc;AAElB,UAAM,IAAI,MAAM,wEAAwE;AAAA,EAC5F;AACJ;","names":[]}
|