@ackplus/nest-file-storage 0.1.51 → 1.1.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.
Files changed (50) hide show
  1. package/README.md +6 -404
  2. package/eslint.config.mjs +22 -0
  3. package/jest.config.ts +10 -0
  4. package/package.json +3 -45
  5. package/project.json +38 -0
  6. package/src/lib/constants.ts +1 -0
  7. package/src/lib/file-storage.service.ts +36 -0
  8. package/src/lib/interceptor/file-storage.interceptor.ts +174 -0
  9. package/src/lib/nest-file-storage.module.ts +78 -0
  10. package/src/lib/storage/azure.storage.ts +214 -0
  11. package/src/lib/storage/local.storage.ts +233 -0
  12. package/src/lib/storage/s3.storage.ts +242 -0
  13. package/src/lib/storage.factory.ts +58 -0
  14. package/src/lib/{types.d.ts → types.ts} +48 -22
  15. package/tsconfig.json +17 -0
  16. package/tsconfig.lib.json +14 -0
  17. package/tsconfig.spec.json +15 -0
  18. package/src/index.js +0 -8
  19. package/src/index.js.map +0 -1
  20. package/src/lib/constants.d.ts +0 -1
  21. package/src/lib/constants.js +0 -5
  22. package/src/lib/constants.js.map +0 -1
  23. package/src/lib/file-storage.service.d.ts +0 -7
  24. package/src/lib/file-storage.service.js +0 -31
  25. package/src/lib/file-storage.service.js.map +0 -1
  26. package/src/lib/index.js +0 -9
  27. package/src/lib/index.js.map +0 -1
  28. package/src/lib/interceptor/file-storage.interceptor.d.ts +0 -21
  29. package/src/lib/interceptor/file-storage.interceptor.js +0 -122
  30. package/src/lib/interceptor/file-storage.interceptor.js.map +0 -1
  31. package/src/lib/nest-file-storage.module.d.ts +0 -8
  32. package/src/lib/nest-file-storage.module.js +0 -75
  33. package/src/lib/nest-file-storage.module.js.map +0 -1
  34. package/src/lib/storage/azure.storage.d.ts +0 -18
  35. package/src/lib/storage/azure.storage.js +0 -153
  36. package/src/lib/storage/azure.storage.js.map +0 -1
  37. package/src/lib/storage/local.storage.d.ts +0 -17
  38. package/src/lib/storage/local.storage.js +0 -133
  39. package/src/lib/storage/local.storage.js.map +0 -1
  40. package/src/lib/storage/s3.storage.d.ts +0 -19
  41. package/src/lib/storage/s3.storage.js +0 -212
  42. package/src/lib/storage/s3.storage.js.map +0 -1
  43. package/src/lib/storage.factory.d.ts +0 -8
  44. package/src/lib/storage.factory.js +0 -49
  45. package/src/lib/storage.factory.js.map +0 -1
  46. package/src/lib/types.js +0 -10
  47. package/src/lib/types.js.map +0 -1
  48. package/tsconfig.tsbuildinfo +0 -1
  49. /package/src/{index.d.ts → index.ts} +0 -0
  50. /package/src/lib/{index.d.ts → index.ts} +0 -0
