@ackplus/nest-file-storage 1.1.11 → 1.1.13-beta.1
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 +22 -0
- package/README.md +658 -6
- package/{src → dist}/index.d.ts +0 -1
- package/dist/index.js +21 -0
- package/dist/index.js.map +1 -0
- package/{src → dist}/lib/constants.d.ts +0 -1
- package/{src → dist}/lib/constants.js +1 -0
- package/dist/lib/constants.js.map +1 -0
- package/{src → dist}/lib/file-storage.service.d.ts +0 -1
- package/{src → dist}/lib/file-storage.service.js +3 -3
- package/dist/lib/file-storage.service.js.map +1 -0
- package/{src → dist}/lib/index.d.ts +0 -1
- package/dist/lib/index.js +22 -0
- package/dist/lib/index.js.map +1 -0
- package/{src → dist}/lib/interceptor/file-storage.interceptor.d.ts +0 -4
- package/{src → dist}/lib/interceptor/file-storage.interceptor.js +5 -17
- package/dist/lib/interceptor/file-storage.interceptor.js.map +1 -0
- package/{src → dist}/lib/nest-file-storage.module.d.ts +0 -1
- package/{src → dist}/lib/nest-file-storage.module.js +9 -3
- package/dist/lib/nest-file-storage.module.js.map +1 -0
- package/{src → dist}/lib/storage/azure.storage.d.ts +3 -4
- package/{src → dist}/lib/storage/azure.storage.js +97 -46
- package/dist/lib/storage/azure.storage.js.map +1 -0
- package/{src → dist}/lib/storage/local.storage.d.ts +2 -17
- package/{src → dist}/lib/storage/local.storage.js +81 -58
- package/dist/lib/storage/local.storage.js.map +1 -0
- package/{src → dist}/lib/storage/s3.storage.d.ts +3 -4
- package/{src → dist}/lib/storage/s3.storage.js +76 -32
- package/dist/lib/storage/s3.storage.js.map +1 -0
- package/{src → dist}/lib/storage.factory.d.ts +0 -1
- package/dist/lib/storage.factory.js +46 -0
- package/dist/lib/storage.factory.js.map +1 -0
- package/{src → dist}/lib/types.d.ts +1 -15
- package/{src → dist}/lib/types.js +1 -0
- package/dist/lib/types.js.map +1 -0
- package/dist/tsconfig.build.tsbuildinfo +1 -0
- package/examples/1-basic-local-storage.example.ts +22 -0
- package/examples/10-testing.example.ts +233 -0
- package/examples/2-s3-storage.example.ts +40 -0
- package/examples/3-azure-storage.example.ts +35 -0
- package/examples/4-upload-controller.example.ts +117 -0
- package/examples/5-custom-configuration.example.ts +75 -0
- package/examples/6-file-service.example.ts +124 -0
- package/examples/7-user-avatar.example.ts +139 -0
- package/examples/8-document-management.example.ts +265 -0
- package/examples/9-dynamic-storage.example.ts +175 -0
- package/examples/README.md +122 -0
- package/package.json +84 -5
- package/src/index.d.ts.map +0 -1
- package/src/index.js +0 -7
- package/src/lib/constants.d.ts.map +0 -1
- package/src/lib/file-storage.service.d.ts.map +0 -1
- package/src/lib/index.d.ts.map +0 -1
- package/src/lib/index.js +0 -8
- package/src/lib/interceptor/file-storage.interceptor.d.ts.map +0 -1
- package/src/lib/nest-file-storage.module.d.ts.map +0 -1
- package/src/lib/storage/azure.storage.d.ts.map +0 -1
- package/src/lib/storage/local.storage.d.ts.map +0 -1
- package/src/lib/storage/s3.storage.d.ts.map +0 -1
- package/src/lib/storage.factory.d.ts.map +0 -1
- package/src/lib/storage.factory.js +0 -81
- package/src/lib/types.d.ts.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,iEAA+C;AAC/C,6DAA2C;AAC3C,6EAA2D;AAC3D,8CAA4B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/lib/constants.ts"],"names":[],"mappings":";;;AAAa,QAAA,oBAAoB,GAAG,oBAAoB,CAAC"}
|
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.FileStorageService = void 0;
|
|
4
4
|
const storage_factory_1 = require("./storage.factory");
|
|
5
5
|
class FileStorageService {
|
|
6
|
+
static options;
|
|
6
7
|
static setOptions(options) {
|
|
7
8
|
FileStorageService.options = options;
|
|
8
9
|
}
|
|
@@ -11,19 +12,18 @@ class FileStorageService {
|
|
|
11
12
|
}
|
|
12
13
|
static async getStorage(storageType) {
|
|
13
14
|
const options = this.getOptions();
|
|
14
|
-
// Check if it's a class factory approach
|
|
15
15
|
if ('storageFactory' in options) {
|
|
16
16
|
const classOptions = options;
|
|
17
17
|
const StorageClass = await classOptions.storageFactory();
|
|
18
18
|
return new StorageClass(classOptions.options);
|
|
19
19
|
}
|
|
20
|
-
// Configuration-based approach
|
|
21
20
|
const configOptions = options;
|
|
22
21
|
if (!storageType) {
|
|
23
22
|
storageType = configOptions.storage;
|
|
24
23
|
}
|
|
25
|
-
const config = configOptions[
|
|
24
|
+
const config = configOptions[`${storageType}Config`];
|
|
26
25
|
return await storage_factory_1.StorageFactory.createStorage(storageType, config);
|
|
27
26
|
}
|
|
28
27
|
}
|
|
29
28
|
exports.FileStorageService = FileStorageService;
|
|
29
|
+
//# sourceMappingURL=file-storage.service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"file-storage.service.js","sourceRoot":"","sources":["../../src/lib/file-storage.service.ts"],"names":[],"mappings":";;;AAAA,uDAAmD;AAInD,MAAa,kBAAkB;IAEnB,MAAM,CAAC,OAAO,CAA2B;IAEjD,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,CAAC,KAAK,CAAC,UAAU,CAAC,WAA6B;QACjD,MAAM,OAAO,GAAG,IAAI,CAAC,UAAU,EAAE,CAAC;QAGlC,IAAI,gBAAgB,IAAI,OAAO,EAAE,CAAC;YAC9B,MAAM,YAAY,GAAG,OAAkC,CAAC;YACxD,MAAM,YAAY,GAAG,MAAM,YAAY,CAAC,cAAc,EAAE,CAAC;YACzD,OAAO,IAAI,YAAY,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC;QAClD,CAAC;QAGD,MAAM,aAAa,GAAG,OAAmC,CAAC;QAC1D,IAAI,CAAC,WAAW,EAAE,CAAC;YACf,WAAW,GAAG,aAAa,CAAC,OAAO,CAAC;QACxC,CAAC;QACD,MAAM,MAAM,GAAI,aAAqB,CAAC,GAAG,WAAW,QAAQ,CAAC,CAAC;QAC9D,OAAO,MAAM,gCAAc,CAAC,aAAa,CAAC,WAAW,EAAE,MAAM,CAAC,CAAC;IACnE,CAAC;CAEJ;AA/BD,gDA+BC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./nest-file-storage.module"), exports);
|
|
18
|
+
__exportStar(require("./types"), exports);
|
|
19
|
+
__exportStar(require("./storage.factory"), exports);
|
|
20
|
+
__exportStar(require("./interceptor/file-storage.interceptor"), exports);
|
|
21
|
+
__exportStar(require("./file-storage.service"), exports);
|
|
22
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/lib/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,6DAA2C;AAC3C,0CAAwB;AACxB,oDAAkC;AAClC,yEAAuD;AACvD,yDAAuC"}
|
|
@@ -18,8 +18,4 @@ export type FileStorageInterceptorOptions = {
|
|
|
18
18
|
storageOptions?: StorageOptions;
|
|
19
19
|
mapToRequestBody?: (file: any, fieldName: string, req?: Request) => any;
|
|
20
20
|
};
|
|
21
|
-
/**
|
|
22
|
-
* Function-based interceptor that accepts storage options dynamically.
|
|
23
|
-
*/
|
|
24
21
|
export declare function FileStorageInterceptor(fileConfig: FileUploadConfig | string, interceptorOptions?: FileStorageInterceptorOptions): NestInterceptor;
|
|
25
|
-
//# sourceMappingURL=file-storage.interceptor.d.ts.map
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
6
|
exports.FileStorageInterceptor = FileStorageInterceptor;
|
|
4
|
-
const
|
|
5
|
-
const multer_1 = tslib_1.__importDefault(require("multer"));
|
|
7
|
+
const multer_1 = __importDefault(require("multer"));
|
|
6
8
|
const file_storage_service_1 = require("../file-storage.service");
|
|
7
9
|
const storage_factory_1 = require("../storage.factory");
|
|
8
10
|
const types_1 = require("../types");
|
|
9
|
-
// Helper function to map file object
|
|
10
11
|
function mapFileObject(file) {
|
|
11
12
|
return {
|
|
12
13
|
fieldName: file.fieldname,
|
|
@@ -21,15 +22,11 @@ function mapFileObject(file) {
|
|
|
21
22
|
fullPath: file.fullPath
|
|
22
23
|
};
|
|
23
24
|
}
|
|
24
|
-
// Helper function to apply file mapping with callback
|
|
25
25
|
function applyFileKeyMapping(request, fileConfig, interceptorOptions) {
|
|
26
|
-
// Default callback returns the file key
|
|
27
26
|
const mapCallback = interceptorOptions?.mapToRequestBody || ((file) => {
|
|
28
|
-
// For arrays, return array of keys
|
|
29
27
|
if (Array.isArray(file)) {
|
|
30
28
|
return file.map(f => f.key);
|
|
31
29
|
}
|
|
32
|
-
// For single file, return the key
|
|
33
30
|
return file.key;
|
|
34
31
|
});
|
|
35
32
|
if (fileConfig.type === 'single') {
|
|
@@ -58,9 +55,6 @@ function applyFileKeyMapping(request, fileConfig, interceptorOptions) {
|
|
|
58
55
|
}
|
|
59
56
|
}
|
|
60
57
|
}
|
|
61
|
-
/**
|
|
62
|
-
* Function-based interceptor that accepts storage options dynamically.
|
|
63
|
-
*/
|
|
64
58
|
function FileStorageInterceptor(fileConfig, interceptorOptions) {
|
|
65
59
|
if (typeof fileConfig === 'string') {
|
|
66
60
|
fileConfig = {
|
|
@@ -73,17 +67,14 @@ function FileStorageInterceptor(fileConfig, interceptorOptions) {
|
|
|
73
67
|
const options = file_storage_service_1.FileStorageService.getOptions();
|
|
74
68
|
const request = context.switchToHttp().getRequest();
|
|
75
69
|
const response = context.switchToHttp().getResponse();
|
|
76
|
-
// Determine storage type - handle both config approaches
|
|
77
70
|
let storageType;
|
|
78
71
|
let storageConfig;
|
|
79
72
|
if ('storage' in options) {
|
|
80
|
-
// Configuration-based approach
|
|
81
73
|
const configOptions = options;
|
|
82
74
|
storageType = interceptorOptions?.storageType ?? configOptions.storage;
|
|
83
75
|
storageConfig = configOptions[`${storageType}Config`];
|
|
84
76
|
}
|
|
85
77
|
else {
|
|
86
|
-
// Class factory approach - default to LOCAL
|
|
87
78
|
storageType = interceptorOptions?.storageType ?? types_1.FileStorageEnum.LOCAL;
|
|
88
79
|
storageConfig = {};
|
|
89
80
|
}
|
|
@@ -99,10 +90,8 @@ function FileStorageInterceptor(fileConfig, interceptorOptions) {
|
|
|
99
90
|
},
|
|
100
91
|
prefix: interceptorOptions?.prefix || storageConfig?.prefix,
|
|
101
92
|
};
|
|
102
|
-
// Create storage instance dynamically
|
|
103
93
|
const storage = await storage_factory_1.StorageFactory.createStorage(storageType, storageOptions);
|
|
104
94
|
const multerInstance = (0, multer_1.default)({ storage });
|
|
105
|
-
// Multer setup based on fileConfig
|
|
106
95
|
let multerMiddleware;
|
|
107
96
|
switch (fileConfig.type) {
|
|
108
97
|
case 'single':
|
|
@@ -126,13 +115,12 @@ function FileStorageInterceptor(fileConfig, interceptorOptions) {
|
|
|
126
115
|
default:
|
|
127
116
|
throw new Error('Invalid file upload type. Use "single", "array", or "fields".');
|
|
128
117
|
}
|
|
129
|
-
// Execute Multer middleware
|
|
130
118
|
await new Promise((resolve, reject) => {
|
|
131
119
|
multerMiddleware(request, response, (err) => (err ? reject(err) : resolve(true)));
|
|
132
120
|
});
|
|
133
|
-
// Apply file key mapping after multer processing
|
|
134
121
|
applyFileKeyMapping(request, fileConfig, interceptorOptions);
|
|
135
122
|
return next.handle();
|
|
136
123
|
}
|
|
137
124
|
};
|
|
138
125
|
}
|
|
126
|
+
//# sourceMappingURL=file-storage.interceptor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"file-storage.interceptor.js","sourceRoot":"","sources":["../../../src/lib/interceptor/file-storage.interceptor.ts"],"names":[],"mappings":";;;;;AAuFA,wDAqFC;AA1KD,oDAA4B;AAE5B,kEAA6D;AAC7D,wDAAoD;AACpD,oCAAmG;AAsBnG,SAAS,aAAa,CAAC,IAAS;IAC5B,OAAO;QACH,SAAS,EAAE,IAAI,CAAC,SAAS;QACzB,YAAY,EAAE,IAAI,CAAC,YAAY;QAC/B,QAAQ,EAAE,IAAI,CAAC,QAAQ;QACvB,QAAQ,EAAE,IAAI,CAAC,QAAQ;QACvB,IAAI,EAAE,IAAI,CAAC,IAAI;QACf,GAAG,EAAG,IAAY,CAAC,GAAG;QACtB,IAAI,EAAG,IAAY,CAAC,IAAI;QACxB,GAAG,EAAG,IAAY,CAAC,GAAG;QACtB,QAAQ,EAAE,IAAI,CAAC,QAAQ;QACvB,QAA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iDAAiD,CAAC,CAAC;oBACvE,CAAC;oBACD,gBAAgB,GAAG,cAAc,CAAC,KAAK,CAAC,UAAU,CAAC,SAAS,EAAE,UAAU,CAAC,QAAQ,CAAC,CAAC;oBACnF,MAAM;gBACV,KAAK,QAAQ;oBACT,IAAI,CAAC,UAAU,CAAC,MAAM,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,UAAU,CAAC,MAAM,CAAC,EAAE,CAAC;wBAC1D,MAAM,IAAI,KAAK,CAAC,2DAA2D,CAAC,CAAC;oBACjF,CAAC;oBACD,gBAAgB,GAAG,cAAc,CAAC,MAAM,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC;oBAC5D,MAAM;gBACV;oBACI,MAAM,IAAI,KAAK,CAAC,+DAA+D,CAAC,CAAC;YACzF,CAAC;YAGD,MAAM,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;gBAClC,gBAAgB,CAAC,OAAO,EAAE,QAAQ,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;YACtF,CAAC,CAAC,CAAC;YAGH,mBAAmB,CAAC,OAAO,EAAE,UAAU,EAAE,kBAAkB,CAAC,CAAC;YAE7D,OAAO,IAAI,CAAC,MAAM,EAAE,CAAC;QACzB,CAAC;KACJ,CAAC;AACN,CAAC"}
|
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
2
8
|
var NestFileStorageModule_1;
|
|
3
9
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
10
|
exports.NestFileStorageModule = void 0;
|
|
5
|
-
const tslib_1 = require("tslib");
|
|
6
11
|
const common_1 = require("@nestjs/common");
|
|
7
12
|
const constants_1 = require("./constants");
|
|
8
13
|
const file_storage_service_1 = require("./file-storage.service");
|
|
@@ -14,7 +19,7 @@ let NestFileStorageModule = NestFileStorageModule_1 = class NestFileStorageModul
|
|
|
14
19
|
{
|
|
15
20
|
provide: constants_1.FILE_STORAGE_OPTIONS,
|
|
16
21
|
useFactory: async () => {
|
|
17
|
-
file_storage_service_1.FileStorageService.setOptions(options);
|
|
22
|
+
file_storage_service_1.FileStorageService.setOptions(options);
|
|
18
23
|
return options;
|
|
19
24
|
},
|
|
20
25
|
inject: [],
|
|
@@ -69,6 +74,7 @@ let NestFileStorageModule = NestFileStorageModule_1 = class NestFileStorageModul
|
|
|
69
74
|
}
|
|
70
75
|
};
|
|
71
76
|
exports.NestFileStorageModule = NestFileStorageModule;
|
|
72
|
-
exports.NestFileStorageModule = NestFileStorageModule = NestFileStorageModule_1 =
|
|
77
|
+
exports.NestFileStorageModule = NestFileStorageModule = NestFileStorageModule_1 = __decorate([
|
|
73
78
|
(0, common_1.Module)({})
|
|
74
79
|
], NestFileStorageModule);
|
|
80
|
+
//# sourceMappingURL=nest-file-storage.module.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nest-file-storage.module.js","sourceRoot":"","sources":["../../src/lib/nest-file-storage.module.ts"],"names":[],"mappings":";;;;;;;;;;AAAA,2CAAiE;AAEjE,2CAAmD;AACnD,iEAA4D;AAKrD,IAAM,qBAAqB,6BAA3B,MAAM,qBAAqB;IAE9B,MAAM,CAAC,OAAO,CAAC,OAAiC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yCAAkB,CAAC,UAAU,CAAC,kBAAkB,CAAC,CAAC;oBAClD,OAAO,kBAAkB,CAAC;gBAC9B,CAAC;gBACD,MAAM,EAAE,OAAO,CAAC,MAAM,IAAI,EAAE;aAC/B,CAAC;QACN,CAAC;QAED,OAAO;YACH,OAAO,EAAE,gCAAoB;YAC7B,UAAU,EAAE,KAAK,EAAE,cAAyC,EAAE,EAAE;gBAC5D,MAAM,kBAAkB,GAAG,MAAM,cAAc,CAAC,wBAAwB,EAAE,CAAC;gBAC3E,yCAAkB,CAAC,UAAU,CAAC,kBAAkB,CAAC,CAAC;gBAClD,OAAO,kBAAkB,CAAC;YAC9B,CAAC;YACD,MAAM,EAAE,CAAC,OAAO,CAAC,WAAW,IAAI,OAAO,CAAC,QAAS,CAAC;SACrD,CAAC;IACN,CAAC;CAEJ,CAAA;AArEY,sDAAqB;gCAArB,qBAAqB;IADjC,IAAA,eAAM,EAAC,EAAE,CAAC;GACE,qBAAqB,CAqEjC"}
|
|
@@ -7,13 +7,12 @@ export declare class AzureStorage implements StorageEngine, Storage {
|
|
|
7
7
|
private fileNameFunction;
|
|
8
8
|
private fileDistFunction;
|
|
9
9
|
constructor(options: AzureStorageOptions);
|
|
10
|
-
_handleFile(req: any, file: any, cb: (error?: any, info?: any) => void):
|
|
11
|
-
_removeFile(_req: any, file: any, cb: (error: Error | null) => void):
|
|
10
|
+
_handleFile(req: any, file: any, cb: (error?: any, info?: any) => void): void;
|
|
11
|
+
_removeFile(_req: any, file: any, cb: (error: Error | null) => void): void;
|
|
12
12
|
getUrl(key: string): string;
|
|
13
13
|
getSignedUrl(key: string, signatureValues?: Partial<Omit<BlobSASSignatureValues, 'containerName'>>): string;
|
|
14
14
|
getFile(key: string): Promise<Buffer>;
|
|
15
|
-
putFile(buffer: Buffer, key: string): Promise<UploadedFile>;
|
|
15
|
+
putFile(buffer: Buffer, key: string, options?: any): Promise<UploadedFile>;
|
|
16
16
|
deleteFile(key: string): Promise<void>;
|
|
17
17
|
copyFile(oldKey: string, newKey: string): Promise<UploadedFile>;
|
|
18
18
|
}
|
|
19
|
-
//# sourceMappingURL=azure.storage.d.ts.map
|
|
@@ -1,13 +1,52 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
+
};
|
|
2
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
39
|
exports.AzureStorage = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
40
|
const storage_blob_1 = require("@azure/storage-blob");
|
|
6
|
-
const concat_stream_1 =
|
|
7
|
-
const moment_1 =
|
|
8
|
-
const path_1 =
|
|
41
|
+
const concat_stream_1 = __importDefault(require("concat-stream"));
|
|
42
|
+
const moment_1 = __importDefault(require("moment"));
|
|
43
|
+
const path_1 = __importStar(require("path"));
|
|
9
44
|
const uuid_1 = require("uuid");
|
|
10
45
|
class AzureStorage {
|
|
46
|
+
options;
|
|
47
|
+
blobServiceClient;
|
|
48
|
+
fileNameFunction;
|
|
49
|
+
fileDistFunction;
|
|
11
50
|
constructor(options) {
|
|
12
51
|
this.options = options;
|
|
13
52
|
this.fileNameFunction = options.fileName || ((file, _req) => {
|
|
@@ -19,42 +58,53 @@ class AzureStorage {
|
|
|
19
58
|
const sharedKeyCredential = new storage_blob_1.StorageSharedKeyCredential(options.account, options.accountKey);
|
|
20
59
|
this.blobServiceClient = new storage_blob_1.BlobServiceClient(`https://${options.account}.blob.core.windows.net`, sharedKeyCredential);
|
|
21
60
|
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
61
|
+
_handleFile(req, file, cb) {
|
|
62
|
+
void (async () => {
|
|
63
|
+
try {
|
|
64
|
+
const dist = await this.fileDistFunction(file, req);
|
|
65
|
+
const key = await this.fileNameFunction(file, req);
|
|
66
|
+
const filePath = (0, path_1.join)(dist, key);
|
|
67
|
+
file.stream.pipe((0, concat_stream_1.default)({ encoding: 'buffer' }, (buffer) => {
|
|
68
|
+
void (async () => {
|
|
69
|
+
try {
|
|
70
|
+
const uploadedFile = await this.putFile(buffer, filePath);
|
|
71
|
+
const fileInfo = {
|
|
72
|
+
...uploadedFile,
|
|
73
|
+
fieldName: file.fieldname,
|
|
74
|
+
originalName: file.originalname,
|
|
75
|
+
mimetype: file.mimetype,
|
|
76
|
+
};
|
|
77
|
+
let transformData = fileInfo;
|
|
78
|
+
if (this.options?.transformUploadedFileObject) {
|
|
79
|
+
transformData = await this.options.transformUploadedFileObject(fileInfo);
|
|
80
|
+
}
|
|
81
|
+
cb(null, transformData);
|
|
82
|
+
}
|
|
83
|
+
catch (error) {
|
|
84
|
+
cb(error);
|
|
85
|
+
}
|
|
86
|
+
})();
|
|
87
|
+
}));
|
|
88
|
+
file.stream.on('error', (err) => cb(err));
|
|
89
|
+
}
|
|
90
|
+
catch (error) {
|
|
91
|
+
cb(error);
|
|
92
|
+
}
|
|
93
|
+
})();
|
|
46
94
|
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
95
|
+
_removeFile(_req, file, cb) {
|
|
96
|
+
void (async () => {
|
|
97
|
+
try {
|
|
98
|
+
const blobClient = this.blobServiceClient
|
|
99
|
+
.getContainerClient(this.options.container)
|
|
100
|
+
.getBlobClient(file.key);
|
|
101
|
+
await blobClient.delete();
|
|
102
|
+
cb(null);
|
|
103
|
+
}
|
|
104
|
+
catch (error) {
|
|
105
|
+
cb(error);
|
|
106
|
+
}
|
|
107
|
+
})();
|
|
58
108
|
}
|
|
59
109
|
getUrl(key) {
|
|
60
110
|
return `https://${this.options.account}.blob.core.windows.net/${this.options.container}/${key}`;
|
|
@@ -69,16 +119,15 @@ class AzureStorage {
|
|
|
69
119
|
const containerClient = this.blobServiceClient.getContainerClient(this.options.container);
|
|
70
120
|
const blobClient = containerClient.getBlobClient(key);
|
|
71
121
|
const sharedKeyCredential = new storage_blob_1.StorageSharedKeyCredential(this.options.account, this.options.accountKey);
|
|
72
|
-
// Set the SAS token options
|
|
73
122
|
const expiresOn = new Date();
|
|
74
|
-
expiresOn.setHours(expiresOn.getHours() + 1);
|
|
123
|
+
expiresOn.setHours(expiresOn.getHours() + 1);
|
|
75
124
|
const sasToken = (0, storage_blob_1.generateBlobSASQueryParameters)({
|
|
76
125
|
containerName: this.options.container,
|
|
77
126
|
blobName: key,
|
|
78
|
-
permissions: storage_blob_1.BlobSASPermissions.parse('r'),
|
|
79
|
-
protocol: storage_blob_1.SASProtocol.Https,
|
|
80
|
-
startsOn: new Date(),
|
|
81
|
-
expiresOn,
|
|
127
|
+
permissions: storage_blob_1.BlobSASPermissions.parse('r'),
|
|
128
|
+
protocol: storage_blob_1.SASProtocol.Https,
|
|
129
|
+
startsOn: new Date(),
|
|
130
|
+
expiresOn,
|
|
82
131
|
...signatureValues,
|
|
83
132
|
}, sharedKeyCredential).toString();
|
|
84
133
|
return `${blobClient.url}?${sasToken}`;
|
|
@@ -95,7 +144,7 @@ class AzureStorage {
|
|
|
95
144
|
stream?.on('error', reject);
|
|
96
145
|
});
|
|
97
146
|
}
|
|
98
|
-
async putFile(buffer, key) {
|
|
147
|
+
async putFile(buffer, key, options) {
|
|
99
148
|
try {
|
|
100
149
|
const containerClient = this.blobServiceClient.getContainerClient(this.options.container);
|
|
101
150
|
const blockBlobClient = containerClient.getBlockBlobClient(key);
|
|
@@ -108,6 +157,7 @@ class AzureStorage {
|
|
|
108
157
|
key,
|
|
109
158
|
fullPath: key,
|
|
110
159
|
url: this.getUrl(key),
|
|
160
|
+
...options,
|
|
111
161
|
};
|
|
112
162
|
return fileInfo;
|
|
113
163
|
}
|
|
@@ -151,3 +201,4 @@ class AzureStorage {
|
|
|
151
201
|
}
|
|
152
202
|
}
|
|
153
203
|
exports.AzureStorage = AzureStorage;
|
|
204
|
+
//# sourceMappingURL=azure.storage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"azure.storage.js","sourceRoot":"","sources":["../../../src/lib/storage/azure.storage.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,sDAO6B;AAC7B,kEAAmC;AACnC,oDAA4B;AAE5B,6CAA4C;AAC5C,+BAAoC;AAKpC,MAAa,YAAY;IAQD;IANZ,iBAAiB,CAAoB;IAErC,gBAAgB,CAAqE;IACrF,gBAAgB,CAAqE;IAG7F,YAAoB,OAA4B;QAA5B,YAAO,GAAP,OAAO,CAAqB;QAC5C,IAAI,CAAC,gBAAgB,GAAG,OAAO,CAAC,QAAQ,IAAI,CAAC,CAAC,IAAI,EAAE,IAAI,EAAE,EAAE;YACxD,OAAO,GAAG,IAAA,SAAM,GAAE,IAAI,IAAI,CAAC,YAAY,EAAE,CAAC;QAC9C,CAAC,CAAC,CAAC;QAEH,IAAI,CAAC,gBAAgB,GAAG,OAAO,CAAC,QAAQ,IAAI,CAAC,CAAC,KAAK,EAAE,IAAI,EAAE,EAAE;YACzD,OAAO,cAAI,CAAC,IAAI,CAAC,SAAS,EAAE,IAAA,gBAAM,GAAE,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,IAAA,gBAAM,GAAE,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,IAAA,gBAAM,GAAE,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC;QACvG,CAAC,CAAC,CAAC;QAEH,MAAM,mBAAmB,GAAG,IAAI,yCAA0B,CACtD,OAAO,CAAC,OAAO,EACf,OAAO,CAAC,UAAU,CACrB,CAAC;QAEF,IAAI,CAAC,iBAAiB,GAAG,IAAI,gCAAiB,CAC1C,WAAW,OAAO,CAAC,OAAO,wBAAwB,EAClD,mBAAmB,CACtB,CAAC;IACN,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private fileNameFunction;
|
|
7
7
|
private fileDistFunction;
|
|
8
|
-
/**
|
|
9
|
-
* Convert OS-specific file path to URL-friendly key
|
|
10
|
-
* This ensures keys are consistent across all platforms
|
|
11
|
-
* Windows: C:\uploads\2024\01\file.jpg -> 2024/01/file.jpg
|
|
12
|
-
* Unix: /uploads/2024/01/file.jpg -> 2024/01/file.jpg
|
|
13
|
-
*/
|
|
14
8
|
private pathToUrl;
|
|
15
|
-
/**
|
|
16
|
-
* Convert URL-friendly key to OS-specific file path
|
|
17
|
-
* This converts stored keys back to valid file system paths
|
|
18
|
-
* 2024/01/file.jpg -> Windows: 2024\01\file.jpg, Unix: 2024/01/file.jpg
|
|
19
|
-
*/
|
|
20
9
|
private urlToPath;
|
|
21
|
-
/**
|
|
22
|
-
* Get full file system path from URL-friendly key
|
|
23
|
-
*/
|
|
24
10
|
private getFullPath;
|
|
25
11
|
constructor(options: LocalStorageOptions);
|
|
26
|
-
_handleFile(req: any, file: Express.Multer.File, cb: (error?: any, info?: any) => void):
|
|
12
|
+
_handleFile(req: any, file: Express.Multer.File, cb: (error?: any, info?: any) => void): void;
|
|
27
13
|
_removeFile(_req: any, file: any, cb: (error: Error | null) => void): void;
|
|
28
14
|
getUrl(urlKey: string): string;
|
|
29
15
|
getFile(urlKey: string): Promise<Buffer>;
|
|
30
16
|
deleteFile(urlKey: string): Promise<void>;
|
|
31
|
-
putFile(fileContent: Buffer, urlKey: string): Promise<UploadedFile>;
|
|
17
|
+
putFile(fileContent: Buffer, urlKey: string, options?: any): Promise<UploadedFile>;
|
|
32
18
|
path(urlKey: string): string;
|
|
33
19
|
copyFile(oldUrlKey: string, newUrlKey: string): Promise<UploadedFile>;
|
|
34
20
|
}
|
|
35
|
-
//# sourceMappingURL=local.storage.d.ts.map
|