express-storage 1.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/LICENSE +21 -0
- package/README.md +490 -0
- package/dist/drivers/base.driver.d.ts +69 -0
- package/dist/drivers/base.driver.d.ts.map +1 -0
- package/dist/drivers/base.driver.js +161 -0
- package/dist/drivers/base.driver.js.map +1 -0
- package/dist/drivers/gcs.driver.d.ts +39 -0
- package/dist/drivers/gcs.driver.d.ts.map +1 -0
- package/dist/drivers/gcs.driver.js +126 -0
- package/dist/drivers/gcs.driver.js.map +1 -0
- package/dist/drivers/local.driver.d.ts +30 -0
- package/dist/drivers/local.driver.d.ts.map +1 -0
- package/dist/drivers/local.driver.js +102 -0
- package/dist/drivers/local.driver.js.map +1 -0
- package/dist/drivers/oci.driver.d.ts +37 -0
- package/dist/drivers/oci.driver.d.ts.map +1 -0
- package/dist/drivers/oci.driver.js +84 -0
- package/dist/drivers/oci.driver.js.map +1 -0
- package/dist/drivers/s3.driver.d.ts +38 -0
- package/dist/drivers/s3.driver.d.ts.map +1 -0
- package/dist/drivers/s3.driver.js +135 -0
- package/dist/drivers/s3.driver.js.map +1 -0
- package/dist/factory/driver.factory.d.ts +56 -0
- package/dist/factory/driver.factory.d.ts.map +1 -0
- package/dist/factory/driver.factory.js +117 -0
- package/dist/factory/driver.factory.js.map +1 -0
- package/dist/index.d.ts +29 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +53 -0
- package/dist/index.js.map +1 -0
- package/dist/storage-manager.d.ts +75 -0
- package/dist/storage-manager.d.ts.map +1 -0
- package/dist/storage-manager.js +144 -0
- package/dist/storage-manager.js.map +1 -0
- package/dist/types/storage.types.d.ts +70 -0
- package/dist/types/storage.types.d.ts.map +1 -0
- package/dist/types/storage.types.js +2 -0
- package/dist/types/storage.types.js.map +1 -0
- package/dist/utils/config.utils.d.ts +21 -0
- package/dist/utils/config.utils.d.ts.map +1 -0
- package/dist/utils/config.utils.js +128 -0
- package/dist/utils/config.utils.js.map +1 -0
- package/dist/utils/file.utils.d.ts +45 -0
- package/dist/utils/file.utils.d.ts.map +1 -0
- package/dist/utils/file.utils.js +95 -0
- package/dist/utils/file.utils.js.map +1 -0
- package/package.json +82 -0
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import { S3Client, PutObjectCommand, DeleteObjectCommand, GetObjectCommand } from '@aws-sdk/client-s3';
|
|
2
|
+
import { getSignedUrl } from '@aws-sdk/s3-request-presigner';
|
|
3
|
+
import { BaseStorageDriver } from './base.driver.js';
|
|
4
|
+
/**
|
|
5
|
+
* AWS S3 storage driver
|
|
6
|
+
*/
|
|
7
|
+
export class S3StorageDriver extends BaseStorageDriver {
|
|
8
|
+
constructor(config) {
|
|
9
|
+
super(config);
|
|
10
|
+
this.bucketName = config.bucketName;
|
|
11
|
+
this.region = config.awsRegion;
|
|
12
|
+
this.s3Client = new S3Client({
|
|
13
|
+
region: this.region,
|
|
14
|
+
credentials: {
|
|
15
|
+
accessKeyId: config.awsAccessKey,
|
|
16
|
+
secretAccessKey: config.awsSecretKey,
|
|
17
|
+
},
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Upload file to S3
|
|
22
|
+
*/
|
|
23
|
+
async upload(file) {
|
|
24
|
+
try {
|
|
25
|
+
// Validate file
|
|
26
|
+
const validationErrors = this.validateFile(file);
|
|
27
|
+
if (validationErrors.length > 0) {
|
|
28
|
+
return this.createErrorResult(validationErrors.join(', '));
|
|
29
|
+
}
|
|
30
|
+
// Generate unique filename
|
|
31
|
+
const fileName = this.generateFileName(file.originalname);
|
|
32
|
+
// Create S3 upload command
|
|
33
|
+
const uploadCommand = new PutObjectCommand({
|
|
34
|
+
Bucket: this.bucketName,
|
|
35
|
+
Key: fileName,
|
|
36
|
+
Body: file.buffer,
|
|
37
|
+
ContentType: file.mimetype,
|
|
38
|
+
ContentLength: file.size,
|
|
39
|
+
});
|
|
40
|
+
// Upload to S3
|
|
41
|
+
await this.s3Client.send(uploadCommand);
|
|
42
|
+
// Generate file URL
|
|
43
|
+
const fileUrl = `https://${this.bucketName}.s3.${this.region}.amazonaws.com/${fileName}`;
|
|
44
|
+
return this.createSuccessResult(fileName, fileUrl);
|
|
45
|
+
}
|
|
46
|
+
catch (error) {
|
|
47
|
+
return this.createErrorResult(error instanceof Error ? error.message : 'Failed to upload file to S3');
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Generate presigned upload URL
|
|
52
|
+
*/
|
|
53
|
+
async generateUploadUrl(fileName) {
|
|
54
|
+
try {
|
|
55
|
+
const uploadCommand = new PutObjectCommand({
|
|
56
|
+
Bucket: this.bucketName,
|
|
57
|
+
Key: fileName,
|
|
58
|
+
ContentType: 'application/octet-stream',
|
|
59
|
+
});
|
|
60
|
+
const uploadUrl = await getSignedUrl(this.s3Client, uploadCommand, {
|
|
61
|
+
expiresIn: this.getPresignedUrlExpiry(),
|
|
62
|
+
});
|
|
63
|
+
return this.createPresignedSuccessResult(uploadUrl);
|
|
64
|
+
}
|
|
65
|
+
catch (error) {
|
|
66
|
+
return this.createPresignedErrorResult(error instanceof Error ? error.message : 'Failed to generate upload URL');
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Generate presigned view URL
|
|
71
|
+
*/
|
|
72
|
+
async generateViewUrl(fileName) {
|
|
73
|
+
try {
|
|
74
|
+
const getCommand = new GetObjectCommand({
|
|
75
|
+
Bucket: this.bucketName,
|
|
76
|
+
Key: fileName,
|
|
77
|
+
});
|
|
78
|
+
const viewUrl = await getSignedUrl(this.s3Client, getCommand, {
|
|
79
|
+
expiresIn: this.getPresignedUrlExpiry(),
|
|
80
|
+
});
|
|
81
|
+
return this.createPresignedSuccessResult(undefined, viewUrl);
|
|
82
|
+
}
|
|
83
|
+
catch (error) {
|
|
84
|
+
return this.createPresignedErrorResult(error instanceof Error ? error.message : 'Failed to generate view URL');
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Delete file from S3
|
|
89
|
+
*/
|
|
90
|
+
async delete(fileName) {
|
|
91
|
+
try {
|
|
92
|
+
const deleteCommand = new DeleteObjectCommand({
|
|
93
|
+
Bucket: this.bucketName,
|
|
94
|
+
Key: fileName,
|
|
95
|
+
});
|
|
96
|
+
await this.s3Client.send(deleteCommand);
|
|
97
|
+
return true;
|
|
98
|
+
}
|
|
99
|
+
catch (error) {
|
|
100
|
+
return false;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* AWS S3 presigned storage driver
|
|
106
|
+
*/
|
|
107
|
+
export class S3PresignedStorageDriver extends S3StorageDriver {
|
|
108
|
+
constructor(config) {
|
|
109
|
+
super(config);
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Override upload to return presigned URL instead of direct upload
|
|
113
|
+
*/
|
|
114
|
+
async upload(file) {
|
|
115
|
+
try {
|
|
116
|
+
// Validate file
|
|
117
|
+
const validationErrors = this.validateFile(file);
|
|
118
|
+
if (validationErrors.length > 0) {
|
|
119
|
+
return this.createErrorResult(validationErrors.join(', '));
|
|
120
|
+
}
|
|
121
|
+
// Generate unique filename
|
|
122
|
+
const fileName = this.generateFileName(file.originalname);
|
|
123
|
+
// Generate presigned upload URL
|
|
124
|
+
const presignedResult = await this.generateUploadUrl(fileName);
|
|
125
|
+
if (!presignedResult.success) {
|
|
126
|
+
return this.createErrorResult(presignedResult.error || 'Failed to generate presigned URL');
|
|
127
|
+
}
|
|
128
|
+
return this.createSuccessResult(fileName, presignedResult.uploadUrl);
|
|
129
|
+
}
|
|
130
|
+
catch (error) {
|
|
131
|
+
return this.createErrorResult(error instanceof Error ? error.message : 'Failed to generate presigned URL');
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
//# sourceMappingURL=s3.driver.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"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,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;gBAChC,OAAO,IAAI,CAAC,iBAAiB,CAAC,gBAAgB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;YAC7D,CAAC;YAED,2BAA2B;YAC3B,MAAM,QAAQ,GAAG,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;YAE1D,gCAAgC;YAChC,MAAM,eAAe,GAAG,MAAM,IAAI,CAAC,iBAAiB,CAAC,QAAQ,CAAC,CAAC;YAE/D,IAAI,CAAC,eAAe,CAAC,OAAO,EAAE,CAAC;gBAC7B,OAAO,IAAI,CAAC,iBAAiB,CAAC,eAAe,CAAC,KAAK,IAAI,kCAAkC,CAAC,CAAC;YAC7F,CAAC;YAED,OAAO,IAAI,CAAC,mBAAmB,CAAC,QAAQ,EAAE,eAAe,CAAC,SAAS,CAAC,CAAC;QACvE,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO,IAAI,CAAC,iBAAiB,CAC3B,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,kCAAkC,CAC5E,CAAC;QACJ,CAAC;IACH,CAAC;CACF"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { StorageConfig, IStorageDriver } from '../types/storage.types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Factory class for creating storage drivers
|
|
4
|
+
*/
|
|
5
|
+
export declare class StorageDriverFactory {
|
|
6
|
+
private static drivers;
|
|
7
|
+
/**
|
|
8
|
+
* Create and return a storage driver based on configuration
|
|
9
|
+
*/
|
|
10
|
+
static createDriver(config: StorageConfig): IStorageDriver;
|
|
11
|
+
/**
|
|
12
|
+
* Create a new driver instance
|
|
13
|
+
*/
|
|
14
|
+
private static createNewDriver;
|
|
15
|
+
/**
|
|
16
|
+
* Create S3 driver
|
|
17
|
+
*/
|
|
18
|
+
private static createS3Driver;
|
|
19
|
+
/**
|
|
20
|
+
* Create S3 presigned driver
|
|
21
|
+
*/
|
|
22
|
+
private static createS3PresignedDriver;
|
|
23
|
+
/**
|
|
24
|
+
* Create GCS driver
|
|
25
|
+
*/
|
|
26
|
+
private static createGCSDriver;
|
|
27
|
+
/**
|
|
28
|
+
* Create GCS presigned driver
|
|
29
|
+
*/
|
|
30
|
+
private static createGCSPresignedDriver;
|
|
31
|
+
/**
|
|
32
|
+
* Create OCI driver
|
|
33
|
+
*/
|
|
34
|
+
private static createOCIDriver;
|
|
35
|
+
/**
|
|
36
|
+
* Create OCI presigned driver
|
|
37
|
+
*/
|
|
38
|
+
private static createOCIPresignedDriver;
|
|
39
|
+
/**
|
|
40
|
+
* Generate unique key for driver caching
|
|
41
|
+
*/
|
|
42
|
+
private static getDriverKey;
|
|
43
|
+
/**
|
|
44
|
+
* Clear cached drivers
|
|
45
|
+
*/
|
|
46
|
+
static clearCache(): void;
|
|
47
|
+
/**
|
|
48
|
+
* Get cached driver count
|
|
49
|
+
*/
|
|
50
|
+
static getCachedDriverCount(): number;
|
|
51
|
+
/**
|
|
52
|
+
* Get available drivers
|
|
53
|
+
*/
|
|
54
|
+
static getAvailableDrivers(): string[];
|
|
55
|
+
}
|
|
56
|
+
//# sourceMappingURL=driver.factory.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"driver.factory.d.ts","sourceRoot":"","sources":["../../src/factory/driver.factory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAM1E;;GAEG;AACH,qBAAa,oBAAoB;IAC/B,OAAO,CAAC,MAAM,CAAC,OAAO,CAA0C;IAEhE;;OAEG;IACH,MAAM,CAAC,YAAY,CAAC,MAAM,EAAE,aAAa,GAAG,cAAc;IAiB1D;;OAEG;IACH,OAAO,CAAC,MAAM,CAAC,eAAe;IA4B9B;;OAEG;IACH,OAAO,CAAC,MAAM,CAAC,cAAc;IAI7B;;OAEG;IACH,OAAO,CAAC,MAAM,CAAC,uBAAuB;IAItC;;OAEG;IACH,OAAO,CAAC,MAAM,CAAC,eAAe;IAI9B;;OAEG;IACH,OAAO,CAAC,MAAM,CAAC,wBAAwB;IAIvC;;OAEG;IACH,OAAO,CAAC,MAAM,CAAC,eAAe;IAI9B;;OAEG;IACH,OAAO,CAAC,MAAM,CAAC,wBAAwB;IAIvC;;OAEG;IACH,OAAO,CAAC,MAAM,CAAC,YAAY;IAI3B;;OAEG;IACH,MAAM,CAAC,UAAU,IAAI,IAAI;IAIzB;;OAEG;IACH,MAAM,CAAC,oBAAoB,IAAI,MAAM;IAIrC;;OAEG;IACH,MAAM,CAAC,mBAAmB,IAAI,MAAM,EAAE;CAWvC"}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { LocalStorageDriver } from '../drivers/local.driver.js';
|
|
2
|
+
import { S3StorageDriver, S3PresignedStorageDriver } from '../drivers/s3.driver.js';
|
|
3
|
+
import { GCSStorageDriver, GCSPresignedStorageDriver } from '../drivers/gcs.driver.js';
|
|
4
|
+
import { OCIStorageDriver, OCIPresignedStorageDriver } from '../drivers/oci.driver.js';
|
|
5
|
+
/**
|
|
6
|
+
* Factory class for creating storage drivers
|
|
7
|
+
*/
|
|
8
|
+
export class StorageDriverFactory {
|
|
9
|
+
/**
|
|
10
|
+
* Create and return a storage driver based on configuration
|
|
11
|
+
*/
|
|
12
|
+
static createDriver(config) {
|
|
13
|
+
const driverKey = this.getDriverKey(config);
|
|
14
|
+
// Return cached driver if exists
|
|
15
|
+
if (this.drivers.has(driverKey)) {
|
|
16
|
+
return this.drivers.get(driverKey);
|
|
17
|
+
}
|
|
18
|
+
// Create new driver
|
|
19
|
+
const driver = this.createNewDriver(config);
|
|
20
|
+
// Cache the driver
|
|
21
|
+
this.drivers.set(driverKey, driver);
|
|
22
|
+
return driver;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Create a new driver instance
|
|
26
|
+
*/
|
|
27
|
+
static createNewDriver(config) {
|
|
28
|
+
switch (config.driver) {
|
|
29
|
+
case 'local':
|
|
30
|
+
return new LocalStorageDriver(config);
|
|
31
|
+
case 's3':
|
|
32
|
+
return this.createS3Driver(config);
|
|
33
|
+
case 's3-presigned':
|
|
34
|
+
return this.createS3PresignedDriver(config);
|
|
35
|
+
case 'gcs':
|
|
36
|
+
return this.createGCSDriver(config);
|
|
37
|
+
case 'gcs-presigned':
|
|
38
|
+
return this.createGCSPresignedDriver(config);
|
|
39
|
+
case 'oci':
|
|
40
|
+
return this.createOCIDriver(config);
|
|
41
|
+
case 'oci-presigned':
|
|
42
|
+
return this.createOCIPresignedDriver(config);
|
|
43
|
+
default:
|
|
44
|
+
throw new Error(`Unsupported storage driver: ${config.driver}`);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Create S3 driver
|
|
49
|
+
*/
|
|
50
|
+
static createS3Driver(config) {
|
|
51
|
+
return new S3StorageDriver(config);
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Create S3 presigned driver
|
|
55
|
+
*/
|
|
56
|
+
static createS3PresignedDriver(config) {
|
|
57
|
+
return new S3PresignedStorageDriver(config);
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Create GCS driver
|
|
61
|
+
*/
|
|
62
|
+
static createGCSDriver(config) {
|
|
63
|
+
return new GCSStorageDriver(config);
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Create GCS presigned driver
|
|
67
|
+
*/
|
|
68
|
+
static createGCSPresignedDriver(config) {
|
|
69
|
+
return new GCSPresignedStorageDriver(config);
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Create OCI driver
|
|
73
|
+
*/
|
|
74
|
+
static createOCIDriver(config) {
|
|
75
|
+
return new OCIStorageDriver(config);
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Create OCI presigned driver
|
|
79
|
+
*/
|
|
80
|
+
static createOCIPresignedDriver(config) {
|
|
81
|
+
return new OCIPresignedStorageDriver(config);
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Generate unique key for driver caching
|
|
85
|
+
*/
|
|
86
|
+
static getDriverKey(config) {
|
|
87
|
+
return `${config.driver}_${config.bucketName || 'local'}_${config.localPath || 'default'}`;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Clear cached drivers
|
|
91
|
+
*/
|
|
92
|
+
static clearCache() {
|
|
93
|
+
this.drivers.clear();
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Get cached driver count
|
|
97
|
+
*/
|
|
98
|
+
static getCachedDriverCount() {
|
|
99
|
+
return this.drivers.size;
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Get available drivers
|
|
103
|
+
*/
|
|
104
|
+
static getAvailableDrivers() {
|
|
105
|
+
return [
|
|
106
|
+
'local',
|
|
107
|
+
's3',
|
|
108
|
+
's3-presigned',
|
|
109
|
+
'gcs',
|
|
110
|
+
'gcs-presigned',
|
|
111
|
+
'oci',
|
|
112
|
+
'oci-presigned'
|
|
113
|
+
];
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
StorageDriverFactory.drivers = new Map();
|
|
117
|
+
//# sourceMappingURL=driver.factory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"driver.factory.js","sourceRoot":"","sources":["../../src/factory/driver.factory.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAChE,OAAO,EAAE,eAAe,EAAE,wBAAwB,EAAE,MAAM,yBAAyB,CAAC;AACpF,OAAO,EAAE,gBAAgB,EAAE,yBAAyB,EAAE,MAAM,0BAA0B,CAAC;AACvF,OAAO,EAAE,gBAAgB,EAAE,yBAAyB,EAAE,MAAM,0BAA0B,CAAC;AAEvF;;GAEG;AACH,MAAM,OAAO,oBAAoB;IAG/B;;OAEG;IACH,MAAM,CAAC,YAAY,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|
1
|
+
import { StorageManager } from './storage-manager.js';
|
|
2
|
+
export { StorageManager } from './storage-manager.js';
|
|
3
|
+
export { StorageDriverFactory } from './factory/driver.factory.js';
|
|
4
|
+
export type { StorageDriver, FileUploadResult, PresignedUrlResult, StorageConfig, FileInput, SingleFileInput, MultipleFilesInput, IStorageDriver, StorageRequest, ValidationResult, EnvironmentConfig } from './types/storage.types.js';
|
|
5
|
+
export { loadAndValidateConfig, validateStorageConfig } from './utils/config.utils.js';
|
|
6
|
+
export { generateUniqueFileName, sanitizeFileName, createMonthBasedPath, ensureDirectoryExists, formatFileSize, validateFileSize, validateFileType, createLocalFileUrl, getFileExtension, isImageFile, isDocumentFile } from './utils/file.utils.js';
|
|
7
|
+
export { BaseStorageDriver } from './drivers/base.driver.js';
|
|
8
|
+
export { LocalStorageDriver } from './drivers/local.driver.js';
|
|
9
|
+
export { S3StorageDriver, S3PresignedStorageDriver } from './drivers/s3.driver.js';
|
|
10
|
+
export { GCSStorageDriver, GCSPresignedStorageDriver } from './drivers/gcs.driver.js';
|
|
11
|
+
export { OCIStorageDriver, OCIPresignedStorageDriver } from './drivers/oci.driver.js';
|
|
12
|
+
/**
|
|
13
|
+
* Get or create default storage manager instance
|
|
14
|
+
*/
|
|
15
|
+
export declare function getStorageManager(): StorageManager;
|
|
16
|
+
/**
|
|
17
|
+
* Initialize default storage manager with custom config
|
|
18
|
+
*/
|
|
19
|
+
export declare function initializeStorageManager(config?: any): StorageManager;
|
|
20
|
+
/**
|
|
21
|
+
* Convenience functions for quick usage
|
|
22
|
+
*/
|
|
23
|
+
export declare function uploadFile(file: Express.Multer.File): Promise<import("./types/storage.types.js").FileUploadResult>;
|
|
24
|
+
export declare function uploadFiles(files: Express.Multer.File[]): Promise<import("./types/storage.types.js").FileUploadResult[]>;
|
|
25
|
+
export declare function generateUploadUrl(fileName: string): Promise<import("./types/storage.types.js").PresignedUrlResult>;
|
|
26
|
+
export declare function generateViewUrl(fileName: string): Promise<import("./types/storage.types.js").PresignedUrlResult>;
|
|
27
|
+
export declare function deleteFile(fileName: string): Promise<boolean>;
|
|
28
|
+
export declare function deleteFiles(fileNames: string[]): Promise<boolean[]>;
|
|
29
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAAE,oBAAoB,EAAE,MAAM,6BAA6B,CAAC;AAGnE,YAAY,EACV,aAAa,EACb,gBAAgB,EAChB,kBAAkB,EAClB,aAAa,EACb,SAAS,EACT,eAAe,EACf,kBAAkB,EAClB,cAAc,EACd,cAAc,EACd,gBAAgB,EAChB,iBAAiB,EAClB,MAAM,0BAA0B,CAAC;AAGlC,OAAO,EAAE,qBAAqB,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AACvF,OAAO,EACL,sBAAsB,EACtB,gBAAgB,EAChB,oBAAoB,EACpB,qBAAqB,EACrB,cAAc,EACd,gBAAgB,EAChB,gBAAgB,EAChB,kBAAkB,EAClB,gBAAgB,EAChB,WAAW,EACX,cAAc,EACf,MAAM,uBAAuB,CAAC;AAG/B,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAC7D,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAC/D,OAAO,EAAE,eAAe,EAAE,wBAAwB,EAAE,MAAM,wBAAwB,CAAC;AACnF,OAAO,EAAE,gBAAgB,EAAE,yBAAyB,EAAE,MAAM,yBAAyB,CAAC;AACtF,OAAO,EAAE,gBAAgB,EAAE,yBAAyB,EAAE,MAAM,yBAAyB,CAAC;AAKtF;;GAEG;AACH,wBAAgB,iBAAiB,IAAI,cAAc,CAKlD;AAED;;GAEG;AACH,wBAAgB,wBAAwB,CAAC,MAAM,CAAC,EAAE,GAAG,GAAG,cAAc,CAGrE;AAED;;GAEG;AACH,wBAAsB,UAAU,CAAC,IAAI,EAAE,OAAO,CAAC,MAAM,CAAC,IAAI,gEAEzD;AAED,wBAAsB,WAAW,CAAC,KAAK,EAAE,OAAO,CAAC,MAAM,CAAC,IAAI,EAAE,kEAE7D;AAED,wBAAsB,iBAAiB,CAAC,QAAQ,EAAE,MAAM,kEAEvD;AAED,wBAAsB,eAAe,CAAC,QAAQ,EAAE,MAAM,kEAErD;AAED,wBAAsB,UAAU,CAAC,QAAQ,EAAE,MAAM,oBAEhD;AAED,wBAAsB,WAAW,CAAC,SAAS,EAAE,MAAM,EAAE,sBAEpD"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
// Main exports
|
|
2
|
+
import { StorageManager } from './storage-manager.js';
|
|
3
|
+
export { StorageManager } from './storage-manager.js';
|
|
4
|
+
export { StorageDriverFactory } from './factory/driver.factory.js';
|
|
5
|
+
// Utility exports
|
|
6
|
+
export { loadAndValidateConfig, validateStorageConfig } from './utils/config.utils.js';
|
|
7
|
+
export { generateUniqueFileName, sanitizeFileName, createMonthBasedPath, ensureDirectoryExists, formatFileSize, validateFileSize, validateFileType, createLocalFileUrl, getFileExtension, isImageFile, isDocumentFile } from './utils/file.utils.js';
|
|
8
|
+
// Driver exports
|
|
9
|
+
export { BaseStorageDriver } from './drivers/base.driver.js';
|
|
10
|
+
export { LocalStorageDriver } from './drivers/local.driver.js';
|
|
11
|
+
export { S3StorageDriver, S3PresignedStorageDriver } from './drivers/s3.driver.js';
|
|
12
|
+
export { GCSStorageDriver, GCSPresignedStorageDriver } from './drivers/gcs.driver.js';
|
|
13
|
+
export { OCIStorageDriver, OCIPresignedStorageDriver } from './drivers/oci.driver.js';
|
|
14
|
+
// Default instance
|
|
15
|
+
let defaultStorageManager = null;
|
|
16
|
+
/**
|
|
17
|
+
* Get or create default storage manager instance
|
|
18
|
+
*/
|
|
19
|
+
export function getStorageManager() {
|
|
20
|
+
if (!defaultStorageManager) {
|
|
21
|
+
defaultStorageManager = new StorageManager();
|
|
22
|
+
}
|
|
23
|
+
return defaultStorageManager;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Initialize default storage manager with custom config
|
|
27
|
+
*/
|
|
28
|
+
export function initializeStorageManager(config) {
|
|
29
|
+
defaultStorageManager = StorageManager.initialize(config);
|
|
30
|
+
return defaultStorageManager;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Convenience functions for quick usage
|
|
34
|
+
*/
|
|
35
|
+
export async function uploadFile(file) {
|
|
36
|
+
return getStorageManager().uploadFile(file);
|
|
37
|
+
}
|
|
38
|
+
export async function uploadFiles(files) {
|
|
39
|
+
return getStorageManager().uploadFiles(files);
|
|
40
|
+
}
|
|
41
|
+
export async function generateUploadUrl(fileName) {
|
|
42
|
+
return getStorageManager().generateUploadUrl(fileName);
|
|
43
|
+
}
|
|
44
|
+
export async function generateViewUrl(fileName) {
|
|
45
|
+
return getStorageManager().generateViewUrl(fileName);
|
|
46
|
+
}
|
|
47
|
+
export async function deleteFile(fileName) {
|
|
48
|
+
return getStorageManager().deleteFile(fileName);
|
|
49
|
+
}
|
|
50
|
+
export async function deleteFiles(fileNames) {
|
|
51
|
+
return getStorageManager().deleteFiles(fileNames);
|
|
52
|
+
}
|
|
53
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,eAAe;AACf,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAAE,oBAAoB,EAAE,MAAM,6BAA6B,CAAC;AAiBnE,kBAAkB;AAClB,OAAO,EAAE,qBAAqB,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AACvF,OAAO,EACL,sBAAs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,CAAC,CAAC;AACzD,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,eAAe,CAAC,QAAgB;IACpD,OAAO,iBAAiB,EAAE,CAAC,eAAe,CAAC,QAAQ,CAAC,CAAC;AACvD,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,UAAU,CAAC,QAAgB;IAC/C,OAAO,iBAAiB,EAAE,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC;AAClD,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,WAAW,CAAC,SAAmB;IACnD,OAAO,iBAAiB,EAAE,CAAC,WAAW,CAAC,SAAS,CAAC,CAAC;AACpD,CAAC"}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { FileUploadResult, PresignedUrlResult, FileInput, StorageConfig } from './types/storage.types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Main storage manager class
|
|
4
|
+
*/
|
|
5
|
+
export declare class StorageManager {
|
|
6
|
+
private driver;
|
|
7
|
+
private config;
|
|
8
|
+
private isInitialized;
|
|
9
|
+
constructor();
|
|
10
|
+
/**
|
|
11
|
+
* Initialize storage manager with custom configuration
|
|
12
|
+
*/
|
|
13
|
+
static initialize(config?: Partial<StorageConfig>): StorageManager;
|
|
14
|
+
/**
|
|
15
|
+
* Upload a single file
|
|
16
|
+
*/
|
|
17
|
+
uploadFile(file: Express.Multer.File): Promise<FileUploadResult>;
|
|
18
|
+
/**
|
|
19
|
+
* Upload multiple files
|
|
20
|
+
*/
|
|
21
|
+
uploadFiles(files: Express.Multer.File[]): Promise<FileUploadResult[]>;
|
|
22
|
+
/**
|
|
23
|
+
* Upload files with input type detection
|
|
24
|
+
*/
|
|
25
|
+
upload(input: FileInput): Promise<FileUploadResult | FileUploadResult[]>;
|
|
26
|
+
/**
|
|
27
|
+
* Generate upload URL for presigned uploads
|
|
28
|
+
*/
|
|
29
|
+
generateUploadUrl(fileName: string): Promise<PresignedUrlResult>;
|
|
30
|
+
/**
|
|
31
|
+
* Generate view URL for presigned uploads
|
|
32
|
+
*/
|
|
33
|
+
generateViewUrl(fileName: string): Promise<PresignedUrlResult>;
|
|
34
|
+
/**
|
|
35
|
+
* Generate multiple upload URLs
|
|
36
|
+
*/
|
|
37
|
+
generateUploadUrls(fileNames: string[]): Promise<PresignedUrlResult[]>;
|
|
38
|
+
/**
|
|
39
|
+
* Generate multiple view URLs
|
|
40
|
+
*/
|
|
41
|
+
generateViewUrls(fileNames: string[]): Promise<PresignedUrlResult[]>;
|
|
42
|
+
/**
|
|
43
|
+
* Delete a single file
|
|
44
|
+
*/
|
|
45
|
+
deleteFile(fileName: string): Promise<boolean>;
|
|
46
|
+
/**
|
|
47
|
+
* Delete multiple files
|
|
48
|
+
*/
|
|
49
|
+
deleteFiles(fileNames: string[]): Promise<boolean[]>;
|
|
50
|
+
/**
|
|
51
|
+
* Get current configuration
|
|
52
|
+
*/
|
|
53
|
+
getConfig(): StorageConfig;
|
|
54
|
+
/**
|
|
55
|
+
* Get current driver type
|
|
56
|
+
*/
|
|
57
|
+
getDriverType(): string;
|
|
58
|
+
/**
|
|
59
|
+
* Check if presigned URLs are supported
|
|
60
|
+
*/
|
|
61
|
+
isPresignedSupported(): boolean;
|
|
62
|
+
/**
|
|
63
|
+
* Get available drivers
|
|
64
|
+
*/
|
|
65
|
+
static getAvailableDrivers(): string[];
|
|
66
|
+
/**
|
|
67
|
+
* Clear driver cache
|
|
68
|
+
*/
|
|
69
|
+
static clearCache(): void;
|
|
70
|
+
/**
|
|
71
|
+
* Ensure storage manager is initialized
|
|
72
|
+
*/
|
|
73
|
+
private ensureInitialized;
|
|
74
|
+
}
|
|
75
|
+
//# sourceMappingURL=storage-manager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"storage-manager.d.ts","sourceRoot":"","sources":["../src/storage-manager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkB,gBAAgB,EAAE,kBAAkB,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;A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BAAmB,IAAI,MAAM,EAAE;IAItC;;OAEG;IACH,MAAM,CAAC,UAAU,IAAI,IAAI;IAIzB;;OAEG;IACH,OAAO,CAAC,iBAAiB;CAK1B"}
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import { StorageDriverFactory } from './factory/driver.factory.js';
|
|
2
|
+
import { loadAndValidateConfig } from './utils/config.utils.js';
|
|
3
|
+
/**
|
|
4
|
+
* Main storage manager class
|
|
5
|
+
*/
|
|
6
|
+
export class StorageManager {
|
|
7
|
+
constructor() {
|
|
8
|
+
this.isInitialized = false;
|
|
9
|
+
// Initialize with default config
|
|
10
|
+
const result = loadAndValidateConfig();
|
|
11
|
+
if (!result.validation.isValid) {
|
|
12
|
+
throw new Error(`Configuration validation failed: ${result.validation.errors.join(', ')}`);
|
|
13
|
+
}
|
|
14
|
+
this.config = result.config;
|
|
15
|
+
this.driver = StorageDriverFactory.createDriver(result.config);
|
|
16
|
+
this.isInitialized = true;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Initialize storage manager with custom configuration
|
|
20
|
+
*/
|
|
21
|
+
static initialize(config) {
|
|
22
|
+
const result = loadAndValidateConfig();
|
|
23
|
+
// Merge custom config with default
|
|
24
|
+
const mergedConfig = { ...result.config, ...config };
|
|
25
|
+
// Validate merged config
|
|
26
|
+
const { validateStorageConfig } = require('./utils/config.utils');
|
|
27
|
+
const validationResult = validateStorageConfig(mergedConfig);
|
|
28
|
+
if (!validationResult.isValid) {
|
|
29
|
+
throw new Error(`Configuration validation failed: ${validationResult.errors.join(', ')}`);
|
|
30
|
+
}
|
|
31
|
+
const manager = new StorageManager();
|
|
32
|
+
manager.config = mergedConfig;
|
|
33
|
+
manager.driver = StorageDriverFactory.createDriver(mergedConfig);
|
|
34
|
+
manager.isInitialized = true;
|
|
35
|
+
return manager;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Upload a single file
|
|
39
|
+
*/
|
|
40
|
+
async uploadFile(file) {
|
|
41
|
+
this.ensureInitialized();
|
|
42
|
+
return this.driver.upload(file);
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Upload multiple files
|
|
46
|
+
*/
|
|
47
|
+
async uploadFiles(files) {
|
|
48
|
+
this.ensureInitialized();
|
|
49
|
+
return this.driver.uploadMultiple(files);
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Upload files with input type detection
|
|
53
|
+
*/
|
|
54
|
+
async upload(input) {
|
|
55
|
+
this.ensureInitialized();
|
|
56
|
+
if (input.type === 'single') {
|
|
57
|
+
return this.driver.upload(input.file);
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
return this.driver.uploadMultiple(input.files);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Generate upload URL for presigned uploads
|
|
65
|
+
*/
|
|
66
|
+
async generateUploadUrl(fileName) {
|
|
67
|
+
this.ensureInitialized();
|
|
68
|
+
return this.driver.generateUploadUrl(fileName);
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Generate view URL for presigned uploads
|
|
72
|
+
*/
|
|
73
|
+
async generateViewUrl(fileName) {
|
|
74
|
+
this.ensureInitialized();
|
|
75
|
+
return this.driver.generateViewUrl(fileName);
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Generate multiple upload URLs
|
|
79
|
+
*/
|
|
80
|
+
async generateUploadUrls(fileNames) {
|
|
81
|
+
this.ensureInitialized();
|
|
82
|
+
return this.driver.generateMultipleUploadUrls(fileNames);
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Generate multiple view URLs
|
|
86
|
+
*/
|
|
87
|
+
async generateViewUrls(fileNames) {
|
|
88
|
+
this.ensureInitialized();
|
|
89
|
+
return this.driver.generateMultipleViewUrls(fileNames);
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Delete a single file
|
|
93
|
+
*/
|
|
94
|
+
async deleteFile(fileName) {
|
|
95
|
+
this.ensureInitialized();
|
|
96
|
+
return this.driver.delete(fileName);
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Delete multiple files
|
|
100
|
+
*/
|
|
101
|
+
async deleteFiles(fileNames) {
|
|
102
|
+
this.ensureInitialized();
|
|
103
|
+
return this.driver.deleteMultiple(fileNames);
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Get current configuration
|
|
107
|
+
*/
|
|
108
|
+
getConfig() {
|
|
109
|
+
return { ...this.config };
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Get current driver type
|
|
113
|
+
*/
|
|
114
|
+
getDriverType() {
|
|
115
|
+
return this.config.driver;
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Check if presigned URLs are supported
|
|
119
|
+
*/
|
|
120
|
+
isPresignedSupported() {
|
|
121
|
+
return this.config.driver.includes('-presigned');
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Get available drivers
|
|
125
|
+
*/
|
|
126
|
+
static getAvailableDrivers() {
|
|
127
|
+
return StorageDriverFactory.getAvailableDrivers();
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Clear driver cache
|
|
131
|
+
*/
|
|
132
|
+
static clearCache() {
|
|
133
|
+
StorageDriverFactory.clearCache();
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Ensure storage manager is initialized
|
|
137
|
+
*/
|
|
138
|
+
ensureInitialized() {
|
|
139
|
+
if (!this.isInitialized) {
|
|
140
|
+
throw new Error('StorageManager is not initialized. Call StorageManager.initialize() first.');
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
//# sourceMappingURL=storage-manager.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"storage-manager.js","sourceRoot":"","sources":["../src/storage-manager.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,oBAAoB,EAAE,MAAM,6BAA6B,CAAC;AAC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