@ackplus/nest-file-storage 1.1.1 → 1.1.5
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/package.json +2 -2
- package/src/{index.ts → index.d.ts} +1 -0
- package/src/index.d.ts.map +1 -0
- package/src/index.js +7 -0
- package/src/lib/constants.d.ts +2 -0
- package/src/lib/constants.d.ts.map +1 -0
- package/src/lib/constants.js +4 -0
- package/src/lib/file-storage.service.d.ts +8 -0
- package/src/lib/file-storage.service.d.ts.map +1 -0
- package/src/lib/file-storage.service.js +29 -0
- package/src/lib/{index.ts → index.d.ts} +1 -0
- package/src/lib/index.d.ts.map +1 -0
- package/src/lib/index.js +8 -0
- package/src/lib/interceptor/file-storage.interceptor.d.ts +25 -0
- package/src/lib/interceptor/file-storage.interceptor.d.ts.map +1 -0
- package/src/lib/interceptor/{file-storage.interceptor.ts → file-storage.interceptor.js} +35 -71
- package/src/lib/nest-file-storage.module.d.ts +9 -0
- package/src/lib/nest-file-storage.module.d.ts.map +1 -0
- package/src/lib/nest-file-storage.module.js +74 -0
- package/src/lib/storage/azure.storage.d.ts +19 -0
- package/src/lib/storage/azure.storage.d.ts.map +1 -0
- package/src/lib/storage/{azure.storage.ts → azure.storage.js} +57 -118
- package/src/lib/storage/local.storage.d.ts +35 -0
- package/src/lib/storage/local.storage.d.ts.map +1 -0
- package/src/lib/storage/{local.storage.ts → local.storage.js} +44 -94
- package/src/lib/storage/s3.storage.d.ts +20 -0
- package/src/lib/storage/s3.storage.d.ts.map +1 -0
- package/src/lib/storage/{s3.storage.ts → s3.storage.js} +58 -105
- package/src/lib/storage.factory.d.ts +9 -0
- package/src/lib/storage.factory.d.ts.map +1 -0
- package/src/lib/storage.factory.js +81 -0
- package/src/lib/{types.ts → types.d.ts} +23 -35
- package/src/lib/types.d.ts.map +1 -0
- package/src/lib/types.js +9 -0
- package/eslint.config.mjs +0 -22
- package/jest.config.ts +0 -10
- package/project.json +0 -38
- package/src/lib/constants.ts +0 -1
- package/src/lib/file-storage.service.ts +0 -36
- package/src/lib/nest-file-storage.module.ts +0 -78
- package/src/lib/storage.factory.ts +0 -58
- package/tsconfig.json +0 -17
- package/tsconfig.lib.json +0 -14
- package/tsconfig.spec.json +0 -15
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
import { Module, DynamicModule, Provider } from '@nestjs/common';
|
|
2
|
-
|
|
3
|
-
import { FILE_STORAGE_OPTIONS } from './constants';
|
|
4
|
-
import { FileStorageService } from './file-storage.service';
|
|
5
|
-
import { FileStorageAsyncOptions, FileStorageModuleOptions, FileStorageOptionsFactory } from './types';
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
@Module({})
|
|
9
|
-
export class NestFileStorageModule {
|
|
10
|
-
|
|
11
|
-
static forRoot(options: FileStorageModuleOptions): DynamicModule {
|
|
12
|
-
return {
|
|
13
|
-
module: NestFileStorageModule,
|
|
14
|
-
providers: [
|
|
15
|
-
{
|
|
16
|
-
provide: FILE_STORAGE_OPTIONS,
|
|
17
|
-
useFactory: async () => {
|
|
18
|
-
FileStorageService.setOptions(options); // ✅ Store globally
|
|
19
|
-
return options;
|
|
20
|
-
},
|
|
21
|
-
inject: [],
|
|
22
|
-
},
|
|
23
|
-
FileStorageService,
|
|
24
|
-
],
|
|
25
|
-
exports: [],
|
|
26
|
-
};
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
static forRootAsync(options: FileStorageAsyncOptions): DynamicModule {
|
|
30
|
-
const asyncProviders: Provider[] = this.createAsyncProviders(options);
|
|
31
|
-
|
|
32
|
-
return {
|
|
33
|
-
module: NestFileStorageModule,
|
|
34
|
-
imports: options.imports || [],
|
|
35
|
-
providers: [...asyncProviders, FileStorageService],
|
|
36
|
-
exports: [],
|
|
37
|
-
};
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
private static createAsyncProviders(options: FileStorageAsyncOptions): Provider[] {
|
|
41
|
-
if (options.useExisting || options.useFactory) {
|
|
42
|
-
return [this.createAsyncOptionsProvider(options)];
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
return [
|
|
46
|
-
this.createAsyncOptionsProvider(options),
|
|
47
|
-
{
|
|
48
|
-
provide: options.useClass!,
|
|
49
|
-
useClass: options.useClass!,
|
|
50
|
-
},
|
|
51
|
-
];
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
private static createAsyncOptionsProvider(options: FileStorageAsyncOptions): Provider {
|
|
55
|
-
if (options.useFactory) {
|
|
56
|
-
return {
|
|
57
|
-
provide: FILE_STORAGE_OPTIONS,
|
|
58
|
-
useFactory: async (...args: any[]) => {
|
|
59
|
-
const fileStorageOptions = await options.useFactory!(...args);
|
|
60
|
-
FileStorageService.setOptions(fileStorageOptions);
|
|
61
|
-
return fileStorageOptions;
|
|
62
|
-
},
|
|
63
|
-
inject: options.inject || [],
|
|
64
|
-
};
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
return {
|
|
68
|
-
provide: FILE_STORAGE_OPTIONS,
|
|
69
|
-
useFactory: async (optionsFactory: FileStorageOptionsFactory) => {
|
|
70
|
-
const fileStorageOptions = await optionsFactory.createFileStorageOptions();
|
|
71
|
-
FileStorageService.setOptions(fileStorageOptions);
|
|
72
|
-
return fileStorageOptions;
|
|
73
|
-
},
|
|
74
|
-
inject: [options.useExisting || options.useClass!],
|
|
75
|
-
};
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
}
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
import { AzureStorageOptions, FileStorageEnum, LocalStorageOptions, S3StorageOptions, StorageOptions } from './types';
|
|
2
|
-
import { StorageEngine } from 'multer';
|
|
3
|
-
import { Storage } from './types';
|
|
4
|
-
|
|
5
|
-
export class StorageFactory {
|
|
6
|
-
private static storageInstances = new Map<string, StorageEngine & Storage>();
|
|
7
|
-
|
|
8
|
-
static async createStorage(storageType: FileStorageEnum, options: StorageOptions): Promise<StorageEngine & Storage> {
|
|
9
|
-
const cacheKey = `${storageType}-${JSON.stringify(options)}`;
|
|
10
|
-
|
|
11
|
-
// if (this.storageInstances.has(cacheKey)) {
|
|
12
|
-
// return this.storageInstances.get(cacheKey)!;
|
|
13
|
-
// }
|
|
14
|
-
|
|
15
|
-
let storageInstance: StorageEngine & Storage;
|
|
16
|
-
|
|
17
|
-
switch (storageType) {
|
|
18
|
-
case FileStorageEnum.LOCAL:
|
|
19
|
-
const { LocalStorage } = await import('./storage/local.storage');
|
|
20
|
-
storageInstance = new LocalStorage(options as LocalStorageOptions);
|
|
21
|
-
break;
|
|
22
|
-
|
|
23
|
-
case FileStorageEnum.AZURE:
|
|
24
|
-
try {
|
|
25
|
-
const { AzureStorage } = await import('./storage/azure.storage');
|
|
26
|
-
storageInstance = new AzureStorage(options as AzureStorageOptions);
|
|
27
|
-
} catch (error) {
|
|
28
|
-
throw new Error(
|
|
29
|
-
'Azure Storage SDK (@azure/storage-blob) is required when using AzureStorage. ' +
|
|
30
|
-
'Please install it: npm install @azure/storage-blob'
|
|
31
|
-
);
|
|
32
|
-
}
|
|
33
|
-
break;
|
|
34
|
-
|
|
35
|
-
case FileStorageEnum.S3:
|
|
36
|
-
try {
|
|
37
|
-
const { S3Storage } = await import('./storage/s3.storage');
|
|
38
|
-
storageInstance = new S3Storage(options as S3StorageOptions);
|
|
39
|
-
} catch (error) {
|
|
40
|
-
throw new Error(
|
|
41
|
-
'AWS SDK (@aws-sdk/client-s3 and @aws-sdk/s3-request-presigner) is required when using S3Storage. ' +
|
|
42
|
-
'Please install them: npm install @aws-sdk/client-s3 @aws-sdk/s3-request-presigner'
|
|
43
|
-
);
|
|
44
|
-
}
|
|
45
|
-
break;
|
|
46
|
-
|
|
47
|
-
default:
|
|
48
|
-
throw new Error(`Unsupported storage type: ${storageType}`);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
this.storageInstances.set(cacheKey, storageInstance);
|
|
52
|
-
return storageInstance;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
static clearCache() {
|
|
56
|
-
this.storageInstances.clear();
|
|
57
|
-
}
|
|
58
|
-
}
|
package/tsconfig.json
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"extends": "../../tsconfig.base.json",
|
|
3
|
-
"compilerOptions": {
|
|
4
|
-
"module": "commonjs",
|
|
5
|
-
"forceConsistentCasingInFileNames": true,
|
|
6
|
-
},
|
|
7
|
-
"files": [],
|
|
8
|
-
"include": [],
|
|
9
|
-
"references": [
|
|
10
|
-
{
|
|
11
|
-
"path": "./tsconfig.lib.json"
|
|
12
|
-
},
|
|
13
|
-
{
|
|
14
|
-
"path": "./tsconfig.spec.json"
|
|
15
|
-
}
|
|
16
|
-
]
|
|
17
|
-
}
|
package/tsconfig.lib.json
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"extends": "./tsconfig.json",
|
|
3
|
-
"compilerOptions": {
|
|
4
|
-
"outDir": "../../dist/out-tsc",
|
|
5
|
-
"declaration": true,
|
|
6
|
-
"types": ["node"],
|
|
7
|
-
"target": "es2021",
|
|
8
|
-
"experimentalDecorators": true,
|
|
9
|
-
"emitDecoratorMetadata": true,
|
|
10
|
-
"forceConsistentCasingInFileNames": true
|
|
11
|
-
},
|
|
12
|
-
"include": ["src/**/*.ts"],
|
|
13
|
-
"exclude": ["jest.config.ts", "src/**/*.spec.ts", "src/**/*.test.ts"]
|
|
14
|
-
}
|
package/tsconfig.spec.json
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"extends": "./tsconfig.json",
|
|
3
|
-
"compilerOptions": {
|
|
4
|
-
"outDir": "../../dist/out-tsc",
|
|
5
|
-
"module": "commonjs",
|
|
6
|
-
"moduleResolution": "node10",
|
|
7
|
-
"types": ["jest", "node"]
|
|
8
|
-
},
|
|
9
|
-
"include": [
|
|
10
|
-
"jest.config.ts",
|
|
11
|
-
"src/**/*.test.ts",
|
|
12
|
-
"src/**/*.spec.ts",
|
|
13
|
-
"src/**/*.d.ts"
|
|
14
|
-
]
|
|
15
|
-
}
|