@nest-omni/core 4.1.3-10 → 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.
Files changed (183) hide show
  1. package/audit/audit.module.js +42 -2
  2. package/audit/controllers/audit.controller.d.ts +64 -0
  3. package/audit/controllers/audit.controller.js +50 -0
  4. package/audit/decorators/audit-action.decorator.d.ts +74 -0
  5. package/audit/decorators/audit-action.decorator.js +42 -0
  6. package/audit/decorators/audit-controller.decorator.d.ts +1 -1
  7. package/audit/decorators/audit-controller.decorator.js +2 -2
  8. package/audit/decorators/entity-audit.decorator.d.ts +78 -2
  9. package/audit/decorators/entity-audit.decorator.js +145 -4
  10. package/audit/decorators/index.d.ts +2 -0
  11. package/audit/decorators/index.js +2 -0
  12. package/audit/entities/audit-action-summary.entity.d.ts +23 -0
  13. package/audit/entities/audit-action-summary.entity.js +101 -0
  14. package/audit/entities/entity-audit-log.entity.d.ts +8 -0
  15. package/audit/entities/entity-audit-log.entity.js +54 -2
  16. package/audit/entities/entity-transaction.entity.d.ts +8 -2
  17. package/audit/entities/entity-transaction.entity.js +39 -3
  18. package/audit/entities/index.d.ts +3 -0
  19. package/audit/entities/index.js +3 -0
  20. package/audit/entities/manual-operation-log.entity.js +8 -1
  21. package/audit/enums/audit.enums.d.ts +22 -6
  22. package/audit/enums/audit.enums.js +27 -9
  23. package/audit/index.d.ts +4 -1
  24. package/audit/index.js +25 -2
  25. package/audit/interceptors/audit-action.interceptor.d.ts +38 -0
  26. package/audit/interceptors/audit-action.interceptor.js +215 -0
  27. package/audit/interceptors/index.d.ts +1 -0
  28. package/audit/interceptors/index.js +1 -0
  29. package/audit/interfaces/audit.interfaces.d.ts +145 -2
  30. package/audit/services/audit-action.service.d.ts +141 -0
  31. package/audit/services/audit-action.service.js +244 -0
  32. package/audit/services/audit-context.service.d.ts +82 -0
  33. package/audit/services/audit-context.service.js +170 -0
  34. package/audit/services/entity-audit.service.d.ts +174 -4
  35. package/audit/services/entity-audit.service.js +515 -14
  36. package/audit/services/index.d.ts +3 -0
  37. package/audit/services/index.js +3 -0
  38. package/audit/services/manual-audit-log.service.d.ts +24 -23
  39. package/audit/services/manual-audit-log.service.js +32 -53
  40. package/audit/services/operation-description.service.d.ts +13 -3
  41. package/audit/services/operation-description.service.js +161 -24
  42. package/audit/services/transaction-audit.service.js +3 -3
  43. package/audit/subscribers/entity-audit.subscriber.d.ts +4 -0
  44. package/audit/subscribers/entity-audit.subscriber.js +47 -0
  45. package/file-upload/controllers/file-access.controller.d.ts +23 -0
  46. package/file-upload/controllers/file-access.controller.js +128 -0
  47. package/file-upload/decorators/csv-data.decorator.d.ts +44 -0
  48. package/file-upload/decorators/csv-data.decorator.js +131 -0
  49. package/file-upload/decorators/excel-data.decorator.d.ts +44 -0
  50. package/file-upload/decorators/excel-data.decorator.js +125 -0
  51. package/file-upload/decorators/file-upload.decorator.d.ts +83 -0
  52. package/file-upload/decorators/file-upload.decorator.js +172 -0
  53. package/file-upload/decorators/index.d.ts +4 -0
  54. package/file-upload/decorators/index.js +20 -0
  55. package/file-upload/decorators/process.decorator.d.ts +40 -0
  56. package/file-upload/decorators/process.decorator.js +52 -0
  57. package/file-upload/dto/create-file.dto.d.ts +24 -0
  58. package/file-upload/dto/create-file.dto.js +112 -0
  59. package/file-upload/dto/find-files.dto.d.ts +15 -0
  60. package/file-upload/dto/find-files.dto.js +76 -0
  61. package/file-upload/dto/index.d.ts +4 -0
  62. package/file-upload/dto/index.js +20 -0
  63. package/file-upload/dto/pagination.dto.d.ts +7 -0
  64. package/file-upload/dto/pagination.dto.js +39 -0
  65. package/file-upload/dto/update-file.dto.d.ts +16 -0
  66. package/file-upload/dto/update-file.dto.js +71 -0
  67. package/file-upload/entities/file-metadata.entity.d.ts +22 -0
  68. package/file-upload/entities/file-metadata.entity.js +84 -0
  69. package/file-upload/entities/file.entity.d.ts +129 -0
  70. package/file-upload/entities/file.entity.js +384 -0
  71. package/file-upload/entities/index.d.ts +2 -0
  72. package/file-upload/entities/index.js +18 -0
  73. package/file-upload/enums/file-type.enum.d.ts +72 -0
  74. package/file-upload/enums/file-type.enum.js +212 -0
  75. package/file-upload/exceptions/file-upload.exception.d.ts +57 -0
  76. package/file-upload/exceptions/file-upload.exception.js +120 -0
  77. package/file-upload/exceptions/index.d.ts +1 -0
  78. package/file-upload/exceptions/index.js +17 -0
  79. package/file-upload/file-upload.module.d.ts +89 -0
  80. package/file-upload/file-upload.module.js +264 -0
  81. package/file-upload/index.d.ts +26 -0
  82. package/file-upload/index.js +59 -0
  83. package/file-upload/interceptors/file-upload.interceptor.d.ts +48 -0
  84. package/file-upload/interceptors/file-upload.interceptor.js +434 -0
  85. package/file-upload/interceptors/index.d.ts +1 -0
  86. package/file-upload/interceptors/index.js +17 -0
  87. package/file-upload/interfaces/custom-file-type.interface.d.ts +72 -0
  88. package/file-upload/interfaces/custom-file-type.interface.js +2 -0
  89. package/file-upload/interfaces/file-buffer.interface.d.ts +72 -0
  90. package/file-upload/interfaces/file-buffer.interface.js +2 -0
  91. package/file-upload/interfaces/file-entity.interface.d.ts +142 -0
  92. package/file-upload/interfaces/file-entity.interface.js +28 -0
  93. package/file-upload/interfaces/file-metadata.interface.d.ts +21 -0
  94. package/file-upload/interfaces/file-metadata.interface.js +2 -0
  95. package/file-upload/interfaces/file-upload-options.interface.d.ts +117 -0
  96. package/file-upload/interfaces/file-upload-options.interface.js +2 -0
  97. package/file-upload/interfaces/index.d.ts +7 -0
  98. package/file-upload/interfaces/index.js +24 -0
  99. package/file-upload/interfaces/storage-provider.interface.d.ts +239 -0
  100. package/file-upload/interfaces/storage-provider.interface.js +2 -0
  101. package/file-upload/interfaces/upload-options.interface.d.ts +19 -0
  102. package/file-upload/interfaces/upload-options.interface.js +2 -0
  103. package/file-upload/providers/index.d.ts +2 -0
  104. package/file-upload/providers/index.js +18 -0
  105. package/file-upload/providers/local-storage.provider.d.ts +98 -0
  106. package/file-upload/providers/local-storage.provider.js +484 -0
  107. package/file-upload/providers/s3-storage.provider.d.ts +87 -0
  108. package/file-upload/providers/s3-storage.provider.js +455 -0
  109. package/file-upload/services/file-signature-validator.service.d.ts +118 -0
  110. package/file-upload/services/file-signature-validator.service.js +376 -0
  111. package/file-upload/services/file.service.d.ts +190 -0
  112. package/file-upload/services/file.service.js +609 -0
  113. package/file-upload/services/index.d.ts +4 -0
  114. package/file-upload/services/index.js +20 -0
  115. package/file-upload/services/malicious-file-detector.service.d.ts +274 -0
  116. package/file-upload/services/malicious-file-detector.service.js +1035 -0
  117. package/file-upload/services/mime-registry.service.d.ts +47 -0
  118. package/file-upload/services/mime-registry.service.js +167 -0
  119. package/file-upload/utils/checksum.util.d.ts +28 -0
  120. package/file-upload/utils/checksum.util.js +65 -0
  121. package/file-upload/utils/dynamic-import.util.d.ts +50 -0
  122. package/file-upload/utils/dynamic-import.util.js +144 -0
  123. package/file-upload/utils/filename.util.d.ts +59 -0
  124. package/file-upload/utils/filename.util.js +184 -0
  125. package/file-upload/utils/filepath.util.d.ts +70 -0
  126. package/file-upload/utils/filepath.util.js +152 -0
  127. package/file-upload/utils/index.d.ts +4 -0
  128. package/file-upload/utils/index.js +20 -0
  129. package/http-client/http-client.module.js +1 -5
  130. package/index.d.ts +3 -1
  131. package/index.js +4 -1
  132. package/package.json +4 -5
  133. package/redis-lock/lock-heartbeat.service.d.ts +2 -2
  134. package/redis-lock/lock-heartbeat.service.js +4 -4
  135. package/redis-lock/redis-lock.service.d.ts +18 -0
  136. package/redis-lock/redis-lock.service.js +38 -8
  137. package/setup/bootstrap.setup.d.ts +1 -0
  138. package/setup/bootstrap.setup.js +1 -0
  139. package/setup/schedule.decorator.js +18 -8
  140. package/shared/index.d.ts +1 -1
  141. package/shared/index.js +1 -1
  142. package/shared/{serviceRegistryModule.js → service-registry.module.js} +9 -16
  143. package/shared/services/index.d.ts +0 -1
  144. package/shared/services/index.js +0 -1
  145. package/transaction/__tests__/mocks.d.ts +9 -0
  146. package/transaction/__tests__/mocks.js +33 -0
  147. package/transaction/base-service-transaction.d.ts +99 -0
  148. package/transaction/base-service-transaction.js +286 -0
  149. package/transaction/cls-compatibility.service.d.ts +55 -0
  150. package/transaction/cls-compatibility.service.js +127 -0
  151. package/transaction/data-source-registry.d.ts +91 -0
  152. package/transaction/data-source-registry.js +349 -0
  153. package/transaction/database-adapter.d.ts +44 -0
  154. package/transaction/database-adapter.js +240 -0
  155. package/transaction/decorators/entity-datasource.decorator.d.ts +62 -0
  156. package/transaction/decorators/entity-datasource.decorator.js +105 -0
  157. package/transaction/index.d.ts +14 -0
  158. package/transaction/index.js +57 -0
  159. package/transaction/logging-transactional.interceptor.d.ts +18 -0
  160. package/transaction/logging-transactional.interceptor.js +163 -0
  161. package/transaction/transaction-context.service.d.ts +137 -0
  162. package/transaction/transaction-context.service.js +411 -0
  163. package/transaction/transaction-manager.d.ts +230 -0
  164. package/transaction/transaction-manager.js +1001 -0
  165. package/transaction/transaction-synchronization.d.ts +171 -0
  166. package/transaction/transaction-synchronization.js +380 -0
  167. package/transaction/transaction.errors.d.ts +91 -0
  168. package/transaction/transaction.errors.js +206 -0
  169. package/transaction/transaction.module.d.ts +30 -0
  170. package/transaction/transaction.module.js +98 -0
  171. package/transaction/transactional.decorator.d.ts +82 -0
  172. package/transaction/transactional.decorator.js +319 -0
  173. package/transaction/typeorm-module-wrapper.d.ts +96 -0
  174. package/transaction/typeorm-module-wrapper.js +197 -0
  175. package/validators/file-mimetype.validator.d.ts +0 -2
  176. package/validators/file-mimetype.validator.js +4 -6
  177. package/validators/is-exists.validator.d.ts +2 -5
  178. package/validators/is-exists.validator.js +4 -6
  179. package/validators/is-unique.validator.d.ts +2 -5
  180. package/validators/is-unique.validator.js +6 -11
  181. package/shared/services/validator.service.d.ts +0 -3
  182. package/shared/services/validator.service.js +0 -20
  183. /package/shared/{serviceRegistryModule.d.ts → service-registry.module.d.ts} +0 -0
