UNPKG

3.02 kBTypeScriptView Raw
1/// <reference types="node" />
2import { UploadPartCommandInput, S3Client, PutObjectCommandInput } from '@aws-sdk/client-s3';
3import * as events from 'events';
4import { Canceler } from 'axios';
5import { UploadTask } from '../types/Provider';
6import { StorageAccessLevel } from '..';
7export declare enum AWSS3UploadTaskState {
8 INIT = 0,
9 IN_PROGRESS = 1,
10 PAUSED = 2,
11 CANCELLED = 3,
12 COMPLETED = 4
13}
14export declare enum TaskEvents {
15 CANCEL = "cancel",
16 UPLOAD_COMPLETE = "uploadComplete",
17 UPLOAD_PROGRESS = "uploadPartProgress",
18 ERROR = "error"
19}
20export interface AWSS3UploadTaskParams {
21 s3Client: S3Client;
22 file: Blob;
23 storage: Storage;
24 level: StorageAccessLevel;
25 params: PutObjectCommandInput;
26 prefixPromise: Promise<string>;
27 emitter?: events.EventEmitter;
28}
29export interface InProgressRequest {
30 uploadPartInput: UploadPartCommandInput;
31 s3Request: Promise<any>;
32 cancel: Canceler;
33}
34export interface UploadTaskCompleteEvent {
35 key?: string;
36}
37export interface UploadTaskProgressEvent {
38 /**
39 * bytes that has been sent to S3 so far
40 */
41 loaded: number;
42 /**
43 * total bytes that needs to be sent to S3
44 */
45 total: number;
46}
47export interface FileMetadata {
48 bucket: string;
49 fileName: string;
50 key: string;
51 lastTouched: number;
52 uploadId: string;
53}
54export declare class AWSS3UploadTask implements UploadTask {
55 private readonly emitter;
56 private readonly file;
57 private readonly queueSize;
58 private readonly s3client;
59 private readonly storage;
60 private readonly storageSync;
61 private readonly fileId;
62 private readonly params;
63 private readonly prefixPromise;
64 private partSize;
65 private inProgress;
66 private completedParts;
67 private queued;
68 private bytesUploaded;
69 private totalBytes;
70 private uploadId;
71 state: AWSS3UploadTaskState;
72 constructor({ s3Client, file, emitter, storage, params, level, prefixPromise, }: AWSS3UploadTaskParams);
73 get percent(): number;
74 get isInProgress(): boolean;
75 private _listSingleFile;
76 private _getFileId;
77 private _findCachedUploadParts;
78 private _emitEvent;
79 private _validateParams;
80 private _listCachedUploadTasks;
81 private _cache;
82 private _isCached;
83 private _removeFromCache;
84 private _onPartUploadCompletion;
85 private _completeUpload;
86 private _makeUploadPartRequest;
87 private _startNextPart;
88 /**
89 * Verify on S3 side that the file size matches the one on the client side.
90 *
91 * @async
92 * @throws throws an error if the file size does not match between local copy of the file and the file on s3.
93 */
94 private _verifyFileSize;
95 private _isDone;
96 private _createParts;
97 private _initCachedUploadParts;
98 private _initMultipartUpload;
99 private _initializeUploadTask;
100 resume(): void;
101 private _startUpload;
102 _cancel(): Promise<boolean>;
103 /**
104 * pause this particular upload task
105 **/
106 pause(): void;
107}