@ackplus/nest-file-storage 1.1.22 → 2.0.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.
- package/CHANGELOG.md +72 -0
- package/MIGRATION.md +220 -0
- package/README.md +353 -547
- package/dist/index.d.ts +1 -4
- package/dist/index.js +1 -4
- package/dist/index.js.map +1 -1
- package/dist/lib/constants.d.ts +3 -1
- package/dist/lib/constants.js +4 -2
- package/dist/lib/constants.js.map +1 -1
- package/dist/lib/driver-registry.d.ts +34 -0
- package/dist/lib/driver-registry.js +118 -0
- package/dist/lib/driver-registry.js.map +1 -0
- package/dist/lib/drivers/azure.driver.d.ts +21 -0
- package/dist/lib/drivers/azure.driver.js +91 -0
- package/dist/lib/drivers/azure.driver.js.map +1 -0
- package/dist/lib/drivers/driver.interface.d.ts +40 -0
- package/dist/lib/drivers/driver.interface.js +3 -0
- package/dist/lib/drivers/driver.interface.js.map +1 -0
- package/dist/lib/drivers/driver.util.d.ts +2 -0
- package/dist/lib/drivers/driver.util.js +15 -0
- package/dist/lib/drivers/driver.util.js.map +1 -0
- package/dist/lib/drivers/index.d.ts +7 -0
- package/dist/lib/drivers/index.js +39 -0
- package/dist/lib/drivers/index.js.map +1 -0
- package/dist/lib/drivers/local.driver.d.ts +15 -0
- package/dist/lib/drivers/local.driver.js +110 -0
- package/dist/lib/drivers/local.driver.js.map +1 -0
- package/dist/lib/drivers/s3.driver.d.ts +22 -0
- package/dist/lib/drivers/s3.driver.js +103 -0
- package/dist/lib/drivers/s3.driver.js.map +1 -0
- package/dist/lib/file-storage.service.d.ts +16 -5
- package/dist/lib/file-storage.service.js +60 -22
- package/dist/lib/file-storage.service.js.map +1 -1
- package/dist/lib/index.d.ts +9 -2
- package/dist/lib/index.js +15 -2
- package/dist/lib/index.js.map +1 -1
- package/dist/lib/interceptor/file-storage.interceptor.d.ts +7 -10
- package/dist/lib/interceptor/file-storage.interceptor.js +119 -112
- package/dist/lib/interceptor/file-storage.interceptor.js.map +1 -1
- package/dist/lib/multer/driver-multer-engine.d.ts +18 -0
- package/dist/lib/multer/driver-multer-engine.js +91 -0
- package/dist/lib/multer/driver-multer-engine.js.map +1 -0
- package/dist/lib/nest-file-storage.module.d.ts +3 -3
- package/dist/lib/nest-file-storage.module.js +81 -44
- package/dist/lib/nest-file-storage.module.js.map +1 -1
- package/dist/lib/registry-holder.d.ts +6 -0
- package/dist/lib/registry-holder.js +26 -0
- package/dist/lib/registry-holder.js.map +1 -0
- package/dist/lib/tenant/tenant-from.d.ts +14 -0
- package/dist/lib/tenant/tenant-from.js +71 -0
- package/dist/lib/tenant/tenant-from.js.map +1 -0
- package/dist/lib/tenant/tenant.types.d.ts +20 -0
- package/dist/lib/tenant/tenant.types.js +3 -0
- package/dist/lib/tenant/tenant.types.js.map +1 -0
- package/dist/lib/types.d.ts +45 -35
- package/dist/lib/types.js.map +1 -1
- package/dist/lib/validation.d.ts +22 -0
- package/dist/lib/validation.js +98 -0
- package/dist/lib/validation.js.map +1 -0
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/examples/1-basic-local-storage.example.ts +11 -7
- package/examples/10-testing.example.ts +60 -196
- package/examples/11-custom-driver.example.ts +82 -0
- package/examples/12-multi-tenant.example.ts +93 -0
- package/examples/2-s3-storage.example.ts +18 -16
- package/examples/3-azure-storage.example.ts +14 -12
- package/examples/4-upload-controller.example.ts +20 -55
- package/examples/5-custom-configuration.example.ts +37 -57
- package/examples/6-file-service.example.ts +34 -91
- package/examples/7-user-avatar.example.ts +37 -92
- package/examples/8-document-management.example.ts +45 -196
- package/examples/9-dynamic-storage.example.ts +29 -147
- package/examples/README.md +25 -107
- package/package.json +17 -4
- package/dist/lib/storage/azure.storage.d.ts +0 -18
- package/dist/lib/storage/azure.storage.js +0 -210
- package/dist/lib/storage/azure.storage.js.map +0 -1
- package/dist/lib/storage/local.storage.d.ts +0 -20
- package/dist/lib/storage/local.storage.js +0 -212
- package/dist/lib/storage/local.storage.js.map +0 -1
- package/dist/lib/storage/s3.storage.d.ts +0 -19
- package/dist/lib/storage/s3.storage.js +0 -241
- package/dist/lib/storage/s3.storage.js.map +0 -1
- package/dist/lib/storage.factory.d.ts +0 -8
- package/dist/lib/storage.factory.js +0 -46
- package/dist/lib/storage.factory.js.map +0 -1
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ackplus/nest-file-storage",
|
|
3
|
-
"version": "
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
|
+
"description": "One file-storage API for NestJS — Local, S3, Azure, and custom drivers, with per-request/multi-tenant storage, declarative validation, and a unified file model.",
|
|
5
5
|
"author": "AckPlus",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"main": "dist/index.js",
|
|
@@ -9,6 +9,8 @@
|
|
|
9
9
|
"files": [
|
|
10
10
|
"dist",
|
|
11
11
|
"README.md",
|
|
12
|
+
"MIGRATION.md",
|
|
13
|
+
"CHANGELOG.md",
|
|
12
14
|
"examples",
|
|
13
15
|
"LICENSE"
|
|
14
16
|
],
|
|
@@ -24,7 +26,12 @@
|
|
|
24
26
|
"file-management",
|
|
25
27
|
"nestjs-storage",
|
|
26
28
|
"aws-s3",
|
|
27
|
-
"azure-storage"
|
|
29
|
+
"azure-storage",
|
|
30
|
+
"multi-tenant",
|
|
31
|
+
"custom-storage",
|
|
32
|
+
"storage-driver",
|
|
33
|
+
"minio",
|
|
34
|
+
"cloudflare-r2"
|
|
28
35
|
],
|
|
29
36
|
"repository": {
|
|
30
37
|
"type": "git",
|
|
@@ -67,6 +74,7 @@
|
|
|
67
74
|
"@nestjs/platform-express": "^11.0.1",
|
|
68
75
|
"@types/concat-stream": "^2.0.3",
|
|
69
76
|
"@types/express": "^5.0.0",
|
|
77
|
+
"@types/jest": "^30.0.0",
|
|
70
78
|
"@types/multer": "^1.4.12",
|
|
71
79
|
"@types/node": "^22.10.7",
|
|
72
80
|
"@types/uuid": "^10.0.0",
|
|
@@ -74,8 +82,10 @@
|
|
|
74
82
|
"eslint-config-prettier": "^10.0.1",
|
|
75
83
|
"eslint-plugin-prettier": "^5.2.2",
|
|
76
84
|
"globals": "^16.0.0",
|
|
85
|
+
"jest": "^30.0.0",
|
|
77
86
|
"multer": "^1.4.5-lts.1",
|
|
78
87
|
"prettier": "^3.4.2",
|
|
88
|
+
"ts-jest": "^29.2.5",
|
|
79
89
|
"typescript": "^5.7.3",
|
|
80
90
|
"typescript-eslint": "^8.20.0"
|
|
81
91
|
},
|
|
@@ -83,6 +93,9 @@
|
|
|
83
93
|
"clean": "rm -rf dist tsconfig.build.tsbuildinfo",
|
|
84
94
|
"build": "pnpm clean && pnpm -C ../.. exec tsc -p packages/nest-file-storage/tsconfig.build.json",
|
|
85
95
|
"format": "prettier --write \"src/**/*.ts\"",
|
|
86
|
-
"lint": "eslint \"src/**/*.ts\" --fix"
|
|
96
|
+
"lint": "eslint \"src/**/*.ts\" --fix",
|
|
97
|
+
"test": "jest",
|
|
98
|
+
"test:watch": "jest --watch",
|
|
99
|
+
"test:cov": "jest --coverage"
|
|
87
100
|
}
|
|
88
101
|
}
|
|
@@ -1,18 +0,0 @@
|
|
|
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): void;
|
|
11
|
-
_removeFile(_req: any, file: any, cb: (error: Error | null) => void): 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, options?: any): Promise<UploadedFile>;
|
|
16
|
-
deleteFile(key: string): Promise<void>;
|
|
17
|
-
copyFile(oldKey: string, newKey: string): Promise<UploadedFile>;
|
|
18
|
-
}
|
|
@@ -1,210 +0,0 @@
|
|
|
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
|
-
};
|
|
38
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports.AzureStorage = void 0;
|
|
40
|
-
const storage_blob_1 = require("@azure/storage-blob");
|
|
41
|
-
const concat_stream_1 = __importDefault(require("concat-stream"));
|
|
42
|
-
const path_1 = __importStar(require("path"));
|
|
43
|
-
const uuid_1 = require("uuid");
|
|
44
|
-
function getYYYYMMDD(date = new Date()) {
|
|
45
|
-
const yyyy = String(date.getFullYear());
|
|
46
|
-
const mm = String(date.getMonth() + 1).padStart(2, '0');
|
|
47
|
-
const dd = String(date.getDate()).padStart(2, '0');
|
|
48
|
-
return { yyyy, mm, dd };
|
|
49
|
-
}
|
|
50
|
-
class AzureStorage {
|
|
51
|
-
options;
|
|
52
|
-
blobServiceClient;
|
|
53
|
-
fileNameFunction;
|
|
54
|
-
fileDistFunction;
|
|
55
|
-
constructor(options) {
|
|
56
|
-
this.options = options;
|
|
57
|
-
this.fileNameFunction = options.fileName || ((file, _req) => {
|
|
58
|
-
return `${(0, uuid_1.v4)()}-${file.originalname}`;
|
|
59
|
-
});
|
|
60
|
-
this.fileDistFunction = options.fileDist || ((_file, _req) => {
|
|
61
|
-
const { yyyy, mm, dd } = getYYYYMMDD();
|
|
62
|
-
return path_1.default.join('uploads', yyyy, mm, dd);
|
|
63
|
-
});
|
|
64
|
-
const sharedKeyCredential = new storage_blob_1.StorageSharedKeyCredential(options.account, options.accountKey);
|
|
65
|
-
this.blobServiceClient = new storage_blob_1.BlobServiceClient(`https://${options.account}.blob.core.windows.net`, sharedKeyCredential);
|
|
66
|
-
}
|
|
67
|
-
_handleFile(req, file, cb) {
|
|
68
|
-
void (async () => {
|
|
69
|
-
try {
|
|
70
|
-
const dist = await this.fileDistFunction(file, req);
|
|
71
|
-
const key = await this.fileNameFunction(file, req);
|
|
72
|
-
const filePath = (0, path_1.join)(dist, key);
|
|
73
|
-
file.stream.pipe((0, concat_stream_1.default)({ encoding: 'buffer' }, (buffer) => {
|
|
74
|
-
void (async () => {
|
|
75
|
-
try {
|
|
76
|
-
const uploadedFile = await this.putFile(buffer, filePath);
|
|
77
|
-
const fileInfo = {
|
|
78
|
-
...uploadedFile,
|
|
79
|
-
fieldName: file.fieldname,
|
|
80
|
-
originalName: file.originalname,
|
|
81
|
-
mimetype: file.mimetype,
|
|
82
|
-
};
|
|
83
|
-
let transformData = fileInfo;
|
|
84
|
-
if (this.options?.transformUploadedFileObject) {
|
|
85
|
-
transformData = await this.options.transformUploadedFileObject(fileInfo);
|
|
86
|
-
}
|
|
87
|
-
cb(null, transformData);
|
|
88
|
-
}
|
|
89
|
-
catch (error) {
|
|
90
|
-
cb(error);
|
|
91
|
-
}
|
|
92
|
-
})();
|
|
93
|
-
}));
|
|
94
|
-
file.stream.on('error', (err) => cb(err));
|
|
95
|
-
}
|
|
96
|
-
catch (error) {
|
|
97
|
-
cb(error);
|
|
98
|
-
}
|
|
99
|
-
})();
|
|
100
|
-
}
|
|
101
|
-
_removeFile(_req, file, cb) {
|
|
102
|
-
void (async () => {
|
|
103
|
-
try {
|
|
104
|
-
const blobClient = this.blobServiceClient
|
|
105
|
-
.getContainerClient(this.options.container)
|
|
106
|
-
.getBlobClient(file.key);
|
|
107
|
-
await blobClient.delete();
|
|
108
|
-
cb(null);
|
|
109
|
-
}
|
|
110
|
-
catch (error) {
|
|
111
|
-
cb(error);
|
|
112
|
-
}
|
|
113
|
-
})();
|
|
114
|
-
}
|
|
115
|
-
getUrl(key) {
|
|
116
|
-
return `https://${this.options.account}.blob.core.windows.net/${this.options.container}/${key}`;
|
|
117
|
-
}
|
|
118
|
-
getSignedUrl(key, signatureValues = {}) {
|
|
119
|
-
if (!key)
|
|
120
|
-
return '';
|
|
121
|
-
const cloudFrontDomain = process.env['AZURE_CDN_DOMAIN_NAME'];
|
|
122
|
-
if (cloudFrontDomain) {
|
|
123
|
-
return `${cloudFrontDomain}/${key}`;
|
|
124
|
-
}
|
|
125
|
-
const containerClient = this.blobServiceClient.getContainerClient(this.options.container);
|
|
126
|
-
const blobClient = containerClient.getBlobClient(key);
|
|
127
|
-
const sharedKeyCredential = new storage_blob_1.StorageSharedKeyCredential(this.options.account, this.options.accountKey);
|
|
128
|
-
const expiresOn = new Date();
|
|
129
|
-
expiresOn.setHours(expiresOn.getHours() + 1);
|
|
130
|
-
const sasToken = (0, storage_blob_1.generateBlobSASQueryParameters)({
|
|
131
|
-
containerName: this.options.container,
|
|
132
|
-
blobName: key,
|
|
133
|
-
permissions: storage_blob_1.BlobSASPermissions.parse('r'),
|
|
134
|
-
protocol: storage_blob_1.SASProtocol.Https,
|
|
135
|
-
startsOn: new Date(),
|
|
136
|
-
expiresOn,
|
|
137
|
-
...signatureValues,
|
|
138
|
-
}, sharedKeyCredential).toString();
|
|
139
|
-
return `${blobClient.url}?${sasToken}`;
|
|
140
|
-
}
|
|
141
|
-
async getFile(key) {
|
|
142
|
-
const containerClient = this.blobServiceClient.getContainerClient(this.options.container);
|
|
143
|
-
const blobClient = containerClient.getBlobClient(key);
|
|
144
|
-
const downloadResponse = await blobClient.download();
|
|
145
|
-
const stream = downloadResponse.readableStreamBody;
|
|
146
|
-
return new Promise((resolve, reject) => {
|
|
147
|
-
const chunks = [];
|
|
148
|
-
stream?.on('data', (chunk) => chunks.push(chunk));
|
|
149
|
-
stream?.on('end', () => resolve(Buffer.concat(chunks)));
|
|
150
|
-
stream?.on('error', reject);
|
|
151
|
-
});
|
|
152
|
-
}
|
|
153
|
-
async putFile(buffer, key, options) {
|
|
154
|
-
try {
|
|
155
|
-
const containerClient = this.blobServiceClient.getContainerClient(this.options.container);
|
|
156
|
-
const blockBlobClient = containerClient.getBlockBlobClient(key);
|
|
157
|
-
await blockBlobClient.uploadData(buffer);
|
|
158
|
-
const fileInfo = {
|
|
159
|
-
originalName: (0, path_1.basename)(key),
|
|
160
|
-
fileName: (0, path_1.basename)(key),
|
|
161
|
-
size: buffer.length,
|
|
162
|
-
buffer,
|
|
163
|
-
key,
|
|
164
|
-
fullPath: key,
|
|
165
|
-
url: this.getUrl(key),
|
|
166
|
-
...options,
|
|
167
|
-
};
|
|
168
|
-
return fileInfo;
|
|
169
|
-
}
|
|
170
|
-
catch (error) {
|
|
171
|
-
console.error(`Error uploading file "${key}":`, error);
|
|
172
|
-
throw error;
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
async deleteFile(key) {
|
|
176
|
-
try {
|
|
177
|
-
const blobClient = this.blobServiceClient
|
|
178
|
-
.getContainerClient(this.options.container)
|
|
179
|
-
.getBlobClient(key);
|
|
180
|
-
await blobClient.delete();
|
|
181
|
-
}
|
|
182
|
-
catch (error) {
|
|
183
|
-
console.error(`Error deleting blob "${key}":`, error);
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
async copyFile(oldKey, newKey) {
|
|
187
|
-
try {
|
|
188
|
-
const containerClient = this.blobServiceClient.getContainerClient(this.options.container);
|
|
189
|
-
const sourceBlobClient = containerClient.getBlobClient(oldKey);
|
|
190
|
-
const destinationBlobClient = containerClient.getBlobClient(newKey);
|
|
191
|
-
const copyPoller = await destinationBlobClient.beginCopyFromURL(sourceBlobClient.url);
|
|
192
|
-
await copyPoller.pollUntilDone();
|
|
193
|
-
const properties = await destinationBlobClient.getProperties();
|
|
194
|
-
return {
|
|
195
|
-
originalName: (0, path_1.basename)(newKey),
|
|
196
|
-
size: properties.contentLength || 0,
|
|
197
|
-
fileName: (0, path_1.basename)(newKey),
|
|
198
|
-
key: newKey,
|
|
199
|
-
fullPath: newKey,
|
|
200
|
-
url: this.getUrl(newKey),
|
|
201
|
-
};
|
|
202
|
-
}
|
|
203
|
-
catch (error) {
|
|
204
|
-
console.error('Error copying file in Azure Blob Storage:', error);
|
|
205
|
-
throw error;
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
exports.AzureStorage = AzureStorage;
|
|
210
|
-
//# sourceMappingURL=azure.storage.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"azure.storage.js","sourceRoot":"","sources":["../../../src/lib/storage/azure.storage.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,sDAO6B;AAC7B,kEAAmC;AAEnC,6CAA4C;AAC5C,+BAAoC;AAIpC,SAAS,WAAW,CAAC,OAAa,IAAI,IAAI,EAAE;IACxC,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC,CAAC;IACxC,MAAM,EAAE,GAAG,MAAM,CAAC,IAAI,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;IACxD,MAAM,EAAE,GAAG,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;IACnD,OAAO,EAAE,IAAI,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC;AAC5B,CAAC;AAGD,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,MAAM,EAAE,IAAI,EAAE,EAAE,EAAE,E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EAAE,MAAM;gBACX,QAAQ,EAAE,MAAM;gBAChB,GAAG,EAAE,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC;aAC3B,CAAC;QACN,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACb,OAAO,CAAC,KAAK,CAAC,2CAA2C,EAAE,KAAK,CAAC,CAAC;YAClE,MAAM,KAAK,CAAC;QAChB,CAAC;IACL,CAAC;CAGJ;AAhND,oCAgNC"}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { StorageEngine } from 'multer';
|
|
2
|
-
import { LocalStorageOptions, Storage, UploadedFile } from '../types';
|
|
3
|
-
export declare class LocalStorage implements StorageEngine, Storage {
|
|
4
|
-
private options;
|
|
5
|
-
private rootPath;
|
|
6
|
-
private fileNameFunction;
|
|
7
|
-
private fileDistFunction;
|
|
8
|
-
private pathToUrl;
|
|
9
|
-
private urlToPath;
|
|
10
|
-
private getFullPath;
|
|
11
|
-
constructor(options: LocalStorageOptions);
|
|
12
|
-
_handleFile(req: any, file: Express.Multer.File, cb: (error?: any, info?: any) => void): void;
|
|
13
|
-
_removeFile(_req: any, file: any, cb: (error: Error | null) => void): void;
|
|
14
|
-
getUrl(urlKey: string): string;
|
|
15
|
-
getFile(urlKey: string): Promise<Buffer>;
|
|
16
|
-
deleteFile(urlKey: string): Promise<void>;
|
|
17
|
-
putFile(fileContent: Buffer, urlKey: string, options?: any): Promise<UploadedFile>;
|
|
18
|
-
path(urlKey: string): string;
|
|
19
|
-
copyFile(oldUrlKey: string, newUrlKey: string): Promise<UploadedFile>;
|
|
20
|
-
}
|
|
@@ -1,212 +0,0 @@
|
|
|
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
|
-
};
|
|
38
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports.LocalStorage = void 0;
|
|
40
|
-
const concat_stream_1 = __importDefault(require("concat-stream"));
|
|
41
|
-
const fs = __importStar(require("fs"));
|
|
42
|
-
const path_1 = require("path");
|
|
43
|
-
const uuid_1 = require("uuid");
|
|
44
|
-
function getYYYYMMDD(date = new Date()) {
|
|
45
|
-
const yyyy = String(date.getFullYear());
|
|
46
|
-
const mm = String(date.getMonth() + 1).padStart(2, '0');
|
|
47
|
-
const dd = String(date.getDate()).padStart(2, '0');
|
|
48
|
-
return { yyyy, mm, dd };
|
|
49
|
-
}
|
|
50
|
-
class LocalStorage {
|
|
51
|
-
options;
|
|
52
|
-
rootPath;
|
|
53
|
-
fileNameFunction;
|
|
54
|
-
fileDistFunction;
|
|
55
|
-
pathToUrl(filePath) {
|
|
56
|
-
if (!filePath)
|
|
57
|
-
return '';
|
|
58
|
-
let relativePath = filePath;
|
|
59
|
-
if (filePath.startsWith(this.rootPath)) {
|
|
60
|
-
relativePath = filePath.substring(this.rootPath.length);
|
|
61
|
-
}
|
|
62
|
-
return relativePath.replace(/\\/g, '/').replace(/^\/+/, '');
|
|
63
|
-
}
|
|
64
|
-
urlToPath(urlKey) {
|
|
65
|
-
if (!urlKey)
|
|
66
|
-
return '';
|
|
67
|
-
const parts = urlKey.split('/').filter(part => part.length > 0);
|
|
68
|
-
return parts.join(path_1.sep);
|
|
69
|
-
}
|
|
70
|
-
getFullPath(urlKey) {
|
|
71
|
-
const osPath = this.urlToPath(urlKey);
|
|
72
|
-
return (0, path_1.join)(this.rootPath, osPath);
|
|
73
|
-
}
|
|
74
|
-
constructor(options) {
|
|
75
|
-
this.options = options;
|
|
76
|
-
this.rootPath = (0, path_1.normalize)(options.rootPath || (0, path_1.join)(process.cwd(), 'public'));
|
|
77
|
-
this.fileNameFunction = options.fileName || ((file, _req) => {
|
|
78
|
-
return `${(0, uuid_1.v4)()}-${file.originalname}`;
|
|
79
|
-
});
|
|
80
|
-
this.fileDistFunction = options.fileDist || ((_file, _req) => {
|
|
81
|
-
const { yyyy, mm, dd } = getYYYYMMDD();
|
|
82
|
-
return (0, path_1.join)(this.rootPath, yyyy, mm, dd);
|
|
83
|
-
});
|
|
84
|
-
if (!fs.existsSync(this.rootPath)) {
|
|
85
|
-
fs.mkdirSync(this.rootPath, { recursive: true });
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
_handleFile(req, file, cb) {
|
|
89
|
-
const run = async () => {
|
|
90
|
-
try {
|
|
91
|
-
const dist = await this.fileDistFunction(file, req);
|
|
92
|
-
const fileName = await this.fileNameFunction(file, req);
|
|
93
|
-
const filePath = (0, path_1.join)(dist, fileName);
|
|
94
|
-
const urlKey = this.pathToUrl(filePath);
|
|
95
|
-
file.stream.pipe((0, concat_stream_1.default)({ encoding: 'buffer' }, (buffer) => {
|
|
96
|
-
void (async () => {
|
|
97
|
-
try {
|
|
98
|
-
const uploadedFile = await this.putFile(buffer, urlKey);
|
|
99
|
-
const fileInfo = {
|
|
100
|
-
...uploadedFile,
|
|
101
|
-
fieldName: file.fieldname,
|
|
102
|
-
originalName: file.originalname,
|
|
103
|
-
mimetype: file.mimetype,
|
|
104
|
-
};
|
|
105
|
-
let transformData = fileInfo;
|
|
106
|
-
if (this.options?.transformUploadedFileObject) {
|
|
107
|
-
transformData = await this.options.transformUploadedFileObject(fileInfo);
|
|
108
|
-
}
|
|
109
|
-
cb(null, transformData);
|
|
110
|
-
}
|
|
111
|
-
catch (error) {
|
|
112
|
-
cb(error);
|
|
113
|
-
}
|
|
114
|
-
})();
|
|
115
|
-
}));
|
|
116
|
-
}
|
|
117
|
-
catch (error) {
|
|
118
|
-
console.error('error', error);
|
|
119
|
-
cb(error);
|
|
120
|
-
}
|
|
121
|
-
};
|
|
122
|
-
run().catch(cb);
|
|
123
|
-
}
|
|
124
|
-
_removeFile(_req, file, cb) {
|
|
125
|
-
const filePath = file.path;
|
|
126
|
-
fs.unlink(filePath, (err) => {
|
|
127
|
-
if (err) {
|
|
128
|
-
cb(err);
|
|
129
|
-
}
|
|
130
|
-
else {
|
|
131
|
-
cb(null);
|
|
132
|
-
}
|
|
133
|
-
});
|
|
134
|
-
}
|
|
135
|
-
getUrl(urlKey) {
|
|
136
|
-
if (urlKey && urlKey.startsWith('http')) {
|
|
137
|
-
return urlKey;
|
|
138
|
-
}
|
|
139
|
-
if (!urlKey) {
|
|
140
|
-
return '';
|
|
141
|
-
}
|
|
142
|
-
const baseUrl = this.options.baseUrl.replace(/\/$/, '');
|
|
143
|
-
const cleanKey = urlKey.replace(/^\//, '');
|
|
144
|
-
return `${baseUrl}/${cleanKey}`;
|
|
145
|
-
}
|
|
146
|
-
async getFile(urlKey) {
|
|
147
|
-
const fullPath = this.getFullPath(urlKey);
|
|
148
|
-
return fs.promises.readFile(fullPath);
|
|
149
|
-
}
|
|
150
|
-
async deleteFile(urlKey) {
|
|
151
|
-
const fullPath = this.getFullPath(urlKey);
|
|
152
|
-
return fs.promises.unlink(fullPath);
|
|
153
|
-
}
|
|
154
|
-
async putFile(fileContent, urlKey, options) {
|
|
155
|
-
return new Promise((putFileResolve, reject) => {
|
|
156
|
-
const filePath = this.getFullPath(urlKey);
|
|
157
|
-
const directoryPath = (0, path_1.dirname)(filePath);
|
|
158
|
-
fs.mkdirSync(directoryPath, { recursive: true });
|
|
159
|
-
fs.writeFile(filePath, fileContent, (err) => {
|
|
160
|
-
if (err) {
|
|
161
|
-
reject(err);
|
|
162
|
-
return;
|
|
163
|
-
}
|
|
164
|
-
const stats = fs.statSync(filePath);
|
|
165
|
-
const fileName = urlKey.split('/').pop() || urlKey;
|
|
166
|
-
const fileInfo = {
|
|
167
|
-
originalName: fileName,
|
|
168
|
-
size: stats.size,
|
|
169
|
-
fileName: fileName,
|
|
170
|
-
key: urlKey,
|
|
171
|
-
url: this.getUrl(urlKey),
|
|
172
|
-
fullPath: filePath,
|
|
173
|
-
...options,
|
|
174
|
-
};
|
|
175
|
-
putFileResolve(fileInfo);
|
|
176
|
-
});
|
|
177
|
-
});
|
|
178
|
-
}
|
|
179
|
-
path(urlKey) {
|
|
180
|
-
if (!urlKey) {
|
|
181
|
-
return '';
|
|
182
|
-
}
|
|
183
|
-
return this.getFullPath(urlKey);
|
|
184
|
-
}
|
|
185
|
-
async copyFile(oldUrlKey, newUrlKey) {
|
|
186
|
-
return new Promise((resolve, reject) => {
|
|
187
|
-
const oldPath = this.getFullPath(oldUrlKey);
|
|
188
|
-
const newPath = this.getFullPath(newUrlKey);
|
|
189
|
-
const directoryPath = (0, path_1.dirname)(newPath);
|
|
190
|
-
fs.mkdirSync(directoryPath, { recursive: true });
|
|
191
|
-
fs.copyFile(oldPath, newPath, (err) => {
|
|
192
|
-
if (err) {
|
|
193
|
-
reject(err);
|
|
194
|
-
return;
|
|
195
|
-
}
|
|
196
|
-
const stats = fs.statSync(newPath);
|
|
197
|
-
const fileName = newUrlKey.split('/').pop() || newUrlKey;
|
|
198
|
-
const fileInfo = {
|
|
199
|
-
originalName: fileName,
|
|
200
|
-
size: stats.size,
|
|
201
|
-
fileName: fileName,
|
|
202
|
-
key: newUrlKey,
|
|
203
|
-
fullPath: newPath,
|
|
204
|
-
url: this.getUrl(newUrlKey),
|
|
205
|
-
};
|
|
206
|
-
resolve(fileInfo);
|
|
207
|
-
});
|
|
208
|
-
});
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
exports.LocalStorage = LocalStorage;
|
|
212
|
-
//# sourceMappingURL=local.storage.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"local.storage.js","sourceRoot":"","sources":["../../../src/lib/storage/local.storage.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,kEAAmC;AACnC,uCAAyB;AAEzB,+BAAqD;AACrD,+BAAoC;AAIpC,SAAS,WAAW,CAAC,OAAa,IAAI,IAAI,EAAE;IACxC,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC,CAAC;IACxC,MAAM,EAAE,GAAG,MAAM,CAAC,IAAI,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;IACxD,MAAM,EAAE,GAAG,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC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S,EAAE,IAAI,EAAE,CAAC,CAAC;YAEjD,EAAE,CAAC,QAAQ,CAAC,OAAO,EAAE,OAAO,EAAE,CAAC,GAAG,EAAE,EAAE;gBAClC,IAAI,GAAG,EAAE,CAAC;oBACN,MAAM,CAAC,GAAG,CAAC,CAAC;oBACZ,OAAO;gBACX,CAAC;gBAED,MAAM,KAAK,GAAG,EAAE,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;gBACnC,MAAM,QAAQ,GAAG,SAAS,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,IAAI,SAAS,CAAC;gBAEzD,MAAM,QAAQ,GAAiB;oBAC3B,YAAY,EAAE,QAAQ;oBACtB,IAAI,EAAE,KAAK,CAAC,IAAI;oBAChB,QAAQ,EAAE,QAAQ;oBAClB,GAAG,EAAE,SAAS;oBACd,QAAQ,EAAE,OAAO;oBACjB,GAAG,EAAE,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC;iBAC9B,CAAC;gBACF,OAAO,CAAC,QAAQ,CAAC,CAAC;YACtB,CAAC,CAAC,CAAC;QACP,CAAC,CAAC,CAAC;IACP,CAAC;CAGJ;AAzOD,oCAyOC"}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { GetObjectCommandInput, PutObjectCommandInput } from '@aws-sdk/client-s3';
|
|
2
|
-
import { StorageEngine } from 'multer';
|
|
3
|
-
import { S3StorageOptions, Storage, UploadedFile } from '../types';
|
|
4
|
-
export declare class S3Storage implements StorageEngine, Storage {
|
|
5
|
-
private options;
|
|
6
|
-
private s3;
|
|
7
|
-
private fileNameFunction;
|
|
8
|
-
private fileDistFunction;
|
|
9
|
-
constructor(options: S3StorageOptions);
|
|
10
|
-
_handleFile(req: any, file: Express.Multer.File, cb: (error?: any, info?: any) => void): void;
|
|
11
|
-
_removeFile(_req: any, file: any, cb: (error: Error | null) => void): void;
|
|
12
|
-
getUrl(key: string): string;
|
|
13
|
-
getSignedUrl(key: string, objectConfig?: Partial<GetObjectCommandInput>): Promise<string>;
|
|
14
|
-
getFile(key: string): Promise<Buffer>;
|
|
15
|
-
putFile(fileContent: Buffer, key: string, options?: Partial<PutObjectCommandInput>): Promise<any>;
|
|
16
|
-
deleteFile(key: string): Promise<void>;
|
|
17
|
-
private streamToBuffer;
|
|
18
|
-
copyFile(oldKey: string, newKey: string): Promise<UploadedFile>;
|
|
19
|
-
}
|