@@ -0,0 +1,242 @@
1
+ import { CopyObjectCommand, GetObjectCommandInput, S3 } from '@aws-sdk/client-s3';
2
+ import { DeleteObjectCommand, GetObjectCommand, GetObjectCommandOutput, HeadObjectCommand, PutObjectCommand } from '@aws-sdk/client-s3';
3
+ import { getSignedUrl } from '@aws-sdk/s3-request-presigner';
4
+ import moment from 'moment';
5
+ import { StorageEngine } from 'multer';
6
+ import path, { basename, join } from 'path';
7
+ import { Readable } from 'stream';
8
+ import { v4 as uuidv4 } from 'uuid';
9
+
10
+
11
+ import { S3StorageOptions, Storage, UploadedFile } from '../types';
12
+
13
+
14
+ export class S3Storage implements StorageEngine, Storage {
15
+
16
+ private s3: S3;
17
+ private fileNameFunction: (file: Express.Multer.File, req?: any) => string | Promise<string>;
18
+ private fileDistFunction: (file: Express.Multer.File, req?: any) => string | Promise<string>;
19
+
20
+ constructor(private options: S3StorageOptions) {
21
+ this.fileNameFunction = options.fileName || ((file, _req) => {
22
+ return `${uuidv4()}-${file.originalname}`;
23
+ });
24
+
25
+ this.fileDistFunction = options.fileDist || ((_file, _req) => {
26
+ return path.join('uploads', moment().format('YYYY'), moment().format('MM'), moment().format('DD'));
27
+ });
28
+
29
+ this.s3 = new S3({
30
+ ...(this.options.endpoint ? { endpoint: this.options.endpoint } : {}),
31
+ region: this.options.region,
32
+ credentials: {
33
+ accessKeyId: this.options.accessKeyId,
34
+ secretAccessKey: this.options.secretAccessKey,
35
+ },
36
+ });
37
+ }
38
+
39
+ async _handleFile(
40
+ req: any,
41
+ file: Express.Multer.File,
42
+ cb: (error?: any, info?: any) => void,
43
+ ): Promise<void> {
44
+ // Collect file chunks to determine size
45
+ const chunks: Uint8Array[] = [];
46
+ file.stream.on('data', (chunk) => chunks.push(chunk));
47
+ file.stream.on('end', async () => {
48
+ const buffer = Buffer.concat(chunks);
49
+
50
+ try {
51
+ const dist = await this.fileDistFunction(file, req);
52
+ const key = await this.fileNameFunction(file, req);
53
+ const filePath = join(dist, key);
54
+
55
+ const uploadedFile = await this.putFile(buffer, filePath);
56
+
57
+ const fileInfo: UploadedFile = {
58
+ ...uploadedFile,
59
+ fieldName: file.fieldname,
60
+ originalName: file.originalname,
61
+ mimetype: file.mimetype,
62
+ };
63
+ let transformData = fileInfo;
64
+
65
+ if (this.options?.transformUploadedFileObject) {
66
+ transformData = await this.options.transformUploadedFileObject(fileInfo);
67
+ }
68
+ cb(null, transformData);
69
+ } catch (err) {
70
+ cb(err);
71
+ }
72
+ });
73
+
74
+ file.stream.on('error', (err) => cb(err));
75
+ }
76
+
77
+ _removeFile(
78
+ _req: any,
79
+ file: any,
80
+ cb: (error: Error | null) => void,
81
+ ): void {
82
+ const params = {
83
+ Bucket: this.options.bucket,
84
+ Key: file.key,
85
+ };
86
+
87
+ this.s3
88
+ .deleteObject(params)
89
+ .then(() => cb(null))
90
+ .catch((err) => cb(err));
91
+ }
92
+
93
+ getUrl(key: string) {
94
+ if (this.options?.cloudFrontUrl) {
95
+ return `${this.options.cloudFrontUrl}/${key}`;
96
+ }
97
+ return `https://${this.options.bucket}.s3.amazonaws.com/${key}`;
98
+ }
99
+
100
+ async getSignedUrl(key: string, objectConfig?: Partial<GetObjectCommandInput>): Promise<string> {
101
+ if (key) {
102
+ const url = await getSignedUrl(
103
+ this.s3 as any,
104
+ new GetObjectCommand({
105
+ Bucket: this.options.bucket,
106
+ Key: key,
107
+ ...(objectConfig && { ...objectConfig }),
108
+ }),
109
+ );
110
+ return url;
111
+ }
112
+ return '';
113
+ }
114
+
115
+ async getFile(key: string): Promise<Buffer> {
116
+ if (!key) {
117
+ throw new Error('Key is required to fetch the file from S3.');
118
+ }
119
+
120
+ try {
121
+ const command = new GetObjectCommand({
122
+ Bucket: this.options.bucket,
123
+ Key: key,
124
+ });
125
+
126
+ const data: GetObjectCommandOutput = await this.s3.send(command);
127
+
128
+ if (!data.Body) {
129
+ throw new Error('Empty response received from S3.');
130
+ }
131
+
132
+ // Handle both Buffer and Readable Stream responses
133
+ if (data.Body instanceof Readable) {
134
+ return await this.streamToBuffer(data.Body);
135
+ }
136
+
137
+ throw new Error('Unexpected data.Body type received from S3.');
138
+ } catch (error) {
139
+ console.error(`Error fetching file (${key}) from S3:`, error);
140
+ throw error;
141
+ }
142
+ }
143
+
144
+
145
+ async putFile(fileContent: Buffer, key: string): Promise<any> {
146
+ try {
147
+ const fileName = basename(key);
148
+ const fileKey = key || (Math.random() + 1).toString(36).substring(12);
149
+
150
+ // Upload the file
151
+ const putParams = {
152
+ Bucket: this.options.bucket,
153
+ Key: fileKey,
154
+ Body: fileContent,
155
+ ContentDisposition: `inline; ${fileName}`,
156
+ };
157
+
158
+ await this.s3.send(new PutObjectCommand(putParams));
159
+
160
+ // Fetch file metadata to get size
161
+ const headParams = {
162
+ Bucket: this.options.bucket,
163
+ Key: fileKey,
164
+ };
165
+
166
+ const headObject = await this.s3.send(new HeadObjectCommand(headParams));
167
+ const fileSize = headObject.ContentLength || 0;
168
+
169
+ // Construct response object
170
+ const fileData: UploadedFile = {
171
+ originalName: fileName,
172
+ fileName: fileName,
173
+ size: fileSize,
174
+ buffer: fileContent,
175
+ fullPath: fileKey,
176
+ key: fileKey,
177
+ url: this.getUrl(fileKey),
178
+ };
179
+ return fileData;
180
+ } catch (error) {
181
+ console.error('Error uploading file to S3:', error);
182
+ throw error;
183
+ }
184
+ }
185
+
186
+
187
+ async deleteFile(key: string): Promise<void> {
188
+ if (!key) {
189
+ throw new Error('File key is required for deletion.');
190
+ }
191
+
192
+ try {
193
+ const deleteParams = {
194
+ Bucket: this.options.bucket,
195
+ Key: key,
196
+ };
197
+
198
+ await this.s3.send(new DeleteObjectCommand(deleteParams));
199
+ } catch (error) {
200
+ console.error(`Error deleting file (${key}) from S3:`, error);
201
+ throw error;
202
+ }
203
+ }
204
+
205
+
206
+ private async streamToBuffer(stream: Readable): Promise<Buffer> {
207
+ const chunks: Uint8Array[] = [];
208
+ for await (const chunk of stream) {
209
+ chunks.push(chunk);
210
+ }
211
+ return Buffer.concat(chunks);
212
+ }
213
+
214
+ async copyFile(oldKey: string, newKey: string): Promise<UploadedFile> {
215
+ try {
216
+ await this.s3.send(new CopyObjectCommand({
217
+ Bucket: this.options.bucket,
218
+ CopySource: `/${this.options.bucket}/${oldKey}`,
219
+ Key: newKey,
220
+ }));
221
+
222
+ const headObject = await this.s3.send(new HeadObjectCommand({
223
+ Bucket: this.options.bucket,
224
+ Key: newKey,
225
+ }));
226
+
227
+ return {
228
+ originalName: basename(newKey),
229
+ size: headObject.ContentLength || 0,
230
+ fileName: basename(newKey),
231
+ key: newKey,
232
+ fullPath: newKey,
233
+ url: this.getUrl(newKey),
234
+ };
235
+ } catch (error) {
236
+ console.error('Error copying file in S3:', error);
237
+ throw error;
238
+ }
239
+ }
240
+
241
+
242
+ }
@@ -0,0 +1,58 @@
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
+ }
@@ -1,16 +1,20 @@
1
1
  import { ModuleMetadata, Type } from '@nestjs/common';
