express-storage 1.0.0 → 1.1.3
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 +519 -348
- package/dist/drivers/azure.driver.d.ts +88 -0
- package/dist/drivers/azure.driver.d.ts.map +1 -0
- package/dist/drivers/azure.driver.js +367 -0
- package/dist/drivers/azure.driver.js.map +1 -0
- package/dist/drivers/base.driver.d.ts +125 -24
- package/dist/drivers/base.driver.d.ts.map +1 -1
- package/dist/drivers/base.driver.js +248 -62
- package/dist/drivers/base.driver.js.map +1 -1
- package/dist/drivers/gcs.driver.d.ts +60 -13
- package/dist/drivers/gcs.driver.d.ts.map +1 -1
- package/dist/drivers/gcs.driver.js +242 -41
- package/dist/drivers/gcs.driver.js.map +1 -1
- package/dist/drivers/local.driver.d.ts +89 -12
- package/dist/drivers/local.driver.d.ts.map +1 -1
- package/dist/drivers/local.driver.js +533 -45
- package/dist/drivers/local.driver.js.map +1 -1
- package/dist/drivers/s3.driver.d.ts +64 -13
- package/dist/drivers/s3.driver.d.ts.map +1 -1
- package/dist/drivers/s3.driver.js +269 -41
- package/dist/drivers/s3.driver.js.map +1 -1
- package/dist/factory/driver.factory.d.ts +35 -29
- package/dist/factory/driver.factory.d.ts.map +1 -1
- package/dist/factory/driver.factory.js +119 -59
- package/dist/factory/driver.factory.js.map +1 -1
- package/dist/index.d.ts +23 -22
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +26 -46
- package/dist/index.js.map +1 -1
- package/dist/storage-manager.d.ts +205 -52
- package/dist/storage-manager.d.ts.map +1 -1
- package/dist/storage-manager.js +644 -73
- package/dist/storage-manager.js.map +1 -1
- package/dist/types/storage.types.d.ts +243 -18
- package/dist/types/storage.types.d.ts.map +1 -1
- package/dist/utils/config.utils.d.ts +28 -4
- package/dist/utils/config.utils.d.ts.map +1 -1
- package/dist/utils/config.utils.js +121 -47
- package/dist/utils/config.utils.js.map +1 -1
- package/dist/utils/file.utils.d.ts +111 -14
- package/dist/utils/file.utils.d.ts.map +1 -1
- package/dist/utils/file.utils.js +215 -32
- package/dist/utils/file.utils.js.map +1 -1
- package/package.json +51 -27
- package/dist/drivers/oci.driver.d.ts +0 -37
- package/dist/drivers/oci.driver.d.ts.map +0 -1
- package/dist/drivers/oci.driver.js +0 -84
- package/dist/drivers/oci.driver.js.map +0 -1
|
@@ -1,55 +1,61 @@
|
|
|
1
1
|
import { StorageConfig, IStorageDriver } from '../types/storage.types.js';
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
3
|
+
* StorageDriverFactory - Creates and caches storage driver instances.
|
|
4
|
+
*
|
|
5
|
+
* Drivers are cached to avoid recreating connections for the same configuration.
|
|
6
|
+
* The cache is limited to 100 drivers to prevent memory issues in long-running apps.
|
|
7
|
+
*
|
|
8
|
+
* When the cache is full, the least recently used driver gets evicted.
|
|
4
9
|
*/
|
|
5
10
|
export declare class StorageDriverFactory {
|
|
6
11
|
private static drivers;
|
|
7
12
|
/**
|
|
8
|
-
*
|
|
13
|
+
* Gets or creates a driver for the given configuration.
|
|
14
|
+
*
|
|
15
|
+
* If a driver for this exact configuration already exists, it's reused.
|
|
16
|
+
* Otherwise, a new driver is created and cached.
|
|
9
17
|
*/
|
|
10
18
|
static createDriver(config: StorageConfig): IStorageDriver;
|
|
11
19
|
/**
|
|
12
|
-
*
|
|
20
|
+
* Removes the oldest (least recently accessed) driver from the cache.
|
|
13
21
|
*/
|
|
14
|
-
private static
|
|
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;
|
|
22
|
+
private static evictLRU;
|
|
31
23
|
/**
|
|
32
|
-
*
|
|
24
|
+
* Creates a new driver instance based on the config's driver type.
|
|
33
25
|
*/
|
|
34
|
-
private static
|
|
26
|
+
private static createNewDriver;
|
|
35
27
|
/**
|
|
36
|
-
*
|
|
28
|
+
* Creates a fingerprint of a string for cache key comparison.
|
|
29
|
+
* Uses triple hash approach (length + two FNV-1a hashes + checksum) for maximum collision resistance.
|
|
30
|
+
*
|
|
31
|
+
* The triple hash approach with length and checksum significantly reduces collision probability:
|
|
32
|
+
* - Single 32-bit hash: ~77k items for 50% collision probability
|
|
33
|
+
* - This approach: effectively ~128+ bits of entropy, negligible collision probability
|
|
34
|
+
*
|
|
35
|
+
* For credentials, we also include a prefix checksum to detect similar keys early.
|
|
37
36
|
*/
|
|
38
|
-
private static
|
|
37
|
+
private static secureHash;
|
|
39
38
|
/**
|
|
40
|
-
*
|
|
39
|
+
* Generates a unique cache key for a configuration.
|
|
40
|
+
* Includes all properties that affect driver behavior.
|
|
41
41
|
*/
|
|
42
42
|
private static getDriverKey;
|
|
43
43
|
/**
|
|
44
|
-
*
|
|
44
|
+
* Clears all cached drivers.
|
|
45
|
+
* Useful in tests or when you've rotated credentials.
|
|
45
46
|
*/
|
|
46
47
|
static clearCache(): void;
|
|
47
48
|
/**
|
|
48
|
-
*
|
|
49
|
+
* Returns the number of cached drivers.
|
|
50
|
+
*/
|
|
51
|
+
static getCacheSize(): number;
|
|
52
|
+
/**
|
|
53
|
+
* Removes a specific driver from the cache.
|
|
54
|
+
* Useful when credentials have changed for a specific configuration.
|
|
49
55
|
*/
|
|
50
|
-
static
|
|
56
|
+
static removeFromCache(config: StorageConfig): boolean;
|
|
51
57
|
/**
|
|
52
|
-
*
|
|
58
|
+
* Returns a list of all supported driver types.
|
|
53
59
|
*/
|
|
54
60
|
static getAvailableDrivers(): string[];
|
|
55
61
|
}
|
|
@@ -1 +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;
|
|
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;AAa1E;;;;;;;GAOG;AACH,qBAAa,oBAAoB;IAC/B,OAAO,CAAC,MAAM,CAAC,OAAO,CAAsC;IAE5D;;;;;OAKG;IACH,MAAM,CAAC,YAAY,CAAC,MAAM,EAAE,aAAa,GAAG,cAAc;IAuB1D;;OAEG;IACH,OAAO,CAAC,MAAM,CAAC,QAAQ;IAgBvB;;OAEG;IACH,OAAO,CAAC,MAAM,CAAC,eAAe;IAqB9B;;;;;;;;;OASG;IACH,OAAO,CAAC,MAAM,CAAC,UAAU;IAmCzB;;;OAGG;IACH,OAAO,CAAC,MAAM,CAAC,YAAY;IAsB3B;;;OAGG;IACH,MAAM,CAAC,UAAU,IAAI,IAAI;IAIzB;;OAEG;IACH,MAAM,CAAC,YAAY,IAAI,MAAM;IAI7B;;;OAGG;IACH,MAAM,CAAC,eAAe,CAAC,MAAM,EAAE,aAAa,GAAG,OAAO;IAKtD;;OAEG;IACH,MAAM,CAAC,mBAAmB,IAAI,MAAM,EAAE;CAWvC"}
|
|
@@ -1,105 +1,165 @@
|
|
|
1
1
|
import { LocalStorageDriver } from '../drivers/local.driver.js';
|
|
2
2
|
import { S3StorageDriver, S3PresignedStorageDriver } from '../drivers/s3.driver.js';
|
|
3
3
|
import { GCSStorageDriver, GCSPresignedStorageDriver } from '../drivers/gcs.driver.js';
|
|
4
|
-
import {
|
|
4
|
+
import { AzureStorageDriver, AzurePresignedStorageDriver } from '../drivers/azure.driver.js';
|
|
5
|
+
const MAX_CACHED_DRIVERS = 100;
|
|
5
6
|
/**
|
|
6
|
-
*
|
|
7
|
+
* StorageDriverFactory - Creates and caches storage driver instances.
|
|
8
|
+
*
|
|
9
|
+
* Drivers are cached to avoid recreating connections for the same configuration.
|
|
10
|
+
* The cache is limited to 100 drivers to prevent memory issues in long-running apps.
|
|
11
|
+
*
|
|
12
|
+
* When the cache is full, the least recently used driver gets evicted.
|
|
7
13
|
*/
|
|
8
14
|
export class StorageDriverFactory {
|
|
9
15
|
/**
|
|
10
|
-
*
|
|
16
|
+
* Gets or creates a driver for the given configuration.
|
|
17
|
+
*
|
|
18
|
+
* If a driver for this exact configuration already exists, it's reused.
|
|
19
|
+
* Otherwise, a new driver is created and cached.
|
|
11
20
|
*/
|
|
12
21
|
static createDriver(config) {
|
|
13
22
|
const driverKey = this.getDriverKey(config);
|
|
14
|
-
|
|
15
|
-
if (
|
|
16
|
-
|
|
23
|
+
const existing = this.drivers.get(driverKey);
|
|
24
|
+
if (existing) {
|
|
25
|
+
existing.lastAccess = Date.now();
|
|
26
|
+
return existing.driver;
|
|
27
|
+
}
|
|
28
|
+
if (this.drivers.size >= MAX_CACHED_DRIVERS) {
|
|
29
|
+
this.evictLRU();
|
|
17
30
|
}
|
|
18
|
-
// Create new driver
|
|
19
31
|
const driver = this.createNewDriver(config);
|
|
20
|
-
|
|
21
|
-
|
|
32
|
+
this.drivers.set(driverKey, {
|
|
33
|
+
driver,
|
|
34
|
+
lastAccess: Date.now(),
|
|
35
|
+
});
|
|
22
36
|
return driver;
|
|
23
37
|
}
|
|
24
38
|
/**
|
|
25
|
-
*
|
|
39
|
+
* Removes the oldest (least recently accessed) driver from the cache.
|
|
40
|
+
*/
|
|
41
|
+
static evictLRU() {
|
|
42
|
+
let oldestKey = null;
|
|
43
|
+
let oldestTime = Infinity;
|
|
44
|
+
for (const [key, entry] of this.drivers.entries()) {
|
|
45
|
+
if (entry.lastAccess < oldestTime) {
|
|
46
|
+
oldestTime = entry.lastAccess;
|
|
47
|
+
oldestKey = key;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
if (oldestKey) {
|
|
51
|
+
this.drivers.delete(oldestKey);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Creates a new driver instance based on the config's driver type.
|
|
26
56
|
*/
|
|
27
57
|
static createNewDriver(config) {
|
|
28
58
|
switch (config.driver) {
|
|
29
59
|
case 'local':
|
|
30
60
|
return new LocalStorageDriver(config);
|
|
31
61
|
case 's3':
|
|
32
|
-
return
|
|
62
|
+
return new S3StorageDriver(config);
|
|
33
63
|
case 's3-presigned':
|
|
34
|
-
return
|
|
64
|
+
return new S3PresignedStorageDriver(config);
|
|
35
65
|
case 'gcs':
|
|
36
|
-
return
|
|
66
|
+
return new GCSStorageDriver(config);
|
|
37
67
|
case 'gcs-presigned':
|
|
38
|
-
return
|
|
39
|
-
case '
|
|
40
|
-
return
|
|
41
|
-
case '
|
|
42
|
-
return
|
|
68
|
+
return new GCSPresignedStorageDriver(config);
|
|
69
|
+
case 'azure':
|
|
70
|
+
return new AzureStorageDriver(config);
|
|
71
|
+
case 'azure-presigned':
|
|
72
|
+
return new AzurePresignedStorageDriver(config);
|
|
43
73
|
default:
|
|
44
74
|
throw new Error(`Unsupported storage driver: ${config.driver}`);
|
|
45
75
|
}
|
|
46
76
|
}
|
|
47
77
|
/**
|
|
48
|
-
*
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
*
|
|
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
|
|
78
|
+
* Creates a fingerprint of a string for cache key comparison.
|
|
79
|
+
* Uses triple hash approach (length + two FNV-1a hashes + checksum) for maximum collision resistance.
|
|
80
|
+
*
|
|
81
|
+
* The triple hash approach with length and checksum significantly reduces collision probability:
|
|
82
|
+
* - Single 32-bit hash: ~77k items for 50% collision probability
|
|
83
|
+
* - This approach: effectively ~128+ bits of entropy, negligible collision probability
|
|
84
|
+
*
|
|
85
|
+
* For credentials, we also include a prefix checksum to detect similar keys early.
|
|
67
86
|
*/
|
|
68
|
-
static
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
87
|
+
static secureHash(str) {
|
|
88
|
+
if (!str)
|
|
89
|
+
return '0:0:0:0';
|
|
90
|
+
const length = str.length;
|
|
91
|
+
// First hash with standard FNV-1a offset basis
|
|
92
|
+
const FNV_OFFSET_BASIS_1 = 2166136261;
|
|
93
|
+
const FNV_PRIME = 16777619;
|
|
94
|
+
let hash1 = FNV_OFFSET_BASIS_1;
|
|
95
|
+
for (let i = 0; i < str.length; i++) {
|
|
96
|
+
hash1 ^= str.charCodeAt(i);
|
|
97
|
+
hash1 = Math.imul(hash1, FNV_PRIME);
|
|
98
|
+
}
|
|
99
|
+
// Second hash with different seed (XOR first hash into offset basis)
|
|
100
|
+
// This creates a completely different hash even for similar strings
|
|
101
|
+
const FNV_OFFSET_BASIS_2 = 0x811c9dc5 ^ (hash1 >>> 0);
|
|
102
|
+
let hash2 = FNV_OFFSET_BASIS_2;
|
|
103
|
+
for (let i = str.length - 1; i >= 0; i--) { // Reverse direction for different bit mixing
|
|
104
|
+
hash2 ^= str.charCodeAt(i);
|
|
105
|
+
hash2 = Math.imul(hash2, FNV_PRIME);
|
|
106
|
+
}
|
|
107
|
+
// Third component: simple additive checksum of character codes
|
|
108
|
+
// Provides additional collision resistance with minimal computation
|
|
109
|
+
let checksum = 0;
|
|
110
|
+
for (let i = 0; i < str.length; i++) {
|
|
111
|
+
checksum = (checksum + str.charCodeAt(i) * (i + 1)) >>> 0;
|
|
112
|
+
}
|
|
113
|
+
// Return length:hash1:hash2:checksum format - collision requires matching all four
|
|
114
|
+
return `${length}:${(hash1 >>> 0).toString(16)}:${(hash2 >>> 0).toString(16)}:${(checksum >>> 0).toString(16)}`;
|
|
82
115
|
}
|
|
83
116
|
/**
|
|
84
|
-
*
|
|
117
|
+
* Generates a unique cache key for a configuration.
|
|
118
|
+
* Includes all properties that affect driver behavior.
|
|
85
119
|
*/
|
|
86
120
|
static getDriverKey(config) {
|
|
87
|
-
|
|
121
|
+
const keyParts = [
|
|
122
|
+
config.driver,
|
|
123
|
+
config.bucketName || 'local',
|
|
124
|
+
config.localPath || 'default',
|
|
125
|
+
config.bucketPath || '',
|
|
126
|
+
(config.presignedUrlExpiry || 600).toString(),
|
|
127
|
+
(config.maxFileSize || 5368709120).toString(),
|
|
128
|
+
config.awsRegion || '',
|
|
129
|
+
this.secureHash(config.awsAccessKey || ''),
|
|
130
|
+
this.secureHash(config.awsSecretKey || ''),
|
|
131
|
+
config.gcsProjectId || '',
|
|
132
|
+
this.secureHash(config.gcsCredentials || ''),
|
|
133
|
+
config.azureAccountName || '',
|
|
134
|
+
config.azureContainerName || '',
|
|
135
|
+
this.secureHash(config.azureConnectionString || ''),
|
|
136
|
+
this.secureHash(config.azureAccountKey || ''),
|
|
137
|
+
];
|
|
138
|
+
return keyParts.join('_');
|
|
88
139
|
}
|
|
89
140
|
/**
|
|
90
|
-
*
|
|
141
|
+
* Clears all cached drivers.
|
|
142
|
+
* Useful in tests or when you've rotated credentials.
|
|
91
143
|
*/
|
|
92
144
|
static clearCache() {
|
|
93
145
|
this.drivers.clear();
|
|
94
146
|
}
|
|
95
147
|
/**
|
|
96
|
-
*
|
|
148
|
+
* Returns the number of cached drivers.
|
|
97
149
|
*/
|
|
98
|
-
static
|
|
150
|
+
static getCacheSize() {
|
|
99
151
|
return this.drivers.size;
|
|
100
152
|
}
|
|
101
153
|
/**
|
|
102
|
-
*
|
|
154
|
+
* Removes a specific driver from the cache.
|
|
155
|
+
* Useful when credentials have changed for a specific configuration.
|
|
156
|
+
*/
|
|
157
|
+
static removeFromCache(config) {
|
|
158
|
+
const driverKey = this.getDriverKey(config);
|
|
159
|
+
return this.drivers.delete(driverKey);
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Returns a list of all supported driver types.
|
|
103
163
|
*/
|
|
104
164
|
static getAvailableDrivers() {
|
|
105
165
|
return [
|
|
@@ -108,8 +168,8 @@ export class StorageDriverFactory {
|
|
|
108
168
|
's3-presigned',
|
|
109
169
|
'gcs',
|
|
110
170
|
'gcs-presigned',
|
|
111
|
-
'
|
|
112
|
-
'
|
|
171
|
+
'azure',
|
|
172
|
+
'azure-presigned'
|
|
113
173
|
];
|
|
114
174
|
}
|
|
115
175
|
}
|
|
@@ -1 +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,
|
|
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,kBAAkB,EAAE,2BAA2B,EAAE,MAAM,4BAA4B,CAAC;AAE7F,MAAM,kBAAkB,GAAG,GAAG,CAAC;AAO/B;;;;;;;GAOG;AACH,MAAM,OAAO,oBA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1,30 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Express Storage
|
|
3
|
+
*
|
|
4
|
+
* Unified file upload and storage management for Express.js.
|
|
5
|
+
* One API for local disk, AWS S3, Google Cloud Storage, and Azure Blob Storage.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* import { StorageManager } from 'express-storage';
|
|
9
|
+
*
|
|
10
|
+
* // Initialize (reads from environment variables)
|
|
11
|
+
* const storage = new StorageManager();
|
|
12
|
+
*
|
|
13
|
+
* // Upload a file
|
|
14
|
+
* const result = await storage.uploadFile(req.file);
|
|
15
|
+
*
|
|
16
|
+
* // Generate presigned URL for client-side upload
|
|
17
|
+
* const url = await storage.generateUploadUrl('photo.jpg', 'image/jpeg', 12345);
|
|
18
|
+
*/
|
|
2
19
|
export { StorageManager } from './storage-manager.js';
|
|
3
20
|
export { StorageDriverFactory } from './factory/driver.factory.js';
|
|
4
|
-
export type { StorageDriver, FileUploadResult, PresignedUrlResult, StorageConfig, FileInput, SingleFileInput, MultipleFilesInput, IStorageDriver,
|
|
5
|
-
export { loadAndValidateConfig, validateStorageConfig } from './utils/config.utils.js';
|
|
6
|
-
export { generateUniqueFileName, sanitizeFileName, createMonthBasedPath, ensureDirectoryExists, formatFileSize, validateFileSize, validateFileType,
|
|
21
|
+
export type { StorageDriver, FileUploadResult, DeleteResult, PresignedUrlResult, StorageConfig, StorageOptions, StorageCredentials, FileValidationOptions, UploadOptions, FileMetadata, FileInput, SingleFileInput, MultipleFilesInput, IStorageDriver, ValidationResult, EnvironmentConfig, BlobValidationOptions, BlobValidationResult, ListFilesResult, FileInfo, Logger, RateLimitOptions } from './types/storage.types.js';
|
|
22
|
+
export { loadAndValidateConfig, validateStorageConfig, initializeDotenv, resetDotenvInitialization } from './utils/config.utils.js';
|
|
23
|
+
export { generateUniqueFileName, sanitizeFileName, validateFileName, createMonthBasedPath, ensureDirectoryExists, formatFileSize, validateFileSize, validateFileType, getFileExtension, isImageFile, isDocumentFile, withRetry, sleep, withConcurrencyLimit } from './utils/file.utils.js';
|
|
24
|
+
export type { RetryOptions, ConcurrencyOptions } from './utils/file.utils.js';
|
|
7
25
|
export { BaseStorageDriver } from './drivers/base.driver.js';
|
|
8
26
|
export { LocalStorageDriver } from './drivers/local.driver.js';
|
|
9
27
|
export { S3StorageDriver, S3PresignedStorageDriver } from './drivers/s3.driver.js';
|
|
10
28
|
export { GCSStorageDriver, GCSPresignedStorageDriver } from './drivers/gcs.driver.js';
|
|
11
|
-
export {
|
|
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
|
+
export { AzureStorageDriver, AzurePresignedStorageDriver } from './drivers/azure.driver.js';
|
|
29
30
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],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1
|
+
/**
|
|
2
|
+
* Express Storage
|
|
3
|
+
*
|
|
4
|
+
* Unified file upload and storage management for Express.js.
|
|
5
|
+
* One API for local disk, AWS S3, Google Cloud Storage, and Azure Blob Storage.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* import { StorageManager } from 'express-storage';
|
|
9
|
+
*
|
|
10
|
+
* // Initialize (reads from environment variables)
|
|
11
|
+
* const storage = new StorageManager();
|
|
12
|
+
*
|
|
13
|
+
* // Upload a file
|
|
14
|
+
* const result = await storage.uploadFile(req.file);
|
|
15
|
+
*
|
|
16
|
+
* // Generate presigned URL for client-side upload
|
|
17
|
+
* const url = await storage.generateUploadUrl('photo.jpg', 'image/jpeg', 12345);
|
|
18
|
+
*/
|
|
19
|
+
// Main class
|
|
3
20
|
export { StorageManager } from './storage-manager.js';
|
|
21
|
+
// Factory
|
|
4
22
|
export { StorageDriverFactory } from './factory/driver.factory.js';
|
|
5
|
-
//
|
|
6
|
-
export { loadAndValidateConfig, validateStorageConfig } from './utils/config.utils.js';
|
|
7
|
-
|
|
8
|
-
|
|
23
|
+
// Configuration utilities
|
|
24
|
+
export { loadAndValidateConfig, validateStorageConfig, initializeDotenv, resetDotenvInitialization } from './utils/config.utils.js';
|
|
25
|
+
// File utilities
|
|
26
|
+
export { generateUniqueFileName, sanitizeFileName, validateFileName, createMonthBasedPath, ensureDirectoryExists, formatFileSize, validateFileSize, validateFileType, getFileExtension, isImageFile, isDocumentFile, withRetry, sleep, withConcurrencyLimit } from './utils/file.utils.js';
|
|
27
|
+
// Driver classes (for custom implementations or direct use)
|
|
9
28
|
export { BaseStorageDriver } from './drivers/base.driver.js';
|
|
10
29
|
export { LocalStorageDriver } from './drivers/local.driver.js';
|
|
11
30
|
export { S3StorageDriver, S3PresignedStorageDriver } from './drivers/s3.driver.js';
|
|
12
31
|
export { GCSStorageDriver, GCSPresignedStorageDriver } from './drivers/gcs.driver.js';
|
|
13
|
-
export {
|
|
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
|
-
}
|
|
32
|
+
export { AzureStorageDriver, AzurePresignedStorageDriver } from './drivers/azure.driver.js';
|
|
53
33
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,aAAa;AACb,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAEtD,UAAU;AACV,OAAO,EAAE,oBAAoB,EAAE,MAAM,6BAA6B,CAAC;AA4BnE,0BAA0B;AAC1B,OAAO,EAAE,qBAAqB,EAAE,qBAAqB,EAAE,gBAAgB,EAAE,yBAAyB,EAAE,MAAM,yBAAyB,CAAC;AAEpI,iBAAiB;AACjB,OAAO,EACL,sBAAsB,EACtB,gBAAgB,EAChB,gBAAgB,EAChB,oBAAoB,EACpB,qBAAqB,EACrB,cAAc,EACd,gBAAgB,EAChB,gBAAgB,EAChB,gBAAgB,EAChB,WAAW,EACX,cAAc,EACd,SAAS,EACT,KAAK,EACL,oBAAoB,EACrB,MAAM,uBAAuB,CAAC;AAG/B,4DAA4D;AAC5D,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,kBAAkB,EAAE,2BAA2B,EAAE,MAAM,2BAA2B,CAAC"}
|