@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
package/package.json
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../packages/nest-file-storage/src/index.ts"],"names":[],"mappings":"AAAA,cAAc,gCAAgC,CAAC;AAC/C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,4CAA4C,CAAC;AAC3D,cAAc,aAAa,CAAC"}
|
package/src/index.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
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);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../../../../packages/nest-file-storage/src/lib/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,oBAAoB,uBAAuB,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
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
|
+
}
|
|
8
|
+
//# sourceMappingURL=file-storage.service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"file-storage.service.d.ts","sourceRoot":"","sources":["../../../../../packages/nest-file-storage/src/lib/file-storage.service.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,wBAAwB,EAAqD,MAAM,SAAS,CAAC;AAGvH,qBAAa,kBAAkB;IAE3B,OAAO,CAAC,MAAM,CAAC,OAAO,CAA2B;IAEjD,MAAM,CAAC,UAAU,CAAC,OAAO,EAAE,wBAAwB;IAInD,MAAM,CAAC,UAAU,IAAI,wBAAwB;WAIhC,UAAU,CAAC,WAAW,CAAC,EAAE,eAAe;CAmBxD"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FileStorageService = void 0;
|
|
4
|
+
const storage_factory_1 = require("./storage.factory");
|
|
5
|
+
class FileStorageService {
|
|
6
|
+
static setOptions(options) {
|
|
7
|
+
FileStorageService.options = options;
|
|
8
|
+
}
|
|
9
|
+
static getOptions() {
|
|
10
|
+
return FileStorageService.options;
|
|
11
|
+
}
|
|
12
|
+
static async getStorage(storageType) {
|
|
13
|
+
const options = this.getOptions();
|
|
14
|
+
// Check if it's a class factory approach
|
|
15
|
+
if ('storageFactory' in options) {
|
|
16
|
+
const classOptions = options;
|
|
17
|
+
const StorageClass = await classOptions.storageFactory();
|
|
18
|
+
return new StorageClass(classOptions.options);
|
|
19
|
+
}
|
|
20
|
+
// Configuration-based approach
|
|
21
|
+
const configOptions = options;
|
|
22
|
+
if (!storageType) {
|
|
23
|
+
storageType = configOptions.storage;
|
|
24
|
+
}
|
|
25
|
+
const config = configOptions[`Config`];
|
|
26
|
+
return await storage_factory_1.StorageFactory.createStorage(storageType, config);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
exports.FileStorageService = FileStorageService;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../packages/nest-file-storage/src/lib/index.ts"],"names":[],"mappings":"AAAA,cAAc,4BAA4B,CAAC;AAC3C,cAAc,SAAS,CAAC;AACxB,cAAc,mBAAmB,CAAC;AAClC,cAAc,wCAAwC,CAAC;AACvD,cAAc,wBAAwB,CAAC"}
|
package/src/lib/index.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
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);
|
|
@@ -0,0 +1,25 @@
|
|
|
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
|
+
/**
|
|
22
|
+
* Function-based interceptor that accepts storage options dynamically.
|
|
23
|
+
*/
|
|
24
|
+
export declare function FileStorageInterceptor(fileConfig: FileUploadConfig | string, interceptorOptions?: FileStorageInterceptorOptions): NestInterceptor;
|
|
25
|
+
//# sourceMappingURL=file-storage.interceptor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"file-storage.interceptor.d.ts","sourceRoot":"","sources":["../../../../../../packages/nest-file-storage/src/lib/interceptor/file-storage.interceptor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAiC,MAAM,gBAAgB,CAAC;AAChF,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAMlC,OAAO,EAAE,eAAe,EAAE,cAAc,EAA0C,MAAM,UAAU,CAAC;AAGnG,MAAM,MAAM,gBAAgB,GAAG;IAC3B,IAAI,EAAE,QAAQ,GAAG,OAAO,GAAG,QAAQ,CAAC;IACpC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,MAAM,CAAC,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC;CAClD,CAAC;AAEF,MAAM,MAAM,6BAA6B,GAAG;IACxC,QAAQ,CAAC,EAAE,CAAC,IAAI,EAAE,GAAG,EAAE,GAAG,CAAC,EAAE,OAAO,KAAK,MAAM,CAAC;IAChD,QAAQ,CAAC,EAAE,CAAC,IAAI,EAAE,GAAG,EAAE,GAAG,CAAC,EAAE,OAAO,KAAK,MAAM,CAAC;IAChD,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,WAAW,CAAC,EAAE,eAAe,CAAC;IAC9B,cAAc,CAAC,EAAE,cAAc,CAAC;IAGhC,gBAAgB,CAAC,EAAE,CAAC,IAAI,EAAE,GAAG,EAAE,SAAS,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,OAAO,KAAK,GAAG,CAAC;CAC3E,CAAC;AA2DF;;GAEG;AACH,wBAAgB,sBAAsB,CAClC,UAAU,EAAE,gBAAgB,GAAG,MAAM,EACrC,kBAAkB,CAAC,EAAE,6BAA6B,GACnD,eAAe,CAkFjB"}
|
|
@@ -1,55 +1,30 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
export type FileUploadConfig = {
|
|
12
|
-
type: 'single' | 'array' | 'fields';
|
|
13
|
-
fieldName?: string;
|
|
14
|
-
maxCount?: number;
|
|
15
|
-
fields?: { name: string; maxCount?: number }[];
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
export type FileStorageInterceptorOptions = {
|
|
19
|
-
fileName?: (file: any, req?: Request) => string;
|
|
20
|
-
fileDist?: (file: any, req?: Request) => string;
|
|
21
|
-
prefix?: string;
|
|
22
|
-
storageType?: FileStorageEnum;
|
|
23
|
-
storageOptions?: StorageOptions;
|
|
24
|
-
|
|
25
|
-
// File mapping callback - user defines what to return (defaults to file.key)
|
|
26
|
-
mapToRequestBody?: (file: any, fieldName: string, req?: Request) => any;
|
|
27
|
-
};
|
|
28
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FileStorageInterceptor = FileStorageInterceptor;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const multer_1 = tslib_1.__importDefault(require("multer"));
|
|
6
|
+
const file_storage_service_1 = require("../file-storage.service");
|
|
7
|
+
const storage_factory_1 = require("../storage.factory");
|
|
8
|
+
const types_1 = require("../types");
|
|
29
9
|
// Helper function to map file object
|
|
30
|
-
function mapFileObject(file
|
|
10
|
+
function mapFileObject(file) {
|
|
31
11
|
return {
|
|
32
12
|
fieldName: file.fieldname,
|
|
33
13
|
originalName: file.originalname,
|
|
34
14
|
fileName: file.filename,
|
|
35
15
|
mimetype: file.mimetype,
|
|
36
16
|
size: file.size,
|
|
37
|
-
key:
|
|
38
|
-
path:
|
|
39
|
-
url:
|
|
17
|
+
key: file.key,
|
|
18
|
+
path: file.path,
|
|
19
|
+
url: file.url,
|
|
40
20
|
encoding: file.encoding,
|
|
41
|
-
fullPath:
|
|
42
|
-
}
|
|
21
|
+
fullPath: file.fullPath
|
|
22
|
+
};
|
|
43
23
|
}
|
|
44
|
-
|
|
45
24
|
// Helper function to apply file mapping with callback
|
|
46
|
-
function applyFileKeyMapping(
|
|
47
|
-
request: Request,
|
|
48
|
-
fileConfig: FileUploadConfig,
|
|
49
|
-
interceptorOptions?: FileStorageInterceptorOptions
|
|
50
|
-
): void {
|
|
25
|
+
function applyFileKeyMapping(request, fileConfig, interceptorOptions) {
|
|
51
26
|
// Default callback returns the file key
|
|
52
|
-
const mapCallback = interceptorOptions?.mapToRequestBody || ((file
|
|
27
|
+
const mapCallback = interceptorOptions?.mapToRequestBody || ((file) => {
|
|
53
28
|
// For arrays, return array of keys
|
|
54
29
|
if (Array.isArray(file)) {
|
|
55
30
|
return file.map(f => f.key);
|
|
@@ -57,7 +32,6 @@ function applyFileKeyMapping(
|
|
|
57
32
|
// For single file, return the key
|
|
58
33
|
return file.key;
|
|
59
34
|
});
|
|
60
|
-
|
|
61
35
|
if (fileConfig.type === 'single') {
|
|
62
36
|
const file = request.file;
|
|
63
37
|
if (file) {
|
|
@@ -65,15 +39,17 @@ function applyFileKeyMapping(
|
|
|
65
39
|
const mappedFile = mapFileObject(file);
|
|
66
40
|
request.body[fieldName] = mapCallback(mappedFile, fieldName, request);
|
|
67
41
|
}
|
|
68
|
-
}
|
|
69
|
-
|
|
42
|
+
}
|
|
43
|
+
else if (fileConfig.type === 'array') {
|
|
44
|
+
const files = request.files;
|
|
70
45
|
if (files && files.length > 0) {
|
|
71
46
|
const fieldName = fileConfig.fieldName || 'files';
|
|
72
47
|
const mappedFiles = files.map(file => mapFileObject(file));
|
|
73
48
|
request.body[fieldName] = mapCallback(mappedFiles, fieldName, request);
|
|
74
49
|
}
|
|
75
|
-
}
|
|
76
|
-
|
|
50
|
+
}
|
|
51
|
+
else if (fileConfig.type === 'fields') {
|
|
52
|
+
const files = request.files;
|
|
77
53
|
if (files) {
|
|
78
54
|
Object.keys(files).forEach(fieldName => {
|
|
79
55
|
const mappedFiles = files[fieldName].map(file => mapFileObject(file));
|
|
@@ -82,47 +58,40 @@ function applyFileKeyMapping(
|
|
|
82
58
|
}
|
|
83
59
|
}
|
|
84
60
|
}
|
|
85
|
-
|
|
86
61
|
/**
|
|
87
62
|
* Function-based interceptor that accepts storage options dynamically.
|
|
88
63
|
*/
|
|
89
|
-
|
|
90
|
-
fileConfig: FileUploadConfig | string,
|
|
91
|
-
interceptorOptions?: FileStorageInterceptorOptions,
|
|
92
|
-
): NestInterceptor {
|
|
64
|
+
function FileStorageInterceptor(fileConfig, interceptorOptions) {
|
|
93
65
|
if (typeof fileConfig === 'string') {
|
|
94
66
|
fileConfig = {
|
|
95
67
|
type: 'single',
|
|
96
68
|
fieldName: fileConfig,
|
|
97
69
|
};
|
|
98
70
|
}
|
|
99
|
-
|
|
100
71
|
return {
|
|
101
|
-
async intercept(context
|
|
102
|
-
const options = FileStorageService.getOptions();
|
|
72
|
+
async intercept(context, next) {
|
|
73
|
+
const options = file_storage_service_1.FileStorageService.getOptions();
|
|
103
74
|
const request = context.switchToHttp().getRequest();
|
|
104
75
|
const response = context.switchToHttp().getResponse();
|
|
105
|
-
|
|
106
76
|
// Determine storage type - handle both config approaches
|
|
107
|
-
let storageType
|
|
108
|
-
let storageConfig
|
|
109
|
-
|
|
77
|
+
let storageType;
|
|
78
|
+
let storageConfig;
|
|
110
79
|
if ('storage' in options) {
|
|
111
80
|
// Configuration-based approach
|
|
112
|
-
const configOptions = options
|
|
81
|
+
const configOptions = options;
|
|
113
82
|
storageType = interceptorOptions?.storageType ?? configOptions.storage;
|
|
114
|
-
storageConfig =
|
|
115
|
-
}
|
|
83
|
+
storageConfig = configOptions[`Config`];
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
116
86
|
// Class factory approach - default to LOCAL
|
|
117
|
-
storageType = interceptorOptions?.storageType ?? FileStorageEnum.LOCAL;
|
|
87
|
+
storageType = interceptorOptions?.storageType ?? types_1.FileStorageEnum.LOCAL;
|
|
118
88
|
storageConfig = {};
|
|
119
89
|
}
|
|
120
|
-
|
|
121
90
|
const storageOptions = {
|
|
122
91
|
...storageConfig,
|
|
123
92
|
...(interceptorOptions?.storageOptions || {}),
|
|
124
93
|
fileName: interceptorOptions?.fileName || storageConfig?.fileName,
|
|
125
|
-
fileDist: (file
|
|
94
|
+
fileDist: (file, req) => {
|
|
126
95
|
if (interceptorOptions?.fileDist) {
|
|
127
96
|
return interceptorOptions.fileDist(file, req);
|
|
128
97
|
}
|
|
@@ -130,11 +99,9 @@ export function FileStorageInterceptor(
|
|
|
130
99
|
},
|
|
131
100
|
prefix: interceptorOptions?.prefix || storageConfig?.prefix,
|
|
132
101
|
};
|
|
133
|
-
|
|
134
102
|
// Create storage instance dynamically
|
|
135
|
-
const storage = await StorageFactory.createStorage(storageType, storageOptions);
|
|
136
|
-
const multerInstance =
|
|
137
|
-
|
|
103
|
+
const storage = await storage_factory_1.StorageFactory.createStorage(storageType, storageOptions);
|
|
104
|
+
const multerInstance = (0, multer_1.default)({ storage });
|
|
138
105
|
// Multer setup based on fileConfig
|
|
139
106
|
let multerMiddleware;
|
|
140
107
|
switch (fileConfig.type) {
|
|
@@ -159,15 +126,12 @@ export function FileStorageInterceptor(
|
|
|
159
126
|
default:
|
|
160
127
|
throw new Error('Invalid file upload type. Use "single", "array", or "fields".');
|
|
161
128
|
}
|
|
162
|
-
|
|
163
129
|
// Execute Multer middleware
|
|
164
130
|
await new Promise((resolve, reject) => {
|
|
165
131
|
multerMiddleware(request, response, (err) => (err ? reject(err) : resolve(true)));
|
|
166
132
|
});
|
|
167
|
-
|
|
168
133
|
// Apply file key mapping after multer processing
|
|
169
134
|
applyFileKeyMapping(request, fileConfig, interceptorOptions);
|
|
170
|
-
|
|
171
135
|
return next.handle();
|
|
172
136
|
}
|
|
173
137
|
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { DynamicModule } from '@nestjs/common';
|
|
2
|
+
import { FileStorageAsyncOptions, FileStorageModuleOptions } from './types';
|
|
3
|
+
export declare class NestFileStorageModule {
|
|
4
|
+
static forRoot(options: FileStorageModuleOptions): DynamicModule;
|
|
5
|
+
static forRootAsync(options: FileStorageAsyncOptions): DynamicModule;
|
|
6
|
+
private static createAsyncProviders;
|
|
7
|
+
private static createAsyncOptionsProvider;
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=nest-file-storage.module.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nest-file-storage.module.d.ts","sourceRoot":"","sources":["../../../../../packages/nest-file-storage/src/lib/nest-file-storage.module.ts"],"names":[],"mappings":"AAAA,OAAO,EAAU,aAAa,EAAY,MAAM,gBAAgB,CAAC;AAIjE,OAAO,EAAE,uBAAuB,EAAE,wBAAwB,EAA6B,MAAM,SAAS,CAAC;AAGvG,qBACa,qBAAqB;IAE9B,MAAM,CAAC,OAAO,CAAC,OAAO,EAAE,wBAAwB,GAAG,aAAa;IAkBhE,MAAM,CAAC,YAAY,CAAC,OAAO,EAAE,uBAAuB,GAAG,aAAa;IAWpE,OAAO,CAAC,MAAM,CAAC,oBAAoB;IAcnC,OAAO,CAAC,MAAM,CAAC,0BAA0B;CAwB5C"}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var NestFileStorageModule_1;
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.NestFileStorageModule = void 0;
|
|
5
|
+
const tslib_1 = require("tslib");
|
|
6
|
+
const common_1 = require("@nestjs/common");
|
|
7
|
+
const constants_1 = require("./constants");
|
|
8
|
+
const file_storage_service_1 = require("./file-storage.service");
|
|
9
|
+
let NestFileStorageModule = NestFileStorageModule_1 = class NestFileStorageModule {
|
|
10
|
+
static forRoot(options) {
|
|
11
|
+
return {
|
|
12
|
+
module: NestFileStorageModule_1,
|
|
13
|
+
providers: [
|
|
14
|
+
{
|
|
15
|
+
provide: constants_1.FILE_STORAGE_OPTIONS,
|
|
16
|
+
useFactory: async () => {
|
|
17
|
+
file_storage_service_1.FileStorageService.setOptions(options); // ✅ Store globally
|
|
18
|
+
return options;
|
|
19
|
+
},
|
|
20
|
+
inject: [],
|
|
21
|
+
},
|
|
22
|
+
file_storage_service_1.FileStorageService,
|
|
23
|
+
],
|
|
24
|
+
exports: [],
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
static forRootAsync(options) {
|
|
28
|
+
const asyncProviders = this.createAsyncProviders(options);
|
|
29
|
+
return {
|
|
30
|
+
module: NestFileStorageModule_1,
|
|
31
|
+
imports: options.imports || [],
|
|
32
|
+
providers: [...asyncProviders, file_storage_service_1.FileStorageService],
|
|
33
|
+
exports: [],
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
static createAsyncProviders(options) {
|
|
37
|
+
if (options.useExisting || options.useFactory) {
|
|
38
|
+
return [this.createAsyncOptionsProvider(options)];
|
|
39
|
+
}
|
|
40
|
+
return [
|
|
41
|
+
this.createAsyncOptionsProvider(options),
|
|
42
|
+
{
|
|
43
|
+
provide: options.useClass,
|
|
44
|
+
useClass: options.useClass,
|
|
45
|
+
},
|
|
46
|
+
];
|
|
47
|
+
}
|
|
48
|
+
static createAsyncOptionsProvider(options) {
|
|
49
|
+
if (options.useFactory) {
|
|
50
|
+
return {
|
|
51
|
+
provide: constants_1.FILE_STORAGE_OPTIONS,
|
|
52
|
+
useFactory: async (...args) => {
|
|
53
|
+
const fileStorageOptions = await options.useFactory(...args);
|
|
54
|
+
file_storage_service_1.FileStorageService.setOptions(fileStorageOptions);
|
|
55
|
+
return fileStorageOptions;
|
|
56
|
+
},
|
|
57
|
+
inject: options.inject || [],
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
return {
|
|
61
|
+
provide: constants_1.FILE_STORAGE_OPTIONS,
|
|
62
|
+
useFactory: async (optionsFactory) => {
|
|
63
|
+
const fileStorageOptions = await optionsFactory.createFileStorageOptions();
|
|
64
|
+
file_storage_service_1.FileStorageService.setOptions(fileStorageOptions);
|
|
65
|
+
return fileStorageOptions;
|
|
66
|
+
},
|
|
67
|
+
inject: [options.useExisting || options.useClass],
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
exports.NestFileStorageModule = NestFileStorageModule;
|
|
72
|
+
exports.NestFileStorageModule = NestFileStorageModule = NestFileStorageModule_1 = tslib_1.__decorate([
|
|
73
|
+
(0, common_1.Module)({})
|
|
74
|
+
], NestFileStorageModule);
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { BlobSASSignatureValues } from '@azure/storage-blob';
|
|
2
|
+
import { StorageEngine } from 'multer';
|
|
3
|
+
import { AzureStorageOptions, Storage, UploadedFile } from '../types';
|
|
4
|
+
export declare class AzureStorage implements StorageEngine, Storage {
|
|
5
|
+
private options;
|
|
6
|
+
private blobServiceClient;
|
|
7
|
+
private fileNameFunction;
|
|
8
|
+
private fileDistFunction;
|
|
9
|
+
constructor(options: AzureStorageOptions);
|
|
10
|
+
_handleFile(req: any, file: any, cb: (error?: any, info?: any) => void): Promise<void>;
|
|
11
|
+
_removeFile(_req: any, file: any, cb: (error: Error | null) => void): Promise<void>;
|
|
12
|
+
getUrl(key: string): string;
|
|
13
|
+
getSignedUrl(key: string, signatureValues?: Partial<Omit<BlobSASSignatureValues, 'containerName'>>): string;
|
|
14
|
+
getFile(key: string): Promise<Buffer>;
|
|
15
|
+
putFile(buffer: Buffer, key: string): Promise<UploadedFile>;
|
|
16
|
+
deleteFile(key: string): Promise<void>;
|
|
17
|
+
copyFile(oldKey: string, newKey: string): Promise<UploadedFile>;
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=azure.storage.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"azure.storage.d.ts","sourceRoot":"","sources":["../../../../../../packages/nest-file-storage/src/lib/storage/azure.storage.ts"],"names":[],"mappings":"AAAA,OAAO,EAEH,sBAAsB,EAKzB,MAAM,qBAAqB,CAAC;AAG7B,OAAO,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAC;AAIvC,OAAO,EAAE,mBAAmB,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAGtE,qBAAa,YAAa,YAAW,aAAa,EAAE,OAAO;IAQ3C,OAAO,CAAC,OAAO;IAN3B,OAAO,CAAC,iBAAiB,CAAoB;IAE7C,OAAO,CAAC,gBAAgB,CAAqE;IAC7F,OAAO,CAAC,gBAAgB,CAAqE;gBAGzE,OAAO,EAAE,mBAAmB;IAoB1C,WAAW,CACb,GAAG,EAAE,GAAG,EACR,IAAI,EAAE,GAAG,EACT,EAAE,EAAE,CAAC,KAAK,CAAC,EAAE,GAAG,EAAE,IAAI,CAAC,EAAE,GAAG,KAAK,IAAI,GACtC,OAAO,CAAC,IAAI,CAAC;IA6BV,WAAW,CACb,IAAI,EAAE,GAAG,EACT,IAAI,EAAE,GAAG,EACT,EAAE,EAAE,CAAC,KAAK,EAAE,KAAK,GAAG,IAAI,KAAK,IAAI,GAClC,OAAO,CAAC,IAAI,CAAC;IAahB,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM;IAK3B,YAAY,CAAC,GAAG,EAAE,MAAM,EAAE,eAAe,GAAE,OAAO,CAAC,IAAI,CAAC,sBAAsB,EAAE,eAAe,CAAC,CAAM,GAAG,MAAM;IAqCzG,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAcrC,OAAO,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,CAAC;IAwB3D,UAAU,CAAC,GAAG,EAAE,MAAM;IAYtB,QAAQ,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,CAAC;CA0BxE"}
|