@nest-omni/core 4.1.3-11 → 4.1.3-12
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/audit/audit.module.js +17 -0
- package/audit/controllers/audit.controller.d.ts +64 -0
- package/audit/controllers/audit.controller.js +50 -0
- package/audit/decorators/audit-action.decorator.d.ts +74 -0
- package/audit/decorators/audit-action.decorator.js +42 -0
- package/audit/decorators/entity-audit.decorator.d.ts +10 -1
- package/audit/decorators/entity-audit.decorator.js +34 -16
- package/audit/decorators/index.d.ts +1 -0
- package/audit/decorators/index.js +1 -0
- package/audit/entities/audit-action-summary.entity.d.ts +23 -0
- package/audit/entities/audit-action-summary.entity.js +101 -0
- package/audit/entities/entity-audit-log.entity.d.ts +3 -0
- package/audit/entities/entity-audit-log.entity.js +25 -2
- package/audit/entities/entity-transaction.entity.d.ts +3 -4
- package/audit/entities/entity-transaction.entity.js +10 -3
- package/audit/entities/index.d.ts +1 -0
- package/audit/entities/index.js +1 -0
- package/audit/entities/manual-operation-log.entity.js +8 -1
- package/audit/enums/audit.enums.d.ts +1 -10
- package/audit/enums/audit.enums.js +7 -17
- package/audit/index.d.ts +2 -1
- package/audit/index.js +5 -1
- package/audit/interceptors/audit-action.interceptor.d.ts +38 -0
- package/audit/interceptors/audit-action.interceptor.js +215 -0
- package/audit/interceptors/index.d.ts +1 -0
- package/audit/interceptors/index.js +1 -0
- package/audit/interfaces/audit.interfaces.d.ts +10 -5
- package/audit/services/audit-action.service.d.ts +141 -0
- package/audit/services/audit-action.service.js +244 -0
- package/audit/services/audit-context.service.d.ts +82 -0
- package/audit/services/audit-context.service.js +170 -0
- package/audit/services/entity-audit.service.d.ts +104 -3
- package/audit/services/entity-audit.service.js +306 -9
- package/audit/services/index.d.ts +1 -0
- package/audit/services/index.js +1 -0
- package/audit/services/manual-audit-log.service.d.ts +24 -23
- package/audit/services/manual-audit-log.service.js +32 -53
- package/audit/services/operation-description.service.d.ts +13 -3
- package/audit/services/operation-description.service.js +161 -24
- package/audit/services/transaction-audit.service.js +3 -3
- package/audit/subscribers/entity-audit.subscriber.d.ts +4 -0
- package/audit/subscribers/entity-audit.subscriber.js +47 -0
- package/file-upload/controllers/file-access.controller.d.ts +23 -0
- package/file-upload/controllers/file-access.controller.js +128 -0
- package/file-upload/decorators/csv-data.decorator.d.ts +44 -0
- package/file-upload/decorators/csv-data.decorator.js +131 -0
- package/file-upload/decorators/excel-data.decorator.d.ts +44 -0
- package/file-upload/decorators/excel-data.decorator.js +125 -0
- package/file-upload/decorators/file-upload.decorator.d.ts +83 -0
- package/file-upload/decorators/file-upload.decorator.js +172 -0
- package/file-upload/decorators/index.d.ts +4 -0
- package/file-upload/decorators/index.js +20 -0
- package/file-upload/decorators/process.decorator.d.ts +40 -0
- package/file-upload/decorators/process.decorator.js +52 -0
- package/file-upload/dto/create-file.dto.d.ts +24 -0
- package/file-upload/dto/create-file.dto.js +112 -0
- package/file-upload/dto/find-files.dto.d.ts +15 -0
- package/file-upload/dto/find-files.dto.js +76 -0
- package/file-upload/dto/index.d.ts +4 -0
- package/file-upload/dto/index.js +20 -0
- package/file-upload/dto/pagination.dto.d.ts +7 -0
- package/file-upload/dto/pagination.dto.js +39 -0
- package/file-upload/dto/update-file.dto.d.ts +16 -0
- package/file-upload/dto/update-file.dto.js +71 -0
- package/file-upload/entities/file-metadata.entity.d.ts +22 -0
- package/file-upload/entities/file-metadata.entity.js +84 -0
- package/file-upload/entities/file.entity.d.ts +129 -0
- package/file-upload/entities/file.entity.js +384 -0
- package/file-upload/entities/index.d.ts +2 -0
- package/file-upload/entities/index.js +18 -0
- package/file-upload/enums/file-type.enum.d.ts +72 -0
- package/file-upload/enums/file-type.enum.js +212 -0
- package/file-upload/exceptions/file-upload.exception.d.ts +57 -0
- package/file-upload/exceptions/file-upload.exception.js +120 -0
- package/file-upload/exceptions/index.d.ts +1 -0
- package/file-upload/exceptions/index.js +17 -0
- package/file-upload/file-upload.module.d.ts +89 -0
- package/file-upload/file-upload.module.js +264 -0
- package/file-upload/index.d.ts +26 -0
- package/file-upload/index.js +59 -0
- package/file-upload/interceptors/file-upload.interceptor.d.ts +48 -0
- package/file-upload/interceptors/file-upload.interceptor.js +434 -0
- package/file-upload/interceptors/index.d.ts +1 -0
- package/file-upload/interceptors/index.js +17 -0
- package/file-upload/interfaces/custom-file-type.interface.d.ts +72 -0
- package/file-upload/interfaces/custom-file-type.interface.js +2 -0
- package/file-upload/interfaces/file-buffer.interface.d.ts +72 -0
- package/file-upload/interfaces/file-buffer.interface.js +2 -0
- package/file-upload/interfaces/file-entity.interface.d.ts +142 -0
- package/file-upload/interfaces/file-entity.interface.js +28 -0
- package/file-upload/interfaces/file-metadata.interface.d.ts +21 -0
- package/file-upload/interfaces/file-metadata.interface.js +2 -0
- package/file-upload/interfaces/file-upload-options.interface.d.ts +117 -0
- package/file-upload/interfaces/file-upload-options.interface.js +2 -0
- package/file-upload/interfaces/index.d.ts +7 -0
- package/file-upload/interfaces/index.js +24 -0
- package/file-upload/interfaces/storage-provider.interface.d.ts +239 -0
- package/file-upload/interfaces/storage-provider.interface.js +2 -0
- package/file-upload/interfaces/upload-options.interface.d.ts +19 -0
- package/file-upload/interfaces/upload-options.interface.js +2 -0
- package/file-upload/providers/index.d.ts +2 -0
- package/file-upload/providers/index.js +18 -0
- package/file-upload/providers/local-storage.provider.d.ts +98 -0
- package/file-upload/providers/local-storage.provider.js +484 -0
- package/file-upload/providers/s3-storage.provider.d.ts +87 -0
- package/file-upload/providers/s3-storage.provider.js +455 -0
- package/file-upload/services/file-signature-validator.service.d.ts +118 -0
- package/file-upload/services/file-signature-validator.service.js +376 -0
- package/file-upload/services/file.service.d.ts +190 -0
- package/file-upload/services/file.service.js +609 -0
- package/file-upload/services/index.d.ts +4 -0
- package/file-upload/services/index.js +20 -0
- package/file-upload/services/malicious-file-detector.service.d.ts +274 -0
- package/file-upload/services/malicious-file-detector.service.js +1035 -0
- package/file-upload/services/mime-registry.service.d.ts +47 -0
- package/file-upload/services/mime-registry.service.js +167 -0
- package/file-upload/utils/checksum.util.d.ts +28 -0
- package/file-upload/utils/checksum.util.js +65 -0
- package/file-upload/utils/dynamic-import.util.d.ts +50 -0
- package/file-upload/utils/dynamic-import.util.js +144 -0
- package/file-upload/utils/filename.util.d.ts +59 -0
- package/file-upload/utils/filename.util.js +184 -0
- package/file-upload/utils/filepath.util.d.ts +70 -0
- package/file-upload/utils/filepath.util.js +152 -0
- package/file-upload/utils/index.d.ts +4 -0
- package/file-upload/utils/index.js +20 -0
- package/index.d.ts +3 -1
- package/index.js +4 -1
- package/package.json +4 -5
- package/setup/bootstrap.setup.d.ts +1 -0
- package/setup/bootstrap.setup.js +1 -0
- package/shared/index.d.ts +1 -1
- package/shared/index.js +1 -1
- package/shared/{serviceRegistryModule.js → service-registry.module.js} +0 -12
- package/shared/services/index.d.ts +0 -1
- package/shared/services/index.js +0 -1
- package/transaction/__tests__/mocks.d.ts +9 -0
- package/transaction/__tests__/mocks.js +33 -0
- package/transaction/base-service-transaction.d.ts +99 -0
- package/transaction/base-service-transaction.js +286 -0
- package/transaction/cls-compatibility.service.d.ts +55 -0
- package/transaction/cls-compatibility.service.js +127 -0
- package/transaction/data-source-registry.d.ts +91 -0
- package/transaction/data-source-registry.js +349 -0
- package/transaction/database-adapter.d.ts +44 -0
- package/transaction/database-adapter.js +240 -0
- package/transaction/decorators/entity-datasource.decorator.d.ts +62 -0
- package/transaction/decorators/entity-datasource.decorator.js +105 -0
- package/transaction/index.d.ts +14 -0
- package/transaction/index.js +57 -0
- package/transaction/logging-transactional.interceptor.d.ts +18 -0
- package/transaction/logging-transactional.interceptor.js +163 -0
- package/transaction/transaction-context.service.d.ts +137 -0
- package/transaction/transaction-context.service.js +411 -0
- package/transaction/transaction-manager.d.ts +230 -0
- package/transaction/transaction-manager.js +1001 -0
- package/transaction/transaction-synchronization.d.ts +171 -0
- package/transaction/transaction-synchronization.js +380 -0
- package/transaction/transaction.errors.d.ts +91 -0
- package/transaction/transaction.errors.js +206 -0
- package/transaction/transaction.module.d.ts +30 -0
- package/transaction/transaction.module.js +98 -0
- package/transaction/transactional.decorator.d.ts +82 -0
- package/transaction/transactional.decorator.js +319 -0
- package/transaction/typeorm-module-wrapper.d.ts +96 -0
- package/transaction/typeorm-module-wrapper.js +197 -0
- package/validators/file-mimetype.validator.d.ts +0 -2
- package/validators/file-mimetype.validator.js +4 -6
- package/validators/is-exists.validator.d.ts +2 -5
- package/validators/is-exists.validator.js +4 -6
- package/validators/is-unique.validator.d.ts +2 -5
- package/validators/is-unique.validator.js +6 -11
- package/shared/services/validator.service.d.ts +0 -3
- package/shared/services/validator.service.js +0 -20
- /package/shared/{serviceRegistryModule.d.ts → service-registry.module.d.ts} +0 -0
|
@@ -0,0 +1,264 @@
|
|
|
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
|
+
};
|
|
8
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
9
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
10
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
11
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
12
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
13
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
14
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
15
|
+
});
|
|
16
|
+
};
|
|
17
|
+
var FileUploadModule_1;
|
|
18
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
|
+
exports.FileUploadModule = void 0;
|
|
20
|
+
const common_1 = require("@nestjs/common");
|
|
21
|
+
const typeorm_1 = require("@nestjs/typeorm");
|
|
22
|
+
const file_upload_interceptor_1 = require("./interceptors/file-upload.interceptor");
|
|
23
|
+
const local_storage_provider_1 = require("./providers/local-storage.provider");
|
|
24
|
+
const mime_registry_service_1 = require("./services/mime-registry.service");
|
|
25
|
+
const file_signature_validator_service_1 = require("./services/file-signature-validator.service");
|
|
26
|
+
const malicious_file_detector_service_1 = require("./services/malicious-file-detector.service");
|
|
27
|
+
const file_service_1 = require("./services/file.service");
|
|
28
|
+
const file_entity_1 = require("./entities/file.entity");
|
|
29
|
+
const file_metadata_entity_1 = require("./entities/file-metadata.entity");
|
|
30
|
+
const file_access_controller_1 = require("./controllers/file-access.controller");
|
|
31
|
+
/**
|
|
32
|
+
* 文件上传模块(增强版)
|
|
33
|
+
*/
|
|
34
|
+
let FileUploadModule = FileUploadModule_1 = class FileUploadModule {
|
|
35
|
+
/**
|
|
36
|
+
* 同步配置模块
|
|
37
|
+
*/
|
|
38
|
+
static forRoot(options = {}) {
|
|
39
|
+
var _a, _b, _c, _d, _e, _f;
|
|
40
|
+
const providers = [
|
|
41
|
+
// 核心服务
|
|
42
|
+
mime_registry_service_1.MimeRegistryService,
|
|
43
|
+
file_signature_validator_service_1.FileSignatureValidator,
|
|
44
|
+
// 恶意文件检测器(带配置)
|
|
45
|
+
{
|
|
46
|
+
provide: 'MALICIOUS_DETECTOR_OPTIONS',
|
|
47
|
+
useValue: options.maliciousDetection || {},
|
|
48
|
+
},
|
|
49
|
+
malicious_file_detector_service_1.MaliciousFileDetector,
|
|
50
|
+
// Interceptor
|
|
51
|
+
file_upload_interceptor_1.FileUploadInterceptor,
|
|
52
|
+
// 配置
|
|
53
|
+
{
|
|
54
|
+
provide: 'FILE_UPLOAD_OPTIONS',
|
|
55
|
+
useValue: options,
|
|
56
|
+
},
|
|
57
|
+
];
|
|
58
|
+
// 注册自定义文件类型
|
|
59
|
+
if (options.customFileTypes) {
|
|
60
|
+
providers.push({
|
|
61
|
+
provide: 'CUSTOM_FILE_TYPES',
|
|
62
|
+
useValue: options.customFileTypes,
|
|
63
|
+
});
|
|
64
|
+
// 初始化自定义类型
|
|
65
|
+
providers.push({
|
|
66
|
+
provide: 'FILE_TYPE_INITIALIZER',
|
|
67
|
+
useFactory: (registry) => {
|
|
68
|
+
registry.registerCustomFileTypes(options.customFileTypes);
|
|
69
|
+
return registry;
|
|
70
|
+
},
|
|
71
|
+
inject: [mime_registry_service_1.MimeRegistryService],
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
// 注册处理器
|
|
75
|
+
if (options.processors && options.processors.length > 0) {
|
|
76
|
+
const processorMap = new Map();
|
|
77
|
+
for (const ProcessorClass of options.processors) {
|
|
78
|
+
const processor = new ProcessorClass();
|
|
79
|
+
processorMap.set(processor.name, processor);
|
|
80
|
+
}
|
|
81
|
+
providers.push({
|
|
82
|
+
provide: 'FILE_PROCESSORS',
|
|
83
|
+
useValue: processorMap,
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
// 注册存储提供者
|
|
87
|
+
if (options.storage) {
|
|
88
|
+
const storageProviders = this.createStorageProviders(options.storage);
|
|
89
|
+
providers.push(...storageProviders);
|
|
90
|
+
}
|
|
91
|
+
// TypeORM 配置
|
|
92
|
+
const imports = [];
|
|
93
|
+
const databaseEnabled = ((_a = options.database) === null || _a === void 0 ? void 0 : _a.autoCreateTable) !== false;
|
|
94
|
+
if (databaseEnabled) {
|
|
95
|
+
imports.push(typeorm_1.TypeOrmModule.forFeature([file_entity_1.FileEntity, file_metadata_entity_1.FileMetadataEntity]));
|
|
96
|
+
providers.push(file_service_1.FileService);
|
|
97
|
+
}
|
|
98
|
+
// Build exports array - only export what's actually provided
|
|
99
|
+
const exports = [
|
|
100
|
+
mime_registry_service_1.MimeRegistryService,
|
|
101
|
+
file_signature_validator_service_1.FileSignatureValidator,
|
|
102
|
+
malicious_file_detector_service_1.MaliciousFileDetector,
|
|
103
|
+
file_upload_interceptor_1.FileUploadInterceptor,
|
|
104
|
+
'FILE_UPLOAD_OPTIONS',
|
|
105
|
+
];
|
|
106
|
+
if (databaseEnabled) {
|
|
107
|
+
exports.push(file_service_1.FileService);
|
|
108
|
+
}
|
|
109
|
+
if (options.processors && options.processors.length > 0) {
|
|
110
|
+
exports.push('FILE_PROCESSORS');
|
|
111
|
+
}
|
|
112
|
+
if (((_b = options.storage) === null || _b === void 0 ? void 0 : _b.local) ||
|
|
113
|
+
!((_c = options.storage) === null || _c === void 0 ? void 0 : _c.default) ||
|
|
114
|
+
((_d = options.storage) === null || _d === void 0 ? void 0 : _d.default) === 'local') {
|
|
115
|
+
if ((_e = options.storage) === null || _e === void 0 ? void 0 : _e.local) {
|
|
116
|
+
exports.push('LOCAL_STORAGE_PROVIDER');
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
if ((_f = options.storage) === null || _f === void 0 ? void 0 : _f.s3) {
|
|
120
|
+
exports.push('S3_STORAGE_PROVIDER');
|
|
121
|
+
}
|
|
122
|
+
if (options.storage) {
|
|
123
|
+
exports.push('STORAGE_PROVIDER');
|
|
124
|
+
}
|
|
125
|
+
return {
|
|
126
|
+
module: FileUploadModule_1,
|
|
127
|
+
imports,
|
|
128
|
+
controllers: databaseEnabled ? [file_access_controller_1.FileAccessController] : [],
|
|
129
|
+
providers,
|
|
130
|
+
exports,
|
|
131
|
+
global: true,
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* 异步配置模块
|
|
136
|
+
*/
|
|
137
|
+
static forRootAsync(asyncOptions) {
|
|
138
|
+
const providers = [
|
|
139
|
+
// 核心服务
|
|
140
|
+
mime_registry_service_1.MimeRegistryService,
|
|
141
|
+
file_signature_validator_service_1.FileSignatureValidator,
|
|
142
|
+
// 恶意文件检测器配置(异步)
|
|
143
|
+
{
|
|
144
|
+
provide: 'MALICIOUS_DETECTOR_OPTIONS',
|
|
145
|
+
useFactory: (...args) => __awaiter(this, void 0, void 0, function* () {
|
|
146
|
+
const options = yield asyncOptions.useFactory(...args);
|
|
147
|
+
return options.maliciousDetection || {};
|
|
148
|
+
}),
|
|
149
|
+
inject: asyncOptions.inject || [],
|
|
150
|
+
},
|
|
151
|
+
malicious_file_detector_service_1.MaliciousFileDetector,
|
|
152
|
+
// Interceptor
|
|
153
|
+
file_upload_interceptor_1.FileUploadInterceptor,
|
|
154
|
+
// 异步配置
|
|
155
|
+
{
|
|
156
|
+
provide: 'FILE_UPLOAD_OPTIONS',
|
|
157
|
+
useFactory: asyncOptions.useFactory,
|
|
158
|
+
inject: asyncOptions.inject || [],
|
|
159
|
+
},
|
|
160
|
+
// 异步处理器注册
|
|
161
|
+
{
|
|
162
|
+
provide: 'FILE_PROCESSORS',
|
|
163
|
+
useFactory: (...args) => __awaiter(this, void 0, void 0, function* () {
|
|
164
|
+
const options = yield asyncOptions.useFactory(...args);
|
|
165
|
+
if (!options.processors || options.processors.length === 0) {
|
|
166
|
+
return new Map();
|
|
167
|
+
}
|
|
168
|
+
const processorMap = new Map();
|
|
169
|
+
for (const ProcessorClass of options.processors) {
|
|
170
|
+
const processor = new ProcessorClass();
|
|
171
|
+
processorMap.set(processor.name, processor);
|
|
172
|
+
}
|
|
173
|
+
return processorMap;
|
|
174
|
+
}),
|
|
175
|
+
inject: asyncOptions.inject || [],
|
|
176
|
+
},
|
|
177
|
+
// 异步自定义文件类型初始化
|
|
178
|
+
{
|
|
179
|
+
provide: 'FILE_TYPE_INITIALIZER',
|
|
180
|
+
useFactory: (registry, ...args) => __awaiter(this, void 0, void 0, function* () {
|
|
181
|
+
const options = yield asyncOptions.useFactory(...args);
|
|
182
|
+
if (options.customFileTypes) {
|
|
183
|
+
registry.registerCustomFileTypes(options.customFileTypes);
|
|
184
|
+
}
|
|
185
|
+
return registry;
|
|
186
|
+
}),
|
|
187
|
+
inject: [mime_registry_service_1.MimeRegistryService, ...(asyncOptions.inject || [])],
|
|
188
|
+
},
|
|
189
|
+
];
|
|
190
|
+
const imports = [
|
|
191
|
+
// 默认开启 TypeORM
|
|
192
|
+
typeorm_1.TypeOrmModule.forFeature([file_entity_1.FileEntity, file_metadata_entity_1.FileMetadataEntity]),
|
|
193
|
+
];
|
|
194
|
+
providers.push(file_service_1.FileService);
|
|
195
|
+
// For async, we always provide FILE_PROCESSORS (with empty Map fallback)
|
|
196
|
+
// Storage providers need to be handled via the options factory
|
|
197
|
+
return {
|
|
198
|
+
module: FileUploadModule_1,
|
|
199
|
+
imports,
|
|
200
|
+
controllers: [file_access_controller_1.FileAccessController],
|
|
201
|
+
providers,
|
|
202
|
+
exports: [
|
|
203
|
+
mime_registry_service_1.MimeRegistryService,
|
|
204
|
+
file_signature_validator_service_1.FileSignatureValidator,
|
|
205
|
+
malicious_file_detector_service_1.MaliciousFileDetector,
|
|
206
|
+
file_upload_interceptor_1.FileUploadInterceptor,
|
|
207
|
+
file_service_1.FileService,
|
|
208
|
+
'FILE_UPLOAD_OPTIONS',
|
|
209
|
+
'FILE_PROCESSORS',
|
|
210
|
+
],
|
|
211
|
+
global: true,
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* 创建存储提供者
|
|
216
|
+
*/
|
|
217
|
+
static createStorageProviders(storageConfig) {
|
|
218
|
+
const providers = [];
|
|
219
|
+
// 本地存储
|
|
220
|
+
if (storageConfig.local) {
|
|
221
|
+
providers.push({
|
|
222
|
+
provide: 'LOCAL_STORAGE_PROVIDER',
|
|
223
|
+
useFactory: () => __awaiter(this, void 0, void 0, function* () {
|
|
224
|
+
const provider = new local_storage_provider_1.LocalStorageProvider(storageConfig.local);
|
|
225
|
+
yield provider.initialize();
|
|
226
|
+
return provider;
|
|
227
|
+
}),
|
|
228
|
+
});
|
|
229
|
+
// 如果是默认存储
|
|
230
|
+
if (storageConfig.default === 'local' || !storageConfig.default) {
|
|
231
|
+
providers.push({
|
|
232
|
+
provide: 'STORAGE_PROVIDER',
|
|
233
|
+
useExisting: 'LOCAL_STORAGE_PROVIDER',
|
|
234
|
+
});
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
// S3 存储
|
|
238
|
+
if (storageConfig.s3) {
|
|
239
|
+
providers.push({
|
|
240
|
+
provide: 'S3_STORAGE_PROVIDER',
|
|
241
|
+
useFactory: () => __awaiter(this, void 0, void 0, function* () {
|
|
242
|
+
// Lazy load S3StorageProvider to avoid bundling AWS SDK
|
|
243
|
+
const { S3StorageProvider } = yield Promise.resolve().then(() => require('./providers/s3-storage.provider'));
|
|
244
|
+
const provider = new S3StorageProvider(storageConfig.s3);
|
|
245
|
+
yield provider.initialize();
|
|
246
|
+
return provider;
|
|
247
|
+
}),
|
|
248
|
+
});
|
|
249
|
+
// 如果是默认存储
|
|
250
|
+
if (storageConfig.default === 's3') {
|
|
251
|
+
providers.push({
|
|
252
|
+
provide: 'STORAGE_PROVIDER',
|
|
253
|
+
useExisting: 'S3_STORAGE_PROVIDER',
|
|
254
|
+
});
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
// TODO: 添加 OSS, MinIO 存储提供者
|
|
258
|
+
return providers;
|
|
259
|
+
}
|
|
260
|
+
};
|
|
261
|
+
exports.FileUploadModule = FileUploadModule;
|
|
262
|
+
exports.FileUploadModule = FileUploadModule = FileUploadModule_1 = __decorate([
|
|
263
|
+
(0, common_1.Module)({})
|
|
264
|
+
], FileUploadModule);
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export * from './file-upload.module';
|
|
2
|
+
export * from './enums/file-type.enum';
|
|
3
|
+
export * from './interfaces/file-upload-options.interface';
|
|
4
|
+
export * from './interfaces/storage-provider.interface';
|
|
5
|
+
export * from './interfaces/file-buffer.interface';
|
|
6
|
+
export * from './interfaces/file-metadata.interface';
|
|
7
|
+
export * from './interfaces/upload-options.interface';
|
|
8
|
+
export * from './interfaces/custom-file-type.interface';
|
|
9
|
+
export * from './decorators/file-upload.decorator';
|
|
10
|
+
export * from './decorators/excel-data.decorator';
|
|
11
|
+
export * from './decorators/csv-data.decorator';
|
|
12
|
+
export * from './decorators/process.decorator';
|
|
13
|
+
export * from './interceptors/file-upload.interceptor';
|
|
14
|
+
export * from './controllers/file-access.controller';
|
|
15
|
+
export * from './providers/local-storage.provider';
|
|
16
|
+
export * from './services/mime-registry.service';
|
|
17
|
+
export * from './services/file-signature-validator.service';
|
|
18
|
+
export * from './services/malicious-file-detector.service';
|
|
19
|
+
export * from './services/file.service';
|
|
20
|
+
export * from './entities/file.entity';
|
|
21
|
+
export * from './entities/file-metadata.entity';
|
|
22
|
+
export * from './dto/create-file.dto';
|
|
23
|
+
export * from './dto/update-file.dto';
|
|
24
|
+
export * from './dto/find-files.dto';
|
|
25
|
+
export * from './dto/pagination.dto';
|
|
26
|
+
export * from './exceptions/file-upload.exception';
|
|
@@ -0,0 +1,59 @@
|
|
|
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
|
+
// Module
|
|
18
|
+
__exportStar(require("./file-upload.module"), exports);
|
|
19
|
+
// Enums
|
|
20
|
+
__exportStar(require("./enums/file-type.enum"), exports);
|
|
21
|
+
// Interfaces
|
|
22
|
+
__exportStar(require("./interfaces/file-upload-options.interface"), exports);
|
|
23
|
+
__exportStar(require("./interfaces/storage-provider.interface"), exports);
|
|
24
|
+
__exportStar(require("./interfaces/file-buffer.interface"), exports);
|
|
25
|
+
__exportStar(require("./interfaces/file-metadata.interface"), exports);
|
|
26
|
+
__exportStar(require("./interfaces/upload-options.interface"), exports);
|
|
27
|
+
__exportStar(require("./interfaces/custom-file-type.interface"), exports);
|
|
28
|
+
// Note: FileEntity interface is not exported to avoid conflict with TypeORM entity
|
|
29
|
+
// Decorators
|
|
30
|
+
__exportStar(require("./decorators/file-upload.decorator"), exports);
|
|
31
|
+
__exportStar(require("./decorators/excel-data.decorator"), exports);
|
|
32
|
+
__exportStar(require("./decorators/csv-data.decorator"), exports);
|
|
33
|
+
__exportStar(require("./decorators/process.decorator"), exports);
|
|
34
|
+
// Interceptors
|
|
35
|
+
__exportStar(require("./interceptors/file-upload.interceptor"), exports);
|
|
36
|
+
// Controllers
|
|
37
|
+
__exportStar(require("./controllers/file-access.controller"), exports);
|
|
38
|
+
// Providers
|
|
39
|
+
__exportStar(require("./providers/local-storage.provider"), exports);
|
|
40
|
+
// Note: S3StorageProvider is not exported to avoid bundling optional AWS SDK dependencies
|
|
41
|
+
// export * from './providers/s3-storage.provider';
|
|
42
|
+
// Services
|
|
43
|
+
__exportStar(require("./services/mime-registry.service"), exports);
|
|
44
|
+
__exportStar(require("./services/file-signature-validator.service"), exports);
|
|
45
|
+
__exportStar(require("./services/malicious-file-detector.service"), exports);
|
|
46
|
+
__exportStar(require("./services/file.service"), exports);
|
|
47
|
+
// Entities
|
|
48
|
+
__exportStar(require("./entities/file.entity"), exports);
|
|
49
|
+
__exportStar(require("./entities/file-metadata.entity"), exports);
|
|
50
|
+
// DTOs
|
|
51
|
+
__exportStar(require("./dto/create-file.dto"), exports);
|
|
52
|
+
__exportStar(require("./dto/update-file.dto"), exports);
|
|
53
|
+
__exportStar(require("./dto/find-files.dto"), exports);
|
|
54
|
+
__exportStar(require("./dto/pagination.dto"), exports);
|
|
55
|
+
// Exceptions
|
|
56
|
+
__exportStar(require("./exceptions/file-upload.exception"), exports);
|
|
57
|
+
// Utils
|
|
58
|
+
// Note: DynamicImportUtil is an internal utility not exported to avoid bundling optional dependencies
|
|
59
|
+
// export * from './utils/dynamic-import.util';
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { CallHandler, ExecutionContext, NestInterceptor } from '@nestjs/common';
|
|
2
|
+
import { Reflector } from '@nestjs/core';
|
|
3
|
+
import { Observable } from 'rxjs';
|
|
4
|
+
import { IFileProcessor } from '../interfaces/file-upload-options.interface';
|
|
5
|
+
import { FileService } from '../services/file.service';
|
|
6
|
+
import { FileSignatureValidator } from '../services/file-signature-validator.service';
|
|
7
|
+
import { MaliciousFileDetector } from '../services/malicious-file-detector.service';
|
|
8
|
+
import { MimeRegistryService } from '../services/mime-registry.service';
|
|
9
|
+
/**
|
|
10
|
+
* 文件上传拦截器(增强版)
|
|
11
|
+
* 负责创建文件记录、执行钩子、处理器等后置逻辑
|
|
12
|
+
*/
|
|
13
|
+
export declare class FileUploadInterceptor implements NestInterceptor {
|
|
14
|
+
private readonly reflector;
|
|
15
|
+
private readonly mimeRegistry;
|
|
16
|
+
private readonly processors?;
|
|
17
|
+
private readonly fileService?;
|
|
18
|
+
private readonly signatureValidator?;
|
|
19
|
+
private readonly maliciousDetector?;
|
|
20
|
+
private readonly moduleOptions?;
|
|
21
|
+
private readonly logger;
|
|
22
|
+
constructor(reflector: Reflector, mimeRegistry: MimeRegistryService, processors?: Map<string, IFileProcessor>, fileService?: FileService, signatureValidator?: FileSignatureValidator, maliciousDetector?: MaliciousFileDetector, moduleOptions?: any);
|
|
23
|
+
intercept(context: ExecutionContext, next: CallHandler): Promise<Observable<any>>;
|
|
24
|
+
/**
|
|
25
|
+
* 创建上传上下文
|
|
26
|
+
*/
|
|
27
|
+
private createUploadContext;
|
|
28
|
+
/**
|
|
29
|
+
* 获取处理器
|
|
30
|
+
*/
|
|
31
|
+
private getProcessor;
|
|
32
|
+
/**
|
|
33
|
+
* 生成uploadId
|
|
34
|
+
*/
|
|
35
|
+
private generateUploadId;
|
|
36
|
+
/**
|
|
37
|
+
* 计算文件校验和
|
|
38
|
+
*/
|
|
39
|
+
private calculateChecksum;
|
|
40
|
+
/**
|
|
41
|
+
* 验证 MIME 类型
|
|
42
|
+
*/
|
|
43
|
+
private validateMimeType;
|
|
44
|
+
/**
|
|
45
|
+
* 验证扩展名
|
|
46
|
+
*/
|
|
47
|
+
private validateExtension;
|
|
48
|
+
}
|