@wlindabla/file_uploader 1.0.0 → 2.0.0
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 +51 -20
- 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 +267 -0
- package/dist/cjs/core/index.js +753 -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 +63 -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 +94 -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 +13 -0
- package/dist/cjs/index.js +33 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/subscribers/index.d.ts +33 -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/{subscribers/index.js → esm/chunk-332NNKOW.js} +36 -34
- package/dist/esm/chunk-332NNKOW.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/{core/index.js → esm/chunk-6DIKDA6J.js} +226 -227
- package/dist/esm/chunk-6DIKDA6J.js.map +1 -0
- package/dist/esm/chunk-7QVYU63E.js +6 -0
- package/dist/esm/chunk-7QVYU63E.js.map +1 -0
- package/dist/{events/initialize/index.js → esm/chunk-DN5B6PRW.js} +25 -19
- package/dist/esm/chunk-DN5B6PRW.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/{events/complete/index.js → esm/chunk-LTYMA4U4.js} +25 -19
- package/dist/{events/complete/index.js.map → esm/chunk-LTYMA4U4.js.map} +1 -1
- 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/{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 +267 -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 +63 -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 +94 -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 +13 -0
- package/dist/esm/index.js +14 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/subscribers/index.d.mts +33 -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/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,94 @@
|
|
|
1
|
+
export { InitializeUploadFailureEvent, InitializeUploadStartedEvent, InitializeUploadSuccessEvent, InitializingUploadEvent } from './initialize/index.mjs';
|
|
2
|
+
export { UploadCancelledEvent, UploadPausedEvent, UploadProgressEvent, UploadResumedEvent, UploadStateChangedEvent } from './state/index.mjs';
|
|
3
|
+
export { ChunkUploadHttpErrorResponseEvent, UploadChunkStartedEvent } from './chunk/index.mjs';
|
|
4
|
+
export { FinalizeUploadEvent, FinalizeUploadFailureEvent, ResumeUploadEvent, UploadMediaCompleteEvent } from './complete/index.mjs';
|
|
5
|
+
import '../types/index.mjs';
|
|
6
|
+
import '@wlindabla/http_client';
|
|
7
|
+
import '@wlindabla/event_dispatcher';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* HttpFileUploaderEvents - Event Constants for File Upload Operations
|
|
11
|
+
*
|
|
12
|
+
* This abstract class provides a centralized collection of event name constants
|
|
13
|
+
* used throughout the file upload lifecycle. It follows the Symfony event
|
|
14
|
+
* dispatcher pattern, providing a type-safe way to reference events.
|
|
15
|
+
*
|
|
16
|
+
* The events are organized into five categories:
|
|
17
|
+
* - **Initialize Events**: Events related to upload session initialization
|
|
18
|
+
* - **Chunk Upload Events**: Events fired during individual chunk uploads
|
|
19
|
+
* - **Upload State Events**: Events tracking upload state changes (pause, resume, cancel)
|
|
20
|
+
* - **Completion Events**: Events fired when upload completes or fails
|
|
21
|
+
* - **Metadata Events**: Events related to media metadata operations
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* ```typescript
|
|
25
|
+
* import { HttpFileUploaderEvents } from '@wlindabla/file_uploader';
|
|
26
|
+
*
|
|
27
|
+
* // Listen to chunk upload success
|
|
28
|
+
* dispatcher.addListener(
|
|
29
|
+
* HttpFileUploaderEvents.MEDIA_CHUNK_UPLOAD_SUCCESS,
|
|
30
|
+
* (event: ChunkUploadSuccessEvent) => {
|
|
31
|
+
* console.log('Chunk uploaded:', event.progress);
|
|
32
|
+
* }
|
|
33
|
+
* );
|
|
34
|
+
*
|
|
35
|
+
* // Listen to upload state changes
|
|
36
|
+
* dispatcher.addListener(
|
|
37
|
+
* HttpFileUploaderEvents.UPLOAD_STATE_CHANGED,
|
|
38
|
+
* (event: UploadStateChangedEvent) => {
|
|
39
|
+
* console.log(`State changed: ${event.oldState} → ${event.newState}`);
|
|
40
|
+
* }
|
|
41
|
+
* );
|
|
42
|
+
* ```
|
|
43
|
+
*
|
|
44
|
+
* @author AGBOKOUDJO Franck <internationaleswebservices@gmail.com>
|
|
45
|
+
* @version 1.0.0
|
|
46
|
+
* @since 1.0.0
|
|
47
|
+
*
|
|
48
|
+
* @see {@link https://github.com/Agbokoudjo/file_uploader | GitHub Repository}
|
|
49
|
+
* @see {@link EventDispatcherInterface} for event dispatcher usage
|
|
50
|
+
*/
|
|
51
|
+
declare abstract class HttpFileUploaderEvents {
|
|
52
|
+
static readonly INITIALIZE_UPLOAD = "initializingUpload";
|
|
53
|
+
/** Dispatched when upload initialization starts */
|
|
54
|
+
static readonly INITIALIZE_UPLOAD_STARTED = "initializeUploadStarted";
|
|
55
|
+
/** Dispatched when upload initialization succeeds */
|
|
56
|
+
static readonly INITIALIZE_UPLOAD_SUCCESS = "initializeUploadSuccess";
|
|
57
|
+
/** Dispatched when upload initialization fails */
|
|
58
|
+
static readonly INITIALIZE_UPLOAD_FAILURE = "initializeUploadFailure";
|
|
59
|
+
/** Dispatched when a chunk upload starts */
|
|
60
|
+
static readonly MEDIA_CHUNK_UPLOAD_STARTED = "mediaChunkUploadStarted";
|
|
61
|
+
/** Dispatched when a chunk is uploaded successfully */
|
|
62
|
+
static readonly MEDIA_CHUNK_UPLOAD_SUCCESS = "mediaChunkUploadSuccess";
|
|
63
|
+
/** Dispatched when a chunk upload fails */
|
|
64
|
+
static readonly MEDIA_CHUNK_UPLOAD_FAILED = "mediaChunkUploadFailed";
|
|
65
|
+
/** Dispatched when the server returns an HTTP error for a chunk */
|
|
66
|
+
static readonly MEDIA_CHUNK_UPLOAD_HTTP_ERROR_RESPONSE = "mediaChunkUploadHttpErrorResponse";
|
|
67
|
+
/** Dispatched to provide the status of a chunk */
|
|
68
|
+
static readonly MEDIA_CHUNK_UPLOAD_STATUS = "mediaChunkUploadStatus";
|
|
69
|
+
/** Dispatched when maximum retry attempts are exceeded for a chunk */
|
|
70
|
+
static readonly MEDIA_CHUNK_UPLOAD_MAXRETRY_EXPIRE = "mediaChunkUploadMaxRetryExpire";
|
|
71
|
+
/** Dispatched when a chunk upload resumes */
|
|
72
|
+
static readonly MEDIA_CHUNK_UPLOAD_RESUME = "mediaChunkUploadResume";
|
|
73
|
+
/** Dispatched when the upload is paused */
|
|
74
|
+
static readonly UPLOAD_PAUSED = "uploadPaused";
|
|
75
|
+
/** Dispatched when the upload resumes after being paused */
|
|
76
|
+
static readonly UPLOAD_RESUMED = "uploadResumed";
|
|
77
|
+
/** Dispatched when the upload is cancelled */
|
|
78
|
+
static readonly UPLOAD_CANCELLED = "uploadCancelled";
|
|
79
|
+
/** Dispatched when the upload state changes */
|
|
80
|
+
static readonly UPLOAD_STATE_CHANGED = "uploadStateChanged";
|
|
81
|
+
/** Dispatched when the upload completes successfully */
|
|
82
|
+
static readonly DOWNLOAD_MEDIA_COMPLETE = "downloadMediaComplete";
|
|
83
|
+
/** Dispatched when the upload fails completely */
|
|
84
|
+
static readonly DOWNLOAD_MEDIA_FAILURE = "downloadMediaFailure";
|
|
85
|
+
/** Dispatched when the upload resumes from a saved state */
|
|
86
|
+
static readonly DOWNLOAD_MEDIA_RESUME = "downloadMediaResume";
|
|
87
|
+
static readonly FINALIZE_UPLOAD = "finalizeUpload";
|
|
88
|
+
static readonly FINALIZE_UPLOAD_FAILURE = "finalizeUploadFailure";
|
|
89
|
+
/** Dispatched when media metadata is saved successfully */
|
|
90
|
+
static readonly MEDIA_METADATA_SAVE_SUCCESS = "mediaMetadataSaveSuccess";
|
|
91
|
+
private constructor();
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export { HttpFileUploaderEvents };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export { HttpFileUploaderEvents } from '../chunk-JDL3U4OX.js';
|
|
2
|
+
export { ChunkUploadHttpErrorResponseEvent, UploadChunkStartedEvent } from '../chunk-LD2DWZRJ.js';
|
|
3
|
+
export { FinalizeUploadEvent, FinalizeUploadFailureEvent, ResumeUploadEvent, UploadMediaCompleteEvent } from '../chunk-LTYMA4U4.js';
|
|
4
|
+
export { InitializeUploadFailureEvent, InitializeUploadStartedEvent, InitializeUploadSuccessEvent, InitializingUploadEvent } from '../chunk-DN5B6PRW.js';
|
|
5
|
+
export { UploadCancelledEvent, UploadPausedEvent, UploadProgressEvent, UploadResumedEvent, UploadStateChangedEvent } from '../chunk-6225YMFE.js';
|
|
6
|
+
import '../chunk-7QVYU63E.js';
|
|
7
|
+
//# sourceMappingURL=index.js.map
|
|
8
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"index.js"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { InitializeUploadOptions, InitializeUploadResponse } from '../../types/index.mjs';
|
|
2
|
+
import { BaseEvent } from '@wlindabla/event_dispatcher';
|
|
3
|
+
import '@wlindabla/http_client';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Event data for Upload State INITIALIZE
|
|
7
|
+
*/
|
|
8
|
+
declare class InitializingUploadEvent extends BaseEvent {
|
|
9
|
+
readonly initUploadOptions: InitializeUploadOptions;
|
|
10
|
+
private _mediaId;
|
|
11
|
+
constructor(initUploadOptions: InitializeUploadOptions);
|
|
12
|
+
setMediaId(_mediaUploadId: string): void;
|
|
13
|
+
get mediaId(): string;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Event data for INITIALIZE_UPLOAD_STARTED
|
|
17
|
+
*/
|
|
18
|
+
declare class InitializeUploadStartedEvent extends BaseEvent {
|
|
19
|
+
readonly fileName: string;
|
|
20
|
+
readonly fileSize: number;
|
|
21
|
+
readonly fileHash: string;
|
|
22
|
+
constructor(fileName: string, fileSize: number, fileHash: string);
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Event data for INITIALIZE_UPLOAD_SUCCESS
|
|
26
|
+
*/
|
|
27
|
+
declare class InitializeUploadSuccessEvent extends BaseEvent {
|
|
28
|
+
readonly status: number;
|
|
29
|
+
readonly sessionId: string;
|
|
30
|
+
readonly responseData: InitializeUploadResponse;
|
|
31
|
+
constructor(status: number, sessionId: string, responseData: InitializeUploadResponse);
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Event data for INITIALIZE_UPLOAD_FAILURE
|
|
35
|
+
*/
|
|
36
|
+
declare class InitializeUploadFailureEvent extends BaseEvent {
|
|
37
|
+
readonly error: Error;
|
|
38
|
+
readonly status?: number | undefined;
|
|
39
|
+
readonly errorData?: any | undefined;
|
|
40
|
+
readonly responseData?: any | undefined;
|
|
41
|
+
readonly isNetworkError?: boolean | undefined;
|
|
42
|
+
constructor(error: Error, status?: number | undefined, errorData?: any | undefined, responseData?: any | undefined, isNetworkError?: boolean | undefined);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export { InitializeUploadFailureEvent, InitializeUploadStartedEvent, InitializeUploadSuccessEvent, InitializingUploadEvent };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"index.js"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { UploadProgress, UploadState } from '../../types/index.mjs';
|
|
2
|
+
import '@wlindabla/http_client';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Event data for UPLOAD_STATE_CHANGED
|
|
6
|
+
*/
|
|
7
|
+
declare class UploadStateChangedEvent {
|
|
8
|
+
readonly oldState: UploadState;
|
|
9
|
+
readonly newState: UploadState;
|
|
10
|
+
readonly changedAt: number;
|
|
11
|
+
constructor(oldState: UploadState, newState: UploadState, changedAt?: number);
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Event data for UPLOAD_CANCELLED
|
|
15
|
+
*/
|
|
16
|
+
declare class UploadCancelledEvent {
|
|
17
|
+
readonly mediaName: string;
|
|
18
|
+
readonly totalChunks: number;
|
|
19
|
+
readonly uploadedBytes: number;
|
|
20
|
+
readonly percentage: number;
|
|
21
|
+
readonly currentChunkIndex: number;
|
|
22
|
+
readonly message: string;
|
|
23
|
+
readonly cancelledAt: number;
|
|
24
|
+
constructor(mediaName: string, totalChunks: number, uploadedBytes: number, percentage: number, currentChunkIndex: number, message?: string, cancelledAt?: number);
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Event data for UPLOAD_RESUMED
|
|
28
|
+
*/
|
|
29
|
+
declare class UploadResumedEvent {
|
|
30
|
+
readonly mediaName: string;
|
|
31
|
+
readonly totalChunks: number;
|
|
32
|
+
readonly uploadedBytes: number;
|
|
33
|
+
readonly percentage: number;
|
|
34
|
+
readonly resumedAt: number;
|
|
35
|
+
constructor(mediaName: string, totalChunks: number, uploadedBytes: number, percentage: number, resumedAt?: number);
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Event data for UPLOAD_PAUSED
|
|
39
|
+
*/
|
|
40
|
+
declare class UploadPausedEvent {
|
|
41
|
+
readonly mediaName: string;
|
|
42
|
+
readonly totalChunks: number;
|
|
43
|
+
readonly uploadedBytes: number;
|
|
44
|
+
readonly percentage: number;
|
|
45
|
+
readonly pausedAt: number;
|
|
46
|
+
constructor(mediaName: string, totalChunks: number, uploadedBytes: number, percentage: number, pausedAt?: number);
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Event data for MEDIA_CHUNK_UPLOAD_SUCCESS
|
|
50
|
+
*/
|
|
51
|
+
declare class UploadProgressEvent {
|
|
52
|
+
private readonly uploadProgress;
|
|
53
|
+
readonly responseData: string | Record<string, string | any> | unknown;
|
|
54
|
+
readonly httpStatus: number;
|
|
55
|
+
constructor(uploadProgress: UploadProgress, responseData: string | Record<string, string | any> | unknown, httpStatus: number);
|
|
56
|
+
get uploadedChunks(): number;
|
|
57
|
+
get totalChunks(): number;
|
|
58
|
+
get percentage(): number;
|
|
59
|
+
get uploadedBytes(): number;
|
|
60
|
+
get totalBytes(): number;
|
|
61
|
+
get currentChunk(): number;
|
|
62
|
+
get speed(): number | undefined;
|
|
63
|
+
get estimatedTimeRemaining(): number | undefined | null;
|
|
64
|
+
get elapsed(): number;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export { UploadCancelledEvent, UploadPausedEvent, UploadProgressEvent, UploadResumedEvent, UploadStateChangedEvent };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"index.js"}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { ChunkError, ChunkInfo } from '../types/index.mjs';
|
|
2
|
+
import '@wlindabla/http_client';
|
|
3
|
+
|
|
4
|
+
declare class InitializeUploadFailureException extends Error {
|
|
5
|
+
readonly responseData: any;
|
|
6
|
+
constructor(responseData: any, message: string);
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Exception data for MEDIA_CHUNK_UPLOAD_HTTP_ERROR_RESPONSE
|
|
10
|
+
*/
|
|
11
|
+
declare class ChunkUploadHttpErrorException extends Error {
|
|
12
|
+
readonly errorPayload: string | Record<string, string | unknown> | unknown;
|
|
13
|
+
readonly statusResponse: number;
|
|
14
|
+
constructor(errorPayload: string | Record<string, string | unknown> | unknown, statusResponse: number);
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Custom error thrown during chunked file upload operations.
|
|
18
|
+
*
|
|
19
|
+
* This error provides detailed information about which chunk failed,
|
|
20
|
+
* the underlying error, and whether a retry will be attempted.
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* ```typescript
|
|
24
|
+
* try {
|
|
25
|
+
* await uploadChunk(chunk);
|
|
26
|
+
* } catch (error) {
|
|
27
|
+
* throw new FileUploadChunkError(
|
|
28
|
+
* `Failed to upload chunk ${chunkIndex}`,
|
|
29
|
+
* chunkError
|
|
30
|
+
* );
|
|
31
|
+
* }
|
|
32
|
+
*
|
|
33
|
+
* // Later in error handler
|
|
34
|
+
* if (error instanceof FileUploadChunkError) {
|
|
35
|
+
* console.log(`Chunk ${error.chunkIndex} failed`);
|
|
36
|
+
* console.log(`Will retry: ${error.willRetry}`);
|
|
37
|
+
* }
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
declare class FileUploadChunkError extends Error {
|
|
41
|
+
/**
|
|
42
|
+
* The detailed chunk error information
|
|
43
|
+
*/
|
|
44
|
+
readonly chunkError: ChunkError;
|
|
45
|
+
/**
|
|
46
|
+
* Creates a new FileUploadChunkError
|
|
47
|
+
*
|
|
48
|
+
* @param message - Human-readable error message
|
|
49
|
+
* @param chunkError - Detailed information about the chunk failure
|
|
50
|
+
*/
|
|
51
|
+
constructor(message: string, chunkError: ChunkError);
|
|
52
|
+
/**
|
|
53
|
+
* Gets the index of the chunk that failed
|
|
54
|
+
*/
|
|
55
|
+
get chunkIndex(): number;
|
|
56
|
+
/**
|
|
57
|
+
* Gets the attempt number when the chunk failed
|
|
58
|
+
*/
|
|
59
|
+
get attemptNumber(): number;
|
|
60
|
+
/**
|
|
61
|
+
* Indicates whether a retry will be attempted
|
|
62
|
+
*/
|
|
63
|
+
get willRetry(): boolean;
|
|
64
|
+
/**
|
|
65
|
+
* Gets the underlying error that caused the chunk upload to fail
|
|
66
|
+
*/
|
|
67
|
+
get underlyingError(): Error;
|
|
68
|
+
/**
|
|
69
|
+
* Gets the full chunk information
|
|
70
|
+
*/
|
|
71
|
+
get chunk(): ChunkInfo;
|
|
72
|
+
/**
|
|
73
|
+
* Returns a JSON representation of the error
|
|
74
|
+
*/
|
|
75
|
+
toJSON(): object;
|
|
76
|
+
}
|
|
77
|
+
declare class UploadCancelledException extends Error {
|
|
78
|
+
readonly chunkIndex: number;
|
|
79
|
+
readonly totalChunks: number;
|
|
80
|
+
readonly uploadedBytes: number;
|
|
81
|
+
constructor(chunkIndex: number, totalChunks: number, uploadedBytes: number, message: string);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export { ChunkUploadHttpErrorException, FileUploadChunkError, InitializeUploadFailureException, UploadCancelledException };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"index.js"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export { ChunkError, ChunkInfo, ChunkSizeConfig, DEFAULT_CONFIG, InitializeUploadOptions, InitializeUploadResponse, ResumeData, UploadEndpoints, UploadOptions, UploadProgress, UploadResult, UploadState, UploadStatus } from './types/index.mjs';
|
|
2
|
+
export { ChunkFormDataBuilder, ChunkFormDataOptions, ExponentialBackoffStrategy, FileUtils, LinearBackoffStrategy, createChunkFormData, updateProgressBarHTMLNotified } from './utils/index.mjs';
|
|
3
|
+
export { ChunkUploadHttpErrorException, FileUploadChunkError, InitializeUploadFailureException, UploadCancelledException } from './exceptions/index.mjs';
|
|
4
|
+
export { HttpFileUploaderEvents } from './events/index.mjs';
|
|
5
|
+
export { FinalizeUploadSubscriber, InitializeUploadSubscriber } from './subscribers/index.mjs';
|
|
6
|
+
export { DefaultUploadResumeCacheAdapter, UploadCacheError, UploadResumeCacheInterface } from './cache/index.mjs';
|
|
7
|
+
export { ChunkedFileUploader } from './core/index.mjs';
|
|
8
|
+
export { ChunkUploadHttpErrorResponseEvent, UploadChunkStartedEvent } from './events/chunk/index.mjs';
|
|
9
|
+
export { FinalizeUploadEvent, FinalizeUploadFailureEvent, ResumeUploadEvent, UploadMediaCompleteEvent } from './events/complete/index.mjs';
|
|
10
|
+
export { InitializeUploadFailureEvent, InitializeUploadStartedEvent, InitializeUploadSuccessEvent, InitializingUploadEvent } from './events/initialize/index.mjs';
|
|
11
|
+
export { UploadCancelledEvent, UploadPausedEvent, UploadProgressEvent, UploadResumedEvent, UploadStateChangedEvent } from './events/state/index.mjs';
|
|
12
|
+
import '@wlindabla/http_client';
|
|
13
|
+
import '@wlindabla/event_dispatcher';
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export { FinalizeUploadSubscriber, InitializeUploadSubscriber } from './chunk-332NNKOW.js';
|
|
2
|
+
export { DefaultUploadResumeCacheAdapter, UploadCacheError } from './chunk-PFALORWQ.js';
|
|
3
|
+
export { ChunkedFileUploader } from './chunk-6DIKDA6J.js';
|
|
4
|
+
export { ChunkUploadHttpErrorException, FileUploadChunkError, InitializeUploadFailureException, UploadCancelledException } from './chunk-NXYS73I4.js';
|
|
5
|
+
export { ChunkFormDataBuilder, ExponentialBackoffStrategy, FileUtils, LinearBackoffStrategy, createChunkFormData, updateProgressBarHTMLNotified } from './chunk-MFYC4PBP.js';
|
|
6
|
+
import './chunk-X757PBC5.js';
|
|
7
|
+
export { HttpFileUploaderEvents } from './chunk-JDL3U4OX.js';
|
|
8
|
+
export { ChunkUploadHttpErrorResponseEvent, UploadChunkStartedEvent } from './chunk-LD2DWZRJ.js';
|
|
9
|
+
export { FinalizeUploadEvent, FinalizeUploadFailureEvent, ResumeUploadEvent, UploadMediaCompleteEvent } from './chunk-LTYMA4U4.js';
|
|
10
|
+
export { InitializeUploadFailureEvent, InitializeUploadStartedEvent, InitializeUploadSuccessEvent, InitializingUploadEvent } from './chunk-DN5B6PRW.js';
|
|
11
|
+
export { UploadCancelledEvent, UploadPausedEvent, UploadProgressEvent, UploadResumedEvent, UploadStateChangedEvent } from './chunk-6225YMFE.js';
|
|
12
|
+
import './chunk-7QVYU63E.js';
|
|
13
|
+
//# sourceMappingURL=index.js.map
|
|
14
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"index.js"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { EventSubscriberInterface, EventDispatcherInterface } from '@wlindabla/event_dispatcher';
|
|
2
|
+
import { InitializingUploadEvent } from '../events/initialize/index.mjs';
|
|
3
|
+
import { FinalizeUploadEvent } from '../events/complete/index.mjs';
|
|
4
|
+
import '../types/index.mjs';
|
|
5
|
+
import '@wlindabla/http_client';
|
|
6
|
+
|
|
7
|
+
declare class InitializeUploadSubscriber implements EventSubscriberInterface {
|
|
8
|
+
private readonly eventDispatcher;
|
|
9
|
+
constructor(eventDispatcher: EventDispatcherInterface);
|
|
10
|
+
getSubscribedEvents(): Record<string, string | {
|
|
11
|
+
listener: string;
|
|
12
|
+
priority?: number | undefined;
|
|
13
|
+
}>;
|
|
14
|
+
/**
|
|
15
|
+
* Initializes upload session with the server.
|
|
16
|
+
*
|
|
17
|
+
* @param fileHash - SHA-256 hash of the file (first 1MB)
|
|
18
|
+
* @returns Session ID from server, or null if initialization failed
|
|
19
|
+
* @throws {FileUploadInitializationError} If server returns error or network fails
|
|
20
|
+
*/
|
|
21
|
+
onInitializeUpload(event: InitializingUploadEvent): Promise<void>;
|
|
22
|
+
}
|
|
23
|
+
declare class FinalizeUploadSubscriber implements EventSubscriberInterface {
|
|
24
|
+
private readonly eventDispatcher;
|
|
25
|
+
constructor(eventDispatcher: EventDispatcherInterface);
|
|
26
|
+
getSubscribedEvents(): Record<string, string | {
|
|
27
|
+
listener: string;
|
|
28
|
+
priority?: number | undefined;
|
|
29
|
+
}>;
|
|
30
|
+
onFinalizeUpload(event: FinalizeUploadEvent): Promise<void>;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export { FinalizeUploadSubscriber, InitializeUploadSubscriber };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export { FinalizeUploadSubscriber, InitializeUploadSubscriber } from '../chunk-332NNKOW.js';
|
|
2
|
+
import '../chunk-NXYS73I4.js';
|
|
3
|
+
import '../chunk-JDL3U4OX.js';
|
|
4
|
+
import '../chunk-LD2DWZRJ.js';
|
|
5
|
+
import '../chunk-LTYMA4U4.js';
|
|
6
|
+
import '../chunk-DN5B6PRW.js';
|
|
7
|
+
import '../chunk-6225YMFE.js';
|
|
8
|
+
import '../chunk-7QVYU63E.js';
|
|
9
|
+
//# sourceMappingURL=index.js.map
|
|
10
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"index.js"}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { FetchResponseInterface } from '@wlindabla/http_client';
|
|
2
|
+
|
|
3
|
+
interface UploadOptions {
|
|
4
|
+
autoSave?: boolean;
|
|
5
|
+
chunkSize?: number;
|
|
6
|
+
speedMbps?: number;
|
|
7
|
+
config?: ChunkSizeConfig;
|
|
8
|
+
headers?: HeadersInit;
|
|
9
|
+
chunkOtherData?: Record<string, any>;
|
|
10
|
+
metadata?: Record<string, any>;
|
|
11
|
+
maxRetries?: number;
|
|
12
|
+
timeout?: number;
|
|
13
|
+
initTimeout?: number;
|
|
14
|
+
headerInitialzingUpload?: HeadersInit;
|
|
15
|
+
headerFinalezingUpload?: HeadersInit;
|
|
16
|
+
concurrency?: number;
|
|
17
|
+
}
|
|
18
|
+
interface InitializeUploadOptions {
|
|
19
|
+
metadata?: Record<string, any>;
|
|
20
|
+
fileHash: string;
|
|
21
|
+
fileName: string;
|
|
22
|
+
fileSize: number;
|
|
23
|
+
fileType: string;
|
|
24
|
+
endpointInit: string | URL;
|
|
25
|
+
headers?: HeadersInit;
|
|
26
|
+
}
|
|
27
|
+
interface UploadEndpoints {
|
|
28
|
+
init: string | URL;
|
|
29
|
+
upload: string | URL;
|
|
30
|
+
finalize: string | URL;
|
|
31
|
+
}
|
|
32
|
+
interface ChunkSizeConfig {
|
|
33
|
+
defaultChunkSizeMB: number;
|
|
34
|
+
slowSpeedThresholdMbps: number;
|
|
35
|
+
slowSpeedChunkSizeMB: number;
|
|
36
|
+
fileSizeThresholds: Array<{
|
|
37
|
+
maxSizeMB: number;
|
|
38
|
+
chunkSizeMB: number;
|
|
39
|
+
}>;
|
|
40
|
+
}
|
|
41
|
+
type UploadStatus = 'pending' | 'uploading' | 'success' | 'error';
|
|
42
|
+
interface ChunkInfo {
|
|
43
|
+
index: number;
|
|
44
|
+
start: number;
|
|
45
|
+
end: number;
|
|
46
|
+
size: number;
|
|
47
|
+
attempt: number;
|
|
48
|
+
status: UploadStatus;
|
|
49
|
+
}
|
|
50
|
+
declare enum UploadState {
|
|
51
|
+
IDLE = "idle",
|
|
52
|
+
INITIALIZING = "initializing",
|
|
53
|
+
UPLOADING = "uploading",
|
|
54
|
+
PAUSED = "paused",
|
|
55
|
+
CANCELLED = "cancelled",
|
|
56
|
+
FINALIZING = "finalizing",
|
|
57
|
+
COMPLETED = "completed",
|
|
58
|
+
FAILED = "failed"
|
|
59
|
+
}
|
|
60
|
+
interface UploadResult {
|
|
61
|
+
success: boolean;
|
|
62
|
+
fileId?: string;
|
|
63
|
+
totalChunks: number;
|
|
64
|
+
totalBytes: number;
|
|
65
|
+
duration: number;
|
|
66
|
+
averageSpeed: number;
|
|
67
|
+
finalizeUploadResponse?: FetchResponseInterface | null;
|
|
68
|
+
statusResponse?: number;
|
|
69
|
+
}
|
|
70
|
+
interface ResumeData {
|
|
71
|
+
fileId: string;
|
|
72
|
+
fileName: string;
|
|
73
|
+
fileSize: number;
|
|
74
|
+
uploadedChunks: number;
|
|
75
|
+
lastChunkIndex: number;
|
|
76
|
+
lastBytePosition: number;
|
|
77
|
+
chunkSize: number;
|
|
78
|
+
concurrency: number;
|
|
79
|
+
}
|
|
80
|
+
declare const DEFAULT_CONFIG: Readonly<ChunkSizeConfig>;
|
|
81
|
+
interface UploadProgress {
|
|
82
|
+
uploadedChunks: number;
|
|
83
|
+
totalChunks: number;
|
|
84
|
+
uploadedBytes: number;
|
|
85
|
+
totalBytes: number;
|
|
86
|
+
percentage: number;
|
|
87
|
+
currentChunk: number;
|
|
88
|
+
speed?: number;
|
|
89
|
+
estimatedTimeRemaining?: number | null;
|
|
90
|
+
elapsed: number;
|
|
91
|
+
}
|
|
92
|
+
interface ChunkError {
|
|
93
|
+
chunk: ChunkInfo;
|
|
94
|
+
error: Error;
|
|
95
|
+
attempt: number;
|
|
96
|
+
willRetry: boolean;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Expected response structure from initialize endpoint
|
|
100
|
+
*/
|
|
101
|
+
interface InitializeUploadResponse {
|
|
102
|
+
mediaIdFromServer?: string | number;
|
|
103
|
+
sessionId?: string | number;
|
|
104
|
+
uploadId?: string | number;
|
|
105
|
+
mediaId?: string | number;
|
|
106
|
+
message?: string | number;
|
|
107
|
+
[key: string]: any;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
export { type ChunkError, type ChunkInfo, type ChunkSizeConfig, DEFAULT_CONFIG, type InitializeUploadOptions, type InitializeUploadResponse, type ResumeData, type UploadEndpoints, type UploadOptions, type UploadProgress, type UploadResult, UploadState, type UploadStatus };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"index.js"}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { ChunkSizeConfig } from '../types/index.mjs';
|
|
2
|
+
import '@wlindabla/http_client';
|
|
3
|
+
|
|
4
|
+
declare class FileUtils {
|
|
5
|
+
static readonly MB: number;
|
|
6
|
+
static readonly GB: number;
|
|
7
|
+
static bytesToMB(bytes: number): number;
|
|
8
|
+
static bytesToGB(bytes: number): number;
|
|
9
|
+
static formatBytes(bytes: number): string;
|
|
10
|
+
static formatDuration(seconds: number): string;
|
|
11
|
+
static calculateChunkSize(fileSize: number, speedMbps?: number, config?: ChunkSizeConfig): number;
|
|
12
|
+
static generateFileHash(file: File | Blob): Promise<string>;
|
|
13
|
+
}
|
|
14
|
+
declare function updateProgressBarHTMLNotified(progress: number, media_id: number, filename: string, providerName?: string): string;
|
|
15
|
+
/**
|
|
16
|
+
* Options for creating chunk FormData
|
|
17
|
+
*/
|
|
18
|
+
interface ChunkFormDataOptions {
|
|
19
|
+
chunkIndex: number;
|
|
20
|
+
totalChunks: number;
|
|
21
|
+
mediaId: string;
|
|
22
|
+
fileName: string;
|
|
23
|
+
fileSize: number;
|
|
24
|
+
fileHash: string;
|
|
25
|
+
metadata?: Record<string, string | Blob>;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Creates FormData for uploading a single file chunk.
|
|
29
|
+
*
|
|
30
|
+
* @param chunk - The chunk blob to upload
|
|
31
|
+
* @param options - Chunk upload options
|
|
32
|
+
* @returns FormData ready to be sent to the server
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* ```typescript
|
|
36
|
+
* const formData = createChunkFormData(blob, {
|
|
37
|
+
* chunkIndex: 5,
|
|
38
|
+
* totalChunks: 10,
|
|
39
|
+
* mediaId: 'abc123',
|
|
40
|
+
* fileName: 'video.mp4',
|
|
41
|
+
* fileSize: 104857600,
|
|
42
|
+
* fileHash: 'sha256...'
|
|
43
|
+
* });
|
|
44
|
+
* ```
|
|
45
|
+
*/
|
|
46
|
+
declare function createChunkFormData(chunk: Blob, options: ChunkFormDataOptions): FormData;
|
|
47
|
+
/**
|
|
48
|
+
* Builder pattern for creating chunk FormData with fluent API.
|
|
49
|
+
*/
|
|
50
|
+
declare class ChunkFormDataBuilder {
|
|
51
|
+
private formData;
|
|
52
|
+
constructor(chunk: Blob);
|
|
53
|
+
withChunkInfo(chunkIndex: number, totalChunks: number): this;
|
|
54
|
+
withFileInfo(fileName: string, fileSize: number, fileHash: string): this;
|
|
55
|
+
withSessionId(sessionId: string): this;
|
|
56
|
+
withMetadata(metadata: Record<string, string | Blob>): this;
|
|
57
|
+
build(): FormData;
|
|
58
|
+
}
|
|
59
|
+
interface RetryStrategyInterface {
|
|
60
|
+
shouldRetry(attempt: number, maxRetries: number, error: Error): boolean;
|
|
61
|
+
getDelay(attempt: number): number;
|
|
62
|
+
}
|
|
63
|
+
declare class ExponentialBackoffStrategy implements RetryStrategyInterface {
|
|
64
|
+
shouldRetry(attempt: number, maxRetries: number): boolean;
|
|
65
|
+
getDelay(attempt: number): number;
|
|
66
|
+
}
|
|
67
|
+
declare class LinearBackoffStrategy implements RetryStrategyInterface {
|
|
68
|
+
shouldRetry(attempt: number, maxRetries: number): boolean;
|
|
69
|
+
getDelay(attempt: number): number;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export { ChunkFormDataBuilder, type ChunkFormDataOptions, ExponentialBackoffStrategy, FileUtils, LinearBackoffStrategy, createChunkFormData, updateProgressBarHTMLNotified };
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { ChunkFormDataBuilder, ExponentialBackoffStrategy, FileUtils, LinearBackoffStrategy, createChunkFormData, updateProgressBarHTMLNotified } from '../chunk-MFYC4PBP.js';
|
|
2
|
+
import '../chunk-X757PBC5.js';
|
|
3
|
+
import '../chunk-7QVYU63E.js';
|
|
4
|
+
//# sourceMappingURL=index.js.map
|
|
5
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"index.js"}
|