2
2
  import { Request } from 'express';
3
- export declare enum FileStorageEnum {
4
- LOCAL = "local",
5
- S3 = "s3",
6
- AZURE = "azure"
3
+
4
+
5
+ export enum FileStorageEnum {
6
+ LOCAL = 'local',
7
+ S3 = 's3',
8
+ AZURE = 'azure',
7
9
  }
10
+
8
11
  export interface FileStorageOptions {
9
12
  prefix?: string;
10
- fileName?: (file: any, req: Request) => string;
11
- fileDist?: (file: any, req: Request) => string;
13
+ fileName?: (file: any, req: Request) => string; // Custom file key
14
+ fileDist?: (file: any, req: Request) => string; // Custom file dist
12
15
  transformUploadedFileObject?: (file: any) => any;
13
16
  }
17
+
14
18
  export interface S3StorageOptions extends FileStorageOptions {
15
19
  accessKeyId: string;
16
20
  secretAccessKey: string;
@@ -19,53 +23,75 @@ export interface S3StorageOptions extends FileStorageOptions {
19
23
  endpoint?: string;
20
24
  cloudFrontUrl?: string;
21
25
  }
26
+
22
27
  export interface LocalStorageOptions extends FileStorageOptions {
23
28
  rootPath: string;
24
29
  baseUrl: string;
25
30
  }
31
+
26
32
  export interface AzureStorageOptions extends FileStorageOptions {
27
33
  account: string;
28
34
  accountKey: string;
29
35
  container: string;
30
36
  }
37
+
31
38
  export type StorageOptions = S3StorageOptions | AzureStorageOptions | LocalStorageOptions;
32
- export type FileStorageConfigOptions = {
33
- storage: FileStorageEnum.LOCAL;
34
- localConfig: LocalStorageOptions;
35
- } | {
36
- storage: FileStorageEnum.S3;
37
- s3Config: S3StorageOptions;
38
- } | {
39
- storage: FileStorageEnum.AZURE;
40
- azureConfig: AzureStorageOptions;
41
- };
39
+
40
+ // Define discriminated union types - Configuration-based approach
41
+ export type FileStorageConfigOptions =
42
+ | { storage: FileStorageEnum.LOCAL; localConfig: LocalStorageOptions; }
43
+ | { storage: FileStorageEnum.S3; s3Config: S3StorageOptions; }
44
+ | { storage: FileStorageEnum.AZURE; azureConfig: AzureStorageOptions; };
45
+
46
+ // Class factory approach - for direct storage instance usage
42
47
  export interface FileStorageClassOptions {
43
48
  storageFactory: () => Promise<new (...args: any[]) => Storage> | (new (...args: any[]) => Storage);
44
49
  options?: any;
45
50
  }
51
+
52
+ // Combined module options
46
53
  export type FileStorageModuleOptions = FileStorageConfigOptions | FileStorageClassOptions;
54
+
55
+
47
56
  export interface FileStorageAsyncOptions extends Pick<ModuleMetadata, 'imports'> {
57
+ /**
58
+ * The `useExisting` syntax allows you to create aliases for existing providers.
59
+ */
48
60
  useExisting?: Type<FileStorageOptionsFactory>;
61
+ /**
62
+ * The `useClass` syntax allows you to dynamically determine a class
63
+ * that a token should resolve to.
64
+ */
49
65
  useClass?: Type<FileStorageOptionsFactory>;
66
+ /**
67
+ * The `useFactory` syntax allows for creating providers dynamically.
68
+ */
50
69
  useFactory?: (...args: any[]) => Promise<FileStorageModuleOptions> | FileStorageModuleOptions;
70
+ /**
71
+ * Optional list of providers to be injected into the context of the Factory function.
72
+ */
51
73
  inject?: any[];
52
74
  }
75
+
53
76
  export interface FileStorageOptionsFactory {
54
77
  createFileStorageOptions(): Promise<FileStorageModuleOptions> | FileStorageModuleOptions;
55
78
  }
79
+
80
+
56
81
  export interface UploadedFile {
57
82
  fieldName?: string;
58
83
  fieldname?: string;
59
84
  fileName: string;
60
- originalName: string;
61
- size: number;
85
+ originalName: string; // original file name
86
+ size: number; // files in bytes
62
87
  mimetype?: string;
63
88
  buffer?: Buffer;
64
- key: string;
65
- url: string;
66
- fullPath: string;
89
+ key: string; // path of the file in storage
90
+ url: string; // file public url
91
+ fullPath: string; // Full path of the file
67
92
  encoding?: string;
68
93
  }
94
+
69
95
  export interface Storage {
70
96
  getFile(key: string): Promise<Buffer> | Buffer;
71
97
  deleteFile(key: string): Promise<void> | void;
@@ -73,5 +99,5 @@ export interface Storage {
73
99
  path?(filePath: string): Promise<string> | string;
74
100
  getUrl(key: string): Promise<string> | string;
75
101
  getSignedUrl?(key: string, options: any): Promise<string> | string;
76
- copyFile(oldKey: string, newKey: string): Promise<UploadedFile>;
102
+ copyFile(oldKey: string, newKey: string): Promise<UploadedFile>
77
103
  }
package/tsconfig.json ADDED
@@ -0,0 +1,17 @@
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
+ }
@@ -0,0 +1,14 @@
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
+ }
@@ -0,0 +1,15 @@
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
+ }
package/src/index.js DELETED
@@ -1,8 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const tslib_1 = require("tslib");
4
- tslib_1.__exportStar(require("./lib/nest-file-storage.module"), exports);
5
- tslib_1.__exportStar(require("./lib/file-storage.service"), exports);
6
- tslib_1.__exportStar(require("./lib/interceptor/file-storage.interceptor"), exports);
7
- tslib_1.__exportStar(require("./lib/types"), exports);
8
- //# sourceMappingURL=index.js.map
package/src/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../packages/nest-file-storage/src/index.ts"],"names":[],"mappings":";;;AAAA,yEAA+C;AAC/C,qEAA2C;AAC3C,qFAA2D;AAC3D,sDAA4B"}
@@ -1 +0,0 @@
1
- export declare const FILE_STORAGE_OPTIONS = "FileStorageOptions";
@@ -1,5 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.FILE_STORAGE_OPTIONS = void 0;
4
- exports.FILE_STORAGE_OPTIONS = 'FileStorageOptions';
5
- //# sourceMappingURL=constants.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../../../packages/nest-file-storage/src/lib/constants.ts"],"names":[],"mappings":";;;AAAa,QAAA,oBAAoB,GAAG,oBAAoB,CAAC"}
@@ -1,7 +0,0 @@
1
- import { FileStorageEnum, FileStorageModuleOptions } from './types';
2
- export declare class FileStorageService {
3
- private static options;
4
- static setOptions(options: FileStorageModuleOptions): void;
5
- static getOptions(): FileStorageModuleOptions;
6
- static getStorage(storageType?: FileStorageEnum): Promise<import("./types").Storage>;
7
- }
@@ -1,31 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.FileStorageService = void 0;
4
- const tslib_1 = require("tslib");
5
- const storage_factory_1 = require("./storage.factory");
6
- class FileStorageService {
7
- static setOptions(options) {
8
- FileStorageService.options = options;
9
- }
10
- static getOptions() {
11
- return FileStorageService.options;
12
- }
13
- static getStorage(storageType) {
14
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
15
- const options = this.getOptions();
16
- if ('storageFactory' in options) {
17
- const classOptions = options;
18
- const StorageClass = yield classOptions.storageFactory();
19
- return new StorageClass(classOptions.options);
20
- }
21
- const configOptions = options;
22
- if (!storageType) {
23
- storageType = configOptions.storage;
24
- }
25
- const config = configOptions[`${storageType}Config`];
26
- return yield storage_factory_1.StorageFactory.createStorage(storageType, config);
27
- });
28
- }
29
- }
30
- exports.FileStorageService = FileStorageService;
31
- //# sourceMappingURL=file-storage.service.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"file-storage.service.js","sourceRoot":"","sources":["../../../../../packages/nest-file-storage/src/lib/file-storage.service.ts"],"names":[],"mappings":";;;;AAAA,uDAAmD;AAInD,MAAa,kBAAkB;IAI3B,MAAM,CAAC,UAAU,CAAC,OAAiC;QAC/C,kBAAkB,CAAC,OAAO,GAAG,OAAO,CAAC;IACzC,CAAC;IAED,MAAM,CAAC,UAAU;QACb,OAAO,kBAAkB,CAAC,OAAO,CAAC;IACtC,CAAC;IAED,MAAM,CAAO,UAAU,CAAC,WAA6B;;YACjD,MAAM,OAAO,GAAG,IAAI,CAAC,UAAU,EAAE,CAAC;YAGlC,IAAI,gBAAgB,IAAI,OAAO,EAAE,CAAC;gBAC9B,MAAM,YAAY,GAAG,OAAkC,CAAC;gBACxD,MAAM,YAAY,GAAG,MAAM,YAAY,CAAC,cAAc,EAAE,CAAC;gBACzD,OAAO,IAAI,YAAY,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC;YAClD,CAAC;YAGD,MAAM,aAAa,GAAG,OAAmC,CAAC;YAC1D,IAAI,CAAC,WAAW,EAAE,CAAC;gBACf,WAAW,GAAG,aAAa,CAAC,OAAO,CAAC;YACxC,CAAC;YACD,MAAM,MAAM,GAAG,aAAa,CAAC,GAAG,WAAW,QAAQ,CAAC,CAAC;YACrD,OAAO,MAAM,gCAAc,CAAC,aAAa,CAAC,WAAW,EAAE,MAAM,CAAC,CAAC;QACnE,CAAC;KAAA;CAEJ;AA/BD,gDA+BC"}
package/src/lib/index.js DELETED
@@ -1,9 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const tslib_1 = require("tslib");
4
- tslib_1.__exportStar(require("./nest-file-storage.module"), exports);
5
- tslib_1.__exportStar(require("./types"), exports);
6
- tslib_1.__exportStar(require("./storage.factory"), exports);
7
- tslib_1.__exportStar(require("./interceptor/file-storage.interceptor"), exports);
8
- tslib_1.__exportStar(require("./file-storage.service"), exports);
9
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../packages/nest-file-storage/src/lib/index.ts"],"names":[],"mappings":";;;AAAA,qEAA2C;AAC3C,kDAAwB;AACxB,4DAAkC;AAClC,iFAAuD;AACvD,iEAAuC"}
@@ -1,21 +0,0 @@
1
- import { NestInterceptor } from '@nestjs/common';
2
- import { Request } from 'express';
3
- import { FileStorageEnum, StorageOptions } from '../types';
4
- export type FileUploadConfig = {
5
- type: 'single' | 'array' | 'fields';
6
- fieldName?: string;
7
- maxCount?: number;
8
- fields?: {
9
- name: string;
10
- maxCount?: number;
11
- }[];
12
- };
13
- export type FileStorageInterceptorOptions = {
14
- fileName?: (file: any, req?: Request) => string;
15
- fileDist?: (file: any, req?: Request) => string;
16
- prefix?: string;
17
- storageType?: FileStorageEnum;
18
- storageOptions?: StorageOptions;
19
- mapToRequestBody?: (file: any, fieldName: string, req?: Request) => any;
20
- };
21
- export declare function FileStorageInterceptor(fileConfig: FileUploadConfig | string, interceptorOptions?: FileStorageInterceptorOptions): NestInterceptor;