@@ -0,0 +1,57 @@
1
+ import { HttpException, HttpStatus } from '@nestjs/common';
2
+ /**
3
+ * 文件上传基础异常类
4
+ */
5
+ export declare class FileUploadException extends HttpException {
6
+ readonly code: string;
7
+ readonly details?: any;
8
+ constructor(message: string, code: string, details?: any, status?: HttpStatus);
9
+ }
10
+ /**
11
+ * 文件大小超限异常
12
+ */
13
+ export declare class FileSizeExceededException extends FileUploadException {
14
+ constructor(actualSize: number, maxSize: number);
15
+ }
16
+ /**
17
+ * 文件类型不允许异常
18
+ */
19
+ export declare class FileTypeNotAllowedException extends FileUploadException {
20
+ constructor(mimeType: string, allowedTypes: string[]);
21
+ }
22
+ /**
23
+ * 文件扩展名不允许异常
24
+ */
25
+ export declare class FileExtensionNotAllowedException extends FileUploadException {
26
+ constructor(extension: string, allowedExtensions: string[]);
27
+ }
28
+ /**
29
+ * 文件签名不匹配异常
30
+ */
31
+ export declare class FileSignatureMismatchException extends FileUploadException {
32
+ constructor(error: string, reportedMime: string, detectedMime?: string);
33
+ }
34
+ /**
35
+ * 文件损坏异常
36
+ */
37
+ export declare class CorruptedFileException extends FileUploadException {
38
+ constructor(mimeType: string, errors: string[]);
39
+ }
40
+ /**
41
+ * 恶意文件异常
42
+ */
43
+ export declare class MaliciousFileException extends FileUploadException {
44
+ constructor(threats: string[]);
45
+ }
46
+ /**
47
+ * 存储异常
48
+ */
49
+ export declare class StorageException extends FileUploadException {
50
+ constructor(operation: string, error: Error);
51
+ }
52
+ /**
53
+ * 无效文件名异常
54
+ */
55
+ export declare class InvalidFilenameException extends FileUploadException {
56
+ constructor(filename: string);
57
+ }
@@ -0,0 +1,120 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.InvalidFilenameException = exports.StorageException = exports.MaliciousFileException = exports.CorruptedFileException = exports.FileSignatureMismatchException = exports.FileExtensionNotAllowedException = exports.FileTypeNotAllowedException = exports.FileSizeExceededException = exports.FileUploadException = void 0;
4
+ const common_1 = require("@nestjs/common");
5
+ /**
6
+ * 文件上传基础异常类
7
+ */
8
+ class FileUploadException extends common_1.HttpException {
9
+ constructor(message, code, details, status = common_1.HttpStatus.BAD_REQUEST) {
10
+ super({
11
+ message,
12
+ code,
13
+ details,
14
+ timestamp: new Date().toISOString(),
15
+ }, status);
16
+ this.code = code;
17
+ this.details = details;
18
+ }
19
+ }
20
+ exports.FileUploadException = FileUploadException;
21
+ /**
22
+ * 文件大小超限异常
23
+ */
24
+ class FileSizeExceededException extends FileUploadException {
25
+ constructor(actualSize, maxSize) {
26
+ const actualSizeMB = Math.round((actualSize / 1024 / 1024) * 100) / 100;
27
+ const maxSizeMB = Math.round((maxSize / 1024 / 1024) * 100) / 100;
28
+ super(`File size ${actualSizeMB}MB exceeds maximum allowed size ${maxSizeMB}MB`, 'FILE_SIZE_EXCEEDED', {
29
+ actualSize,
30
+ maxSize,
31
+ actualSizeMB,
32
+ maxSizeMB,
33
+ });
34
+ }
35
+ }
36
+ exports.FileSizeExceededException = FileSizeExceededException;
37
+ /**
38
+ * 文件类型不允许异常
39
+ */
40
+ class FileTypeNotAllowedException extends FileUploadException {
41
+ constructor(mimeType, allowedTypes) {
42
+ super(`File type '${mimeType}' is not allowed`, 'FILE_TYPE_NOT_ALLOWED', {
43
+ mimeType,
44
+ allowedTypes,
45
+ });
46
+ }
47
+ }
48
+ exports.FileTypeNotAllowedException = FileTypeNotAllowedException;
49
+ /**
50
+ * 文件扩展名不允许异常
51
+ */
52
+ class FileExtensionNotAllowedException extends FileUploadException {
53
+ constructor(extension, allowedExtensions) {
54
+ super(`File extension '${extension}' is not allowed`, 'FILE_EXTENSION_NOT_ALLOWED', {
55
+ extension,
56
+ allowedExtensions,
57
+ });
58
+ }
59
+ }
60
+ exports.FileExtensionNotAllowedException = FileExtensionNotAllowedException;
61
+ /**
62
+ * 文件签名不匹配异常
63
+ */
64
+ class FileSignatureMismatchException extends FileUploadException {
65
+ constructor(error, reportedMime, detectedMime) {
66
+ super(`File signature verification failed: ${error}`, 'FILE_SIGNATURE_MISMATCH', {
67
+ error,
68
+ reportedMime,
69
+ detectedMime,
70
+ }, common_1.HttpStatus.UNPROCESSABLE_ENTITY);
71
+ }
72
+ }
73
+ exports.FileSignatureMismatchException = FileSignatureMismatchException;
74
+ /**
75
+ * 文件损坏异常
76
+ */
77
+ class CorruptedFileException extends FileUploadException {
78
+ constructor(mimeType, errors) {
79
+ super('File appears to be corrupted or invalid', 'CORRUPTED_FILE', {
80
+ mimeType,
81
+ errors,
82
+ }, common_1.HttpStatus.UNPROCESSABLE_ENTITY);
83
+ }
84
+ }
85
+ exports.CorruptedFileException = CorruptedFileException;
86
+ /**
87
+ * 恶意文件异常
88
+ */
89
+ class MaliciousFileException extends FileUploadException {
90
+ constructor(threats) {
91
+ super('Potentially malicious file detected', 'MALICIOUS_FILE', {
92
+ threats,
93
+ }, common_1.HttpStatus.FORBIDDEN);
94
+ }
95
+ }
96
+ exports.MaliciousFileException = MaliciousFileException;
97
+ /**
98
+ * 存储异常
99
+ */
100
+ class StorageException extends FileUploadException {
101
+ constructor(operation, error) {
102
+ super(`Storage operation failed: ${operation}`, 'STORAGE_ERROR', Object.assign({ operation, error: error.message }, (process.env.NODE_ENV !== 'prod' &&
103
+ process.env.NODE_ENV !== 'prod' && {
104
+ stack: error.stack,
105
+ name: error.name,
106
+ })), common_1.HttpStatus.INTERNAL_SERVER_ERROR);
107
+ }
108
+ }
109
+ exports.StorageException = StorageException;
110
+ /**
111
+ * 无效文件名异常
112
+ */
113
+ class InvalidFilenameException extends FileUploadException {
114
+ constructor(filename) {
115
+ super('Invalid or dangerous filename', 'INVALID_FILENAME', {
116
+ filename,
117
+ });
118
+ }
119
+ }
120
+ exports.InvalidFilenameException = InvalidFilenameException;
@@ -0,0 +1 @@
1
+ export * from './file-upload.exception';
@@ -0,0 +1,17 @@
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("./file-upload.exception"), exports);
@@ -0,0 +1,89 @@
1
+ import { DynamicModule } from '@nestjs/common';
2
+ import { IFileProcessor } from './interfaces/file-upload-options.interface';
3
+ import { LocalStorageOptions, S3StorageOptions } from './interfaces/storage-provider.interface';
4
+ import { CustomFileTypes } from './interfaces/custom-file-type.interface';
5
+ import { MaliciousDetectorOptions } from './services/malicious-file-detector.service';
6
+ /**
7
+ * 文件上传模块配置选项(增强版)
8
+ */
9
+ export interface FileUploadModuleOptions {
10
+ /** 默认配置 */
11
+ defaults?: {
12
+ maxSize?: number;
13
+ types?: string[];
14
+ scan?: boolean | 'auto';
15
+ };
16
+ /** 安全配置 */
17
+ security?: {
18
+ /** 病毒扫描配置 */
19
+ virusScan?: {
20
+ enabled: boolean;
21
+ endpoint?: string;
22
+ };
23
+ /** 速率限制 */
24
+ rateLimit?: {
25
+ max: number;
26
+ window: number;
27
+ };
28
+ };
29
+ /** 存储配置 */
30
+ storage?: {
31
+ /** 默认存储提供者 */
32
+ default?: 'local' | 's3' | 'oss' | 'minio';
33
+ /** 本地存储配置 */
34
+ local?: LocalStorageOptions;
35
+ /** S3 存储配置 */
36
+ s3?: S3StorageOptions;
37
+ /** OSS 存储配置 (待实现) */
38
+ oss?: any;
39
+ /** MinIO 存储配置 (待实现) */
40
+ minio?: any;
41
+ };
42
+ /** 自定义文件类型 */
43
+ customFileTypes?: CustomFileTypes;
44
+ /** 是否启用文件签名验证(默认 true) */
45
+ validateSignature?: boolean;
46
+ /** 签名验证配置 */
47
+ signatureValidation?: {
48
+ maxReadBytes?: number;
49
+ strict?: boolean;
50
+ tolerance?: number;
51
+ };
52
+ /** 恶意文件检测配置(增强) */
53
+ maliciousDetection?: MaliciousDetectorOptions;
54
+ /** TypeORM 相关配置 */
55
+ database?: {
56
+ /** 是否自动创建表(默认 true) */
57
+ autoCreateTable?: boolean;
58
+ /** 数据库模式 */
59
+ schema?: string;
60
+ /** 表前缀 */
61
+ tablePrefix?: string;
62
+ };
63
+ /** 自定义处理器 */
64
+ processors?: Array<new (...args: any[]) => IFileProcessor>;
65
+ }
66
+ /**
67
+ * 异步配置选项
68
+ */
69
+ export interface FileUploadModuleAsyncOptions {
70
+ useFactory: (...args: any[]) => Promise<FileUploadModuleOptions> | FileUploadModuleOptions;
71
+ inject?: any[];
72
+ }
73
+ /**
74
+ * 文件上传模块(增强版)
75
+ */
76
+ export declare class FileUploadModule {
77
+ /**
78
+ * 同步配置模块
79
+ */
80
+ static forRoot(options?: FileUploadModuleOptions): DynamicModule;
81
+ /**
82
+ * 异步配置模块
83
+ */
84
+ static forRootAsync(asyncOptions: FileUploadModuleAsyncOptions): DynamicModule;
85
+ /**
86
+ * 创建存储提供者
87
+ */
88
+ private static createStorageProviders;
89
+ }
@@ -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';