@flusys/nestjs-storage 7.1.0 → 8.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/config/index.d.ts +3 -3
- package/controllers/file-manager.controller.d.ts +4 -4
- package/controllers/folder.controller.d.ts +2 -2
- package/controllers/index.d.ts +4 -4
- package/controllers/storage-config.controller.d.ts +2 -2
- package/controllers/upload.controller.d.ts +3 -3
- package/docs/index.d.ts +1 -1
- package/docs/storage-swagger.config.d.ts +2 -2
- package/dtos/index.d.ts +4 -4
- package/entities/file-manager-with-company.entity.d.ts +2 -2
- package/entities/file-manager.entity.d.ts +1 -1
- package/entities/folder-with-company.entity.d.ts +1 -1
- package/entities/index.d.ts +15 -15
- package/entities/storage-config-with-company.entity.d.ts +1 -1
- package/enums/index.d.ts +1 -1
- package/fesm/493.js +2768 -0
- package/fesm/537.js +1157 -0
- package/fesm/562.js +786 -0
- package/fesm/{providers/azure-provider.optional.js → chunks/190.js} +33 -30
- package/fesm/chunks/252.js +12 -0
- package/fesm/chunks/327.js +12 -0
- package/fesm/chunks/385.js +12 -0
- package/fesm/{providers/s3-provider.optional.js → chunks/591.js} +37 -34
- package/fesm/chunks/746.js +12 -0
- package/fesm/chunks/798.js +12 -0
- package/fesm/{providers/sftp-provider.optional.js → chunks/918.js} +35 -31
- package/fesm/config/index.js +119 -3
- package/fesm/controllers/index.js +16 -4
- package/fesm/docs/index.js +206 -1
- package/fesm/dtos/index.js +879 -4
- package/fesm/entities/index.js +463 -18
- package/fesm/enums/index.js +36 -1
- package/fesm/index.js +398 -12
- package/fesm/interfaces/index.js +19 -5
- package/fesm/modules/index.js +16 -1
- package/fesm/providers/index.js +364 -3
- package/fesm/runtime.js +252 -0
- package/fesm/services/index.js +16 -6
- package/fesm/utils/index.js +149 -1
- package/index.d.ts +11 -11
- package/interfaces/file-manager.interface.d.ts +1 -1
- package/interfaces/folder.interface.d.ts +1 -1
- package/interfaces/index.d.ts +5 -5
- package/interfaces/storage-config.interface.d.ts +1 -1
- package/interfaces/storage-module-options.interface.d.ts +3 -3
- package/interfaces/storage-provider.interface.d.ts +1 -1
- package/middlewares/file-serve.middleware.d.ts +4 -3
- package/middlewares/index.d.ts +1 -1
- package/modules/index.d.ts +1 -1
- package/modules/storage.module.d.ts +2 -2
- package/package.json +30 -41
- package/providers/azure-provider.optional.d.ts +2 -2
- package/providers/index.d.ts +3 -3
- package/providers/local-provider.d.ts +2 -2
- package/providers/s3-provider.optional.d.ts +2 -2
- package/providers/sftp-provider.optional.d.ts +2 -2
- package/providers/storage-factory.service.d.ts +3 -3
- package/providers/storage-provider.registry.d.ts +2 -2
- package/services/file-manager.service.d.ts +9 -8
- package/services/folder.service.d.ts +6 -6
- package/services/index.d.ts +6 -6
- package/services/storage-config.service.d.ts +3 -3
- package/services/storage-datasource.provider.d.ts +3 -3
- package/services/storage-provider-config.service.d.ts +7 -7
- package/services/upload.service.d.ts +6 -6
- package/utils/image-compressor.util.d.ts +1 -1
- package/utils/index.d.ts +1 -1
- package/cjs/config/event-actions.js +0 -34
- package/cjs/config/index.js +0 -20
- package/cjs/config/message-keys.js +0 -46
- package/cjs/config/storage.constants.js +0 -28
- package/cjs/controllers/file-manager.controller.js +0 -152
- package/cjs/controllers/file-manager.controller.spec.js +0 -135
- package/cjs/controllers/folder.controller.js +0 -102
- package/cjs/controllers/folder.controller.spec.js +0 -86
- package/cjs/controllers/index.js +0 -21
- package/cjs/controllers/storage-config.controller.js +0 -102
- package/cjs/controllers/storage-config.controller.spec.js +0 -85
- package/cjs/controllers/upload.controller.js +0 -234
- package/cjs/controllers/upload.controller.spec.js +0 -132
- package/cjs/docs/index.js +0 -11
- package/cjs/docs/storage-swagger.config.js +0 -188
- package/cjs/docs/storage-swagger.config.spec.js +0 -72
- package/cjs/dtos/file-manager.dto.js +0 -327
- package/cjs/dtos/folder.dto.js +0 -105
- package/cjs/dtos/index.js +0 -21
- package/cjs/dtos/storage-config.dto.js +0 -170
- package/cjs/dtos/upload.dto.js +0 -272
- package/cjs/entities/file-manager-with-company.entity.js +0 -61
- package/cjs/entities/file-manager.entity.js +0 -122
- package/cjs/entities/folder-with-company.entity.js +0 -55
- package/cjs/entities/folder.entity.js +0 -64
- package/cjs/entities/index.js +0 -63
- package/cjs/entities/index.spec.js +0 -18
- package/cjs/entities/storage-config-with-company.entity.js +0 -51
- package/cjs/entities/storage-config.entity.js +0 -96
- package/cjs/enums/file-location.enum.js +0 -17
- package/cjs/enums/index.js +0 -18
- package/cjs/index.js +0 -29
- package/cjs/interfaces/file-manager.interface.js +0 -4
- package/cjs/interfaces/folder.interface.js +0 -4
- package/cjs/interfaces/index.js +0 -22
- package/cjs/interfaces/storage-config.interface.js +0 -4
- package/cjs/interfaces/storage-module-options.interface.js +0 -4
- package/cjs/interfaces/storage-provider.interface.js +0 -4
- package/cjs/middlewares/file-serve.middleware.js +0 -241
- package/cjs/middlewares/file-serve.middleware.spec.js +0 -211
- package/cjs/middlewares/index.js +0 -18
- package/cjs/modules/index.js +0 -18
- package/cjs/modules/storage.module.js +0 -165
- package/cjs/modules/storage.module.spec.js +0 -184
- package/cjs/providers/azure-provider.optional.js +0 -155
- package/cjs/providers/azure-provider.optional.spec.js +0 -228
- package/cjs/providers/index.js +0 -26
- package/cjs/providers/local-provider.js +0 -230
- package/cjs/providers/local-provider.spec.js +0 -239
- package/cjs/providers/s3-provider.optional.js +0 -175
- package/cjs/providers/s3-provider.optional.spec.js +0 -243
- package/cjs/providers/sftp-provider.optional.js +0 -203
- package/cjs/providers/sftp-provider.optional.spec.js +0 -217
- package/cjs/providers/storage-factory.service.js +0 -175
- package/cjs/providers/storage-factory.service.spec.js +0 -253
- package/cjs/providers/storage-provider.registry.js +0 -41
- package/cjs/providers/storage-provider.registry.spec.js +0 -67
- package/cjs/services/file-manager.service.js +0 -387
- package/cjs/services/file-manager.service.spec.js +0 -580
- package/cjs/services/folder.service.js +0 -101
- package/cjs/services/folder.service.spec.js +0 -167
- package/cjs/services/index.js +0 -23
- package/cjs/services/storage-config.service.js +0 -129
- package/cjs/services/storage-config.service.spec.js +0 -257
- package/cjs/services/storage-datasource.provider.js +0 -137
- package/cjs/services/storage-datasource.provider.spec.js +0 -217
- package/cjs/services/storage-provider-config.service.js +0 -171
- package/cjs/services/storage-provider-config.service.spec.js +0 -265
- package/cjs/services/upload.service.js +0 -376
- package/cjs/services/upload.service.spec.js +0 -426
- package/cjs/utils/file-validator.util.js +0 -440
- package/cjs/utils/file-validator.util.spec.js +0 -259
- package/cjs/utils/image-compressor.util.js +0 -162
- package/cjs/utils/image-compressor.util.spec.js +0 -166
- package/cjs/utils/index.js +0 -18
- package/fesm/config/event-actions.js +0 -13
- package/fesm/config/message-keys.js +0 -22
- package/fesm/config/storage.constants.js +0 -7
- package/fesm/controllers/file-manager.controller.js +0 -142
- package/fesm/controllers/file-manager.controller.spec.js +0 -131
- package/fesm/controllers/folder.controller.js +0 -92
- package/fesm/controllers/folder.controller.spec.js +0 -82
- package/fesm/controllers/storage-config.controller.js +0 -92
- package/fesm/controllers/storage-config.controller.spec.js +0 -81
- package/fesm/controllers/upload.controller.js +0 -224
- package/fesm/controllers/upload.controller.spec.js +0 -128
- package/fesm/docs/storage-swagger.config.js +0 -181
- package/fesm/docs/storage-swagger.config.spec.js +0 -68
- package/fesm/dtos/file-manager.dto.js +0 -300
- package/fesm/dtos/folder.dto.js +0 -84
- package/fesm/dtos/storage-config.dto.js +0 -149
- package/fesm/dtos/upload.dto.js +0 -245
- package/fesm/entities/file-manager-with-company.entity.js +0 -51
- package/fesm/entities/file-manager.entity.js +0 -112
- package/fesm/entities/folder-with-company.entity.js +0 -45
- package/fesm/entities/folder.entity.js +0 -54
- package/fesm/entities/index.spec.js +0 -14
- package/fesm/entities/storage-config-with-company.entity.js +0 -41
- package/fesm/entities/storage-config.entity.js +0 -86
- package/fesm/enums/file-location.enum.js +0 -7
- package/fesm/interfaces/file-manager.interface.js +0 -1
- package/fesm/interfaces/folder.interface.js +0 -1
- package/fesm/interfaces/storage-config.interface.js +0 -1
- package/fesm/interfaces/storage-module-options.interface.js +0 -3
- package/fesm/interfaces/storage-provider.interface.js +0 -4
- package/fesm/middlewares/file-serve.middleware.js +0 -190
- package/fesm/middlewares/file-serve.middleware.spec.js +0 -207
- package/fesm/middlewares/index.js +0 -1
- package/fesm/modules/storage.module.js +0 -156
- package/fesm/modules/storage.module.spec.js +0 -180
- package/fesm/providers/azure-provider.optional.spec.js +0 -224
- package/fesm/providers/local-provider.js +0 -182
- package/fesm/providers/local-provider.spec.js +0 -194
- package/fesm/providers/s3-provider.optional.spec.js +0 -239
- package/fesm/providers/sftp-provider.optional.spec.js +0 -213
- package/fesm/providers/storage-factory.service.js +0 -124
- package/fesm/providers/storage-factory.service.spec.js +0 -249
- package/fesm/providers/storage-provider.registry.js +0 -34
- package/fesm/providers/storage-provider.registry.spec.js +0 -63
- package/fesm/services/file-manager.service.js +0 -336
- package/fesm/services/file-manager.service.spec.js +0 -576
- package/fesm/services/folder.service.js +0 -91
- package/fesm/services/folder.service.spec.js +0 -163
- package/fesm/services/storage-config.service.js +0 -119
- package/fesm/services/storage-config.service.spec.js +0 -253
- package/fesm/services/storage-datasource.provider.js +0 -86
- package/fesm/services/storage-datasource.provider.spec.js +0 -172
- package/fesm/services/storage-provider-config.service.js +0 -161
- package/fesm/services/storage-provider-config.service.spec.js +0 -261
- package/fesm/services/upload.service.js +0 -366
- package/fesm/services/upload.service.spec.js +0 -422
- package/fesm/utils/file-validator.util.js +0 -433
- package/fesm/utils/file-validator.util.spec.js +0 -255
- package/fesm/utils/image-compressor.util.js +0 -114
- package/fesm/utils/image-compressor.util.spec.js +0 -162
package/fesm/493.js
ADDED
|
@@ -0,0 +1,2768 @@
|
|
|
1
|
+
import { Identity } from "@flusys/nestjs-shared/entities";
|
|
2
|
+
import * as __rspack_external__flusys_nestjs_shared_393d2cae from "@flusys/nestjs-shared";
|
|
3
|
+
import * as __rspack_external__flusys_nestjs_shared_classes_6076a329 from "@flusys/nestjs-shared/classes";
|
|
4
|
+
import * as __rspack_external__flusys_nestjs_shared_constants_81f33d5b from "@flusys/nestjs-shared/constants";
|
|
5
|
+
import * as __rspack_external__flusys_nestjs_shared_modules_24702bee from "@flusys/nestjs-shared/modules";
|
|
6
|
+
import * as __rspack_external__flusys_nestjs_shared_utils_9125c1f1 from "@flusys/nestjs-shared/utils";
|
|
7
|
+
import * as __rspack_external__nestjs_common_a04939da from "@nestjs/common";
|
|
8
|
+
import * as __rspack_external__nestjs_swagger_7cd450b5 from "@nestjs/swagger";
|
|
9
|
+
import * as __rspack_external_class_transformer_c5a479fb from "class-transformer";
|
|
10
|
+
import * as __rspack_external_class_validator_7b99ef4d from "class-validator";
|
|
11
|
+
import * as __rspack_external_typeorm from "typeorm";
|
|
12
|
+
import * as __rspack_external__nestjs_core_d7b00a1a from "@nestjs/core";
|
|
13
|
+
import * as __rspack_external_crypto from "crypto";
|
|
14
|
+
export const __rspack_esm_id = 493;
|
|
15
|
+
export const __rspack_esm_ids = [493];
|
|
16
|
+
export const __webpack_modules__ = {
|
|
17
|
+
884(__unused_rspack_module, __webpack_exports__, __webpack_require__) {
|
|
18
|
+
/**
|
|
19
|
+
* Domain event actions published by the storage module, alongside the CRUD
|
|
20
|
+
* lifecycle actions every ApiService emits.
|
|
21
|
+
*/ const STORAGE_EVENT_ACTIONS = {
|
|
22
|
+
UPLOADED: 'uploaded',
|
|
23
|
+
REMOVED: 'removed'
|
|
24
|
+
};
|
|
25
|
+
/** Every entity the storage module publishes under, ApiService backed or not */ const STORAGE_EVENT_ENTITIES = {
|
|
26
|
+
FILE: 'file_manager',
|
|
27
|
+
FOLDER: 'folder',
|
|
28
|
+
STORAGE_CONFIG: 'storageConfig'
|
|
29
|
+
};
|
|
30
|
+
const STORAGE_EVENT_MODULE = 'storage';
|
|
31
|
+
|
|
32
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
33
|
+
}, {
|
|
34
|
+
fR: STORAGE_EVENT_ENTITIES,
|
|
35
|
+
hw: STORAGE_EVENT_ACTIONS,
|
|
36
|
+
qh: STORAGE_EVENT_MODULE
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
},
|
|
41
|
+
450(__unused_rspack_module, __webpack_exports__, __webpack_require__) {
|
|
42
|
+
// ==================== STORAGE MODULE MESSAGE KEYS ====================
|
|
43
|
+
const FILE_MESSAGES = {
|
|
44
|
+
GET_ALL_SUCCESS: 'file.get.all.success',
|
|
45
|
+
DELETE_SUCCESS: 'file.delete.success',
|
|
46
|
+
NOT_FOUND: 'file.not.found'
|
|
47
|
+
};
|
|
48
|
+
const STORAGE_CONFIG_MESSAGES = {
|
|
49
|
+
DEFAULT_DELETE_FORBIDDEN: 'storage.config.default.delete.forbidden'
|
|
50
|
+
};
|
|
51
|
+
const FOLDER_MESSAGES = {
|
|
52
|
+
NOT_FOUND: 'folder.not.found'
|
|
53
|
+
};
|
|
54
|
+
const UPLOAD_MESSAGES = {
|
|
55
|
+
SUCCESS: 'upload.success',
|
|
56
|
+
MANY_SUCCESS: 'upload.many.success',
|
|
57
|
+
FILE_TOO_LARGE: 'upload.file.too.large',
|
|
58
|
+
INVALID_TYPE: 'upload.invalid.type',
|
|
59
|
+
NO_FILES_PROVIDED: 'upload.no.files.provided',
|
|
60
|
+
NO_FILE_PATH: 'upload.no.file.path',
|
|
61
|
+
INVALID_FILE_PATH: 'upload.invalid.file.path',
|
|
62
|
+
CONFIG_NOT_FOUND: 'upload.config.not.found'
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
66
|
+
}, {
|
|
67
|
+
Ee: FOLDER_MESSAGES,
|
|
68
|
+
Y8: STORAGE_CONFIG_MESSAGES,
|
|
69
|
+
dS: UPLOAD_MESSAGES,
|
|
70
|
+
uA: FILE_MESSAGES
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
},
|
|
75
|
+
188(__unused_rspack_module, __webpack_exports__, __webpack_require__) {
|
|
76
|
+
/**
|
|
77
|
+
* Storage Module Constants
|
|
78
|
+
*/ const STORAGE_MODULE_OPTIONS = 'STORAGE_MODULE_OPTIONS';
|
|
79
|
+
const DEFAULT_MAX_FILE_SIZE = 100 * 1024 * 1024; // 100MB
|
|
80
|
+
const DEFAULT_ALLOWED_FILE_TYPES = [
|
|
81
|
+
'*/*'
|
|
82
|
+
]; // All file types
|
|
83
|
+
|
|
84
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
85
|
+
}, {
|
|
86
|
+
A_: DEFAULT_ALLOWED_FILE_TYPES,
|
|
87
|
+
Sj: DEFAULT_MAX_FILE_SIZE,
|
|
88
|
+
k0: STORAGE_MODULE_OPTIONS
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
},
|
|
93
|
+
322(__unused_rspack_module, __webpack_exports__, __webpack_require__) {
|
|
94
|
+
/* import */ var _nestjs_swagger__rspack_import_0 = __webpack_require__(176);
|
|
95
|
+
/* import */ var class_transformer__rspack_import_1 = __webpack_require__(812);
|
|
96
|
+
/* import */ var class_validator__rspack_import_2 = __webpack_require__(421);
|
|
97
|
+
function _ts_decorate(decorators, target, key, desc) {
|
|
98
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
99
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
|
|
100
|
+
r = Reflect.decorate(decorators, target, key, desc);
|
|
101
|
+
} else {
|
|
102
|
+
for(var i = decorators.length - 1; i >= 0; i--){
|
|
103
|
+
if (d = decorators[i]) {
|
|
104
|
+
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
109
|
+
}
|
|
110
|
+
function _ts_metadata(metadataKey, metadataValue) {
|
|
111
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
|
|
112
|
+
return Reflect.metadata(metadataKey, metadataValue);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
var ImageFormat = /*#__PURE__*/ function(ImageFormat) {
|
|
119
|
+
ImageFormat["ORIGINAL"] = "original";
|
|
120
|
+
ImageFormat["JPEG"] = "jpeg";
|
|
121
|
+
ImageFormat["PNG"] = "png";
|
|
122
|
+
ImageFormat["WEBP"] = "webp";
|
|
123
|
+
return ImageFormat;
|
|
124
|
+
}({});
|
|
125
|
+
class DeleteSingleFileDto {
|
|
126
|
+
key;
|
|
127
|
+
storageConfigId;
|
|
128
|
+
}
|
|
129
|
+
_ts_decorate([
|
|
130
|
+
(0,_nestjs_swagger__rspack_import_0.ApiProperty)({
|
|
131
|
+
description: 'Key of the file to delete',
|
|
132
|
+
example: '/uploads/some-path'
|
|
133
|
+
}),
|
|
134
|
+
(0,class_validator__rspack_import_2.IsNotEmpty)(),
|
|
135
|
+
(0,class_validator__rspack_import_2.IsString)(),
|
|
136
|
+
_ts_metadata("design:type", String)
|
|
137
|
+
], DeleteSingleFileDto.prototype, "key", void 0);
|
|
138
|
+
_ts_decorate([
|
|
139
|
+
(0,_nestjs_swagger__rspack_import_0.ApiPropertyOptional)({
|
|
140
|
+
description: 'Storage configuration ID',
|
|
141
|
+
example: '123e4567-e89b-12d3-a456-426614174000'
|
|
142
|
+
}),
|
|
143
|
+
(0,class_validator__rspack_import_2.IsOptional)(),
|
|
144
|
+
(0,class_validator__rspack_import_2.IsUUID)(),
|
|
145
|
+
_ts_metadata("design:type", String)
|
|
146
|
+
], DeleteSingleFileDto.prototype, "storageConfigId", void 0);
|
|
147
|
+
class DeleteMultipleFileDto {
|
|
148
|
+
keys;
|
|
149
|
+
storageConfigId;
|
|
150
|
+
}
|
|
151
|
+
_ts_decorate([
|
|
152
|
+
(0,_nestjs_swagger__rspack_import_0.ApiProperty)({
|
|
153
|
+
description: 'Array of file keys to delete',
|
|
154
|
+
example: [
|
|
155
|
+
'/uploads/file1',
|
|
156
|
+
'/uploads/file2'
|
|
157
|
+
],
|
|
158
|
+
type: [
|
|
159
|
+
String
|
|
160
|
+
]
|
|
161
|
+
}),
|
|
162
|
+
(0,class_validator__rspack_import_2.IsNotEmpty)(),
|
|
163
|
+
(0,class_validator__rspack_import_2.IsArray)(),
|
|
164
|
+
(0,class_validator__rspack_import_2.IsString)({
|
|
165
|
+
each: true
|
|
166
|
+
}),
|
|
167
|
+
_ts_metadata("design:type", Array)
|
|
168
|
+
], DeleteMultipleFileDto.prototype, "keys", void 0);
|
|
169
|
+
_ts_decorate([
|
|
170
|
+
(0,_nestjs_swagger__rspack_import_0.ApiPropertyOptional)({
|
|
171
|
+
description: 'Storage configuration ID',
|
|
172
|
+
example: '123e4567-e89b-12d3-a456-426614174000'
|
|
173
|
+
}),
|
|
174
|
+
(0,class_validator__rspack_import_2.IsOptional)(),
|
|
175
|
+
(0,class_validator__rspack_import_2.IsUUID)(),
|
|
176
|
+
_ts_metadata("design:type", String)
|
|
177
|
+
], DeleteMultipleFileDto.prototype, "storageConfigId", void 0);
|
|
178
|
+
class UploadOptionsDto {
|
|
179
|
+
storageConfigId;
|
|
180
|
+
folderPath;
|
|
181
|
+
maxWidth = 1280;
|
|
182
|
+
maxHeight = 1280;
|
|
183
|
+
quality = 85;
|
|
184
|
+
format = "original";
|
|
185
|
+
compress = true;
|
|
186
|
+
}
|
|
187
|
+
_ts_decorate([
|
|
188
|
+
(0,_nestjs_swagger__rspack_import_0.ApiPropertyOptional)({
|
|
189
|
+
description: 'Storage configuration ID',
|
|
190
|
+
example: '123e4567-e89b-12d3-a456-426614174000'
|
|
191
|
+
}),
|
|
192
|
+
(0,class_validator__rspack_import_2.IsOptional)(),
|
|
193
|
+
(0,class_validator__rspack_import_2.IsUUID)(),
|
|
194
|
+
_ts_metadata("design:type", String)
|
|
195
|
+
], UploadOptionsDto.prototype, "storageConfigId", void 0);
|
|
196
|
+
_ts_decorate([
|
|
197
|
+
(0,_nestjs_swagger__rspack_import_0.ApiPropertyOptional)({
|
|
198
|
+
description: 'Folder path for upload',
|
|
199
|
+
example: 'uploads/images'
|
|
200
|
+
}),
|
|
201
|
+
(0,class_validator__rspack_import_2.IsOptional)(),
|
|
202
|
+
(0,class_validator__rspack_import_2.Matches)(/^[a-zA-Z0-9-_/]*$/, {
|
|
203
|
+
message: 'folderPath can only contain letters, numbers, hyphens, underscores, and slashes.'
|
|
204
|
+
}),
|
|
205
|
+
_ts_metadata("design:type", String)
|
|
206
|
+
], UploadOptionsDto.prototype, "folderPath", void 0);
|
|
207
|
+
_ts_decorate([
|
|
208
|
+
(0,_nestjs_swagger__rspack_import_0.ApiPropertyOptional)({
|
|
209
|
+
description: 'Maximum width in pixels',
|
|
210
|
+
example: 1280,
|
|
211
|
+
minimum: 100,
|
|
212
|
+
maximum: 10000,
|
|
213
|
+
default: 1280
|
|
214
|
+
}),
|
|
215
|
+
(0,class_validator__rspack_import_2.IsOptional)(),
|
|
216
|
+
(0,class_transformer__rspack_import_1.Type)(()=>Number),
|
|
217
|
+
(0,class_validator__rspack_import_2.IsInt)(),
|
|
218
|
+
(0,class_validator__rspack_import_2.Min)(100),
|
|
219
|
+
(0,class_validator__rspack_import_2.Max)(10000),
|
|
220
|
+
_ts_metadata("design:type", Number)
|
|
221
|
+
], UploadOptionsDto.prototype, "maxWidth", void 0);
|
|
222
|
+
_ts_decorate([
|
|
223
|
+
(0,_nestjs_swagger__rspack_import_0.ApiPropertyOptional)({
|
|
224
|
+
description: 'Maximum height in pixels',
|
|
225
|
+
example: 1280,
|
|
226
|
+
minimum: 100,
|
|
227
|
+
maximum: 10000,
|
|
228
|
+
default: 1280
|
|
229
|
+
}),
|
|
230
|
+
(0,class_validator__rspack_import_2.IsOptional)(),
|
|
231
|
+
(0,class_transformer__rspack_import_1.Type)(()=>Number),
|
|
232
|
+
(0,class_validator__rspack_import_2.IsInt)(),
|
|
233
|
+
(0,class_validator__rspack_import_2.Min)(100),
|
|
234
|
+
(0,class_validator__rspack_import_2.Max)(10000),
|
|
235
|
+
_ts_metadata("design:type", Number)
|
|
236
|
+
], UploadOptionsDto.prototype, "maxHeight", void 0);
|
|
237
|
+
_ts_decorate([
|
|
238
|
+
(0,_nestjs_swagger__rspack_import_0.ApiPropertyOptional)({
|
|
239
|
+
description: 'Compression quality (1-100)',
|
|
240
|
+
example: 85,
|
|
241
|
+
minimum: 1,
|
|
242
|
+
maximum: 100,
|
|
243
|
+
default: 85
|
|
244
|
+
}),
|
|
245
|
+
(0,class_validator__rspack_import_2.IsOptional)(),
|
|
246
|
+
(0,class_transformer__rspack_import_1.Type)(()=>Number),
|
|
247
|
+
(0,class_validator__rspack_import_2.IsInt)(),
|
|
248
|
+
(0,class_validator__rspack_import_2.Min)(1),
|
|
249
|
+
(0,class_validator__rspack_import_2.Max)(100),
|
|
250
|
+
_ts_metadata("design:type", Number)
|
|
251
|
+
], UploadOptionsDto.prototype, "quality", void 0);
|
|
252
|
+
_ts_decorate([
|
|
253
|
+
(0,_nestjs_swagger__rspack_import_0.ApiPropertyOptional)({
|
|
254
|
+
description: 'Output image format',
|
|
255
|
+
enum: ImageFormat,
|
|
256
|
+
default: "original"
|
|
257
|
+
}),
|
|
258
|
+
(0,class_validator__rspack_import_2.IsOptional)(),
|
|
259
|
+
(0,class_validator__rspack_import_2.IsEnum)(ImageFormat),
|
|
260
|
+
_ts_metadata("design:type", String)
|
|
261
|
+
], UploadOptionsDto.prototype, "format", void 0);
|
|
262
|
+
_ts_decorate([
|
|
263
|
+
(0,_nestjs_swagger__rspack_import_0.ApiPropertyOptional)({
|
|
264
|
+
description: 'Whether to compress the image',
|
|
265
|
+
example: true,
|
|
266
|
+
default: true
|
|
267
|
+
}),
|
|
268
|
+
(0,class_validator__rspack_import_2.IsOptional)(),
|
|
269
|
+
(0,class_transformer__rspack_import_1.Type)(()=>Boolean),
|
|
270
|
+
(0,class_validator__rspack_import_2.IsBoolean)(),
|
|
271
|
+
_ts_metadata("design:type", Boolean)
|
|
272
|
+
], UploadOptionsDto.prototype, "compress", void 0);
|
|
273
|
+
class FileUploadResponsePayloadDto {
|
|
274
|
+
name;
|
|
275
|
+
contentType;
|
|
276
|
+
size;
|
|
277
|
+
key;
|
|
278
|
+
location;
|
|
279
|
+
storageConfigId;
|
|
280
|
+
}
|
|
281
|
+
_ts_decorate([
|
|
282
|
+
(0,class_transformer__rspack_import_1.Expose)(),
|
|
283
|
+
(0,_nestjs_swagger__rspack_import_0.ApiProperty)({
|
|
284
|
+
description: 'Original filename of the uploaded file',
|
|
285
|
+
example: 'profile-photo.jpg'
|
|
286
|
+
}),
|
|
287
|
+
_ts_metadata("design:type", String)
|
|
288
|
+
], FileUploadResponsePayloadDto.prototype, "name", void 0);
|
|
289
|
+
_ts_decorate([
|
|
290
|
+
(0,class_transformer__rspack_import_1.Expose)(),
|
|
291
|
+
(0,_nestjs_swagger__rspack_import_0.ApiProperty)({
|
|
292
|
+
description: 'MIME type of the uploaded file',
|
|
293
|
+
example: 'image/jpeg'
|
|
294
|
+
}),
|
|
295
|
+
_ts_metadata("design:type", String)
|
|
296
|
+
], FileUploadResponsePayloadDto.prototype, "contentType", void 0);
|
|
297
|
+
_ts_decorate([
|
|
298
|
+
(0,class_transformer__rspack_import_1.Expose)(),
|
|
299
|
+
(0,_nestjs_swagger__rspack_import_0.ApiProperty)({
|
|
300
|
+
description: 'File size in bytes',
|
|
301
|
+
example: 204800,
|
|
302
|
+
minimum: 0
|
|
303
|
+
}),
|
|
304
|
+
_ts_metadata("design:type", Number)
|
|
305
|
+
], FileUploadResponsePayloadDto.prototype, "size", void 0);
|
|
306
|
+
_ts_decorate([
|
|
307
|
+
(0,class_transformer__rspack_import_1.Expose)(),
|
|
308
|
+
(0,_nestjs_swagger__rspack_import_0.ApiProperty)({
|
|
309
|
+
description: 'Storage key / path used to retrieve the file from the provider',
|
|
310
|
+
example: 'uploads/users/abc123/profile-photo.jpg'
|
|
311
|
+
}),
|
|
312
|
+
_ts_metadata("design:type", String)
|
|
313
|
+
], FileUploadResponsePayloadDto.prototype, "key", void 0);
|
|
314
|
+
_ts_decorate([
|
|
315
|
+
(0,class_transformer__rspack_import_1.Expose)(),
|
|
316
|
+
(0,_nestjs_swagger__rspack_import_0.ApiProperty)({
|
|
317
|
+
description: 'Storage provider type (e.g. s3, gcs, local)',
|
|
318
|
+
example: 's3'
|
|
319
|
+
}),
|
|
320
|
+
_ts_metadata("design:type", String)
|
|
321
|
+
], FileUploadResponsePayloadDto.prototype, "location", void 0);
|
|
322
|
+
_ts_decorate([
|
|
323
|
+
(0,class_transformer__rspack_import_1.Expose)(),
|
|
324
|
+
(0,_nestjs_swagger__rspack_import_0.ApiProperty)({
|
|
325
|
+
description: 'ID of the storage configuration used to store this file',
|
|
326
|
+
example: '123e4567-e89b-12d3-a456-426614174000'
|
|
327
|
+
}),
|
|
328
|
+
_ts_metadata("design:type", String)
|
|
329
|
+
], FileUploadResponsePayloadDto.prototype, "storageConfigId", void 0);
|
|
330
|
+
|
|
331
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
332
|
+
$V: () => (DeleteMultipleFileDto),
|
|
333
|
+
My: () => (FileUploadResponsePayloadDto),
|
|
334
|
+
Pd: () => (DeleteSingleFileDto),
|
|
335
|
+
f5: () => (ImageFormat),
|
|
336
|
+
hL: () => (UploadOptionsDto)
|
|
337
|
+
});
|
|
338
|
+
|
|
339
|
+
|
|
340
|
+
},
|
|
341
|
+
975(__unused_rspack_module, __webpack_exports__, __webpack_require__) {
|
|
342
|
+
|
|
343
|
+
// EXPORTS
|
|
344
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
345
|
+
FileManager: () => (/* reexport */ FileManager),
|
|
346
|
+
NP: () => (/* reexport */ FileManager),
|
|
347
|
+
FileManagerWithCompany: () => (/* reexport */ FileManagerWithCompany),
|
|
348
|
+
Folder: () => (/* reexport */ Folder),
|
|
349
|
+
KQ: () => (/* reexport */ Folder),
|
|
350
|
+
FolderWithCompany: () => (/* reexport */ FolderWithCompany),
|
|
351
|
+
eZ: () => (/* binding */ StorageCompanyEntities),
|
|
352
|
+
StorageConfig: () => (/* reexport */ StorageConfig),
|
|
353
|
+
Zk: () => (/* reexport */ StorageConfig),
|
|
354
|
+
StorageConfigWithCompany: () => (/* reexport */ StorageConfigWithCompany),
|
|
355
|
+
oM: () => (/* binding */ StorageCoreEntities),
|
|
356
|
+
eu: () => (/* binding */ getStorageEntitiesByConfig)
|
|
357
|
+
});
|
|
358
|
+
|
|
359
|
+
;// CONCATENATED MODULE: external "@flusys/nestjs-shared/entities"
|
|
360
|
+
|
|
361
|
+
// EXTERNAL MODULE: external "typeorm"
|
|
362
|
+
var external_typeorm_ = __webpack_require__(158);
|
|
363
|
+
;// CONCATENATED MODULE: ./projects/nestjs-storage/src/entities/file-manager.entity.ts
|
|
364
|
+
function _ts_decorate(decorators, target, key, desc) {
|
|
365
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
366
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
|
|
367
|
+
r = Reflect.decorate(decorators, target, key, desc);
|
|
368
|
+
} else {
|
|
369
|
+
for(var i = decorators.length - 1; i >= 0; i--){
|
|
370
|
+
if (d = decorators[i]) {
|
|
371
|
+
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
376
|
+
}
|
|
377
|
+
function _ts_metadata(metadataKey, metadataValue) {
|
|
378
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
|
|
379
|
+
return Reflect.metadata(metadataKey, metadataValue);
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
|
|
384
|
+
class FileManager extends Identity {
|
|
385
|
+
name;
|
|
386
|
+
contentType;
|
|
387
|
+
size;
|
|
388
|
+
key;
|
|
389
|
+
url;
|
|
390
|
+
location;
|
|
391
|
+
storageConfigId;
|
|
392
|
+
expiresAt = null;
|
|
393
|
+
isPrivate;
|
|
394
|
+
folder;
|
|
395
|
+
}
|
|
396
|
+
_ts_decorate([
|
|
397
|
+
(0,external_typeorm_.Column)({
|
|
398
|
+
type: 'varchar',
|
|
399
|
+
length: 255,
|
|
400
|
+
nullable: false
|
|
401
|
+
}),
|
|
402
|
+
_ts_metadata("design:type", String)
|
|
403
|
+
], FileManager.prototype, "name", void 0);
|
|
404
|
+
_ts_decorate([
|
|
405
|
+
(0,external_typeorm_.Column)({
|
|
406
|
+
type: 'varchar',
|
|
407
|
+
length: 255,
|
|
408
|
+
nullable: false
|
|
409
|
+
}),
|
|
410
|
+
_ts_metadata("design:type", String)
|
|
411
|
+
], FileManager.prototype, "contentType", void 0);
|
|
412
|
+
_ts_decorate([
|
|
413
|
+
(0,external_typeorm_.Column)({
|
|
414
|
+
type: 'varchar',
|
|
415
|
+
length: 255,
|
|
416
|
+
nullable: false
|
|
417
|
+
}),
|
|
418
|
+
_ts_metadata("design:type", String)
|
|
419
|
+
], FileManager.prototype, "size", void 0);
|
|
420
|
+
_ts_decorate([
|
|
421
|
+
(0,external_typeorm_.Column)({
|
|
422
|
+
type: 'text',
|
|
423
|
+
nullable: false
|
|
424
|
+
}),
|
|
425
|
+
_ts_metadata("design:type", String)
|
|
426
|
+
], FileManager.prototype, "key", void 0);
|
|
427
|
+
_ts_decorate([
|
|
428
|
+
(0,external_typeorm_.Column)({
|
|
429
|
+
type: 'text',
|
|
430
|
+
nullable: true
|
|
431
|
+
}),
|
|
432
|
+
_ts_metadata("design:type", Object)
|
|
433
|
+
], FileManager.prototype, "url", void 0);
|
|
434
|
+
_ts_decorate([
|
|
435
|
+
(0,external_typeorm_.Column)({
|
|
436
|
+
type: 'varchar',
|
|
437
|
+
length: 50,
|
|
438
|
+
nullable: false
|
|
439
|
+
}),
|
|
440
|
+
_ts_metadata("design:type", String)
|
|
441
|
+
], FileManager.prototype, "location", void 0);
|
|
442
|
+
_ts_decorate([
|
|
443
|
+
(0,external_typeorm_.Column)({
|
|
444
|
+
type: 'uuid',
|
|
445
|
+
nullable: true
|
|
446
|
+
}),
|
|
447
|
+
_ts_metadata("design:type", Object)
|
|
448
|
+
], FileManager.prototype, "storageConfigId", void 0);
|
|
449
|
+
_ts_decorate([
|
|
450
|
+
(0,external_typeorm_.Column)({
|
|
451
|
+
type: 'bigint',
|
|
452
|
+
nullable: true
|
|
453
|
+
}),
|
|
454
|
+
_ts_metadata("design:type", Object)
|
|
455
|
+
], FileManager.prototype, "expiresAt", void 0);
|
|
456
|
+
_ts_decorate([
|
|
457
|
+
(0,external_typeorm_.Column)({
|
|
458
|
+
type: 'boolean',
|
|
459
|
+
nullable: false,
|
|
460
|
+
default: false
|
|
461
|
+
}),
|
|
462
|
+
_ts_metadata("design:type", Boolean)
|
|
463
|
+
], FileManager.prototype, "isPrivate", void 0);
|
|
464
|
+
_ts_decorate([
|
|
465
|
+
(0,external_typeorm_.ManyToOne)('Folder', (folder)=>folder.fileManager, {
|
|
466
|
+
nullable: true,
|
|
467
|
+
onDelete: 'SET NULL'
|
|
468
|
+
}),
|
|
469
|
+
(0,external_typeorm_.JoinColumn)({
|
|
470
|
+
name: 'folder_id'
|
|
471
|
+
}),
|
|
472
|
+
_ts_metadata("design:type", Object)
|
|
473
|
+
], FileManager.prototype, "folder", void 0);
|
|
474
|
+
FileManager = _ts_decorate([
|
|
475
|
+
(0,external_typeorm_.Entity)({
|
|
476
|
+
name: 'file_manager'
|
|
477
|
+
})
|
|
478
|
+
], FileManager);
|
|
479
|
+
|
|
480
|
+
;// CONCATENATED MODULE: ./projects/nestjs-storage/src/entities/folder.entity.ts
|
|
481
|
+
function folder_entity_ts_decorate(decorators, target, key, desc) {
|
|
482
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
483
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
|
|
484
|
+
r = Reflect.decorate(decorators, target, key, desc);
|
|
485
|
+
} else {
|
|
486
|
+
for(var i = decorators.length - 1; i >= 0; i--){
|
|
487
|
+
if (d = decorators[i]) {
|
|
488
|
+
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
}
|
|
492
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
493
|
+
}
|
|
494
|
+
function folder_entity_ts_metadata(metadataKey, metadataValue) {
|
|
495
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
|
|
496
|
+
return Reflect.metadata(metadataKey, metadataValue);
|
|
497
|
+
}
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
|
|
501
|
+
class Folder extends Identity {
|
|
502
|
+
name;
|
|
503
|
+
slug;
|
|
504
|
+
fileManager;
|
|
505
|
+
}
|
|
506
|
+
folder_entity_ts_decorate([
|
|
507
|
+
(0,external_typeorm_.Column)({
|
|
508
|
+
type: 'varchar',
|
|
509
|
+
length: 255,
|
|
510
|
+
nullable: false
|
|
511
|
+
}),
|
|
512
|
+
folder_entity_ts_metadata("design:type", String)
|
|
513
|
+
], Folder.prototype, "name", void 0);
|
|
514
|
+
folder_entity_ts_decorate([
|
|
515
|
+
(0,external_typeorm_.Column)({
|
|
516
|
+
type: 'varchar',
|
|
517
|
+
length: 255,
|
|
518
|
+
nullable: false
|
|
519
|
+
}),
|
|
520
|
+
folder_entity_ts_metadata("design:type", String)
|
|
521
|
+
], Folder.prototype, "slug", void 0);
|
|
522
|
+
folder_entity_ts_decorate([
|
|
523
|
+
(0,external_typeorm_.OneToMany)('FileManager', (fileManager)=>fileManager.folder),
|
|
524
|
+
folder_entity_ts_metadata("design:type", Array)
|
|
525
|
+
], Folder.prototype, "fileManager", void 0);
|
|
526
|
+
Folder = folder_entity_ts_decorate([
|
|
527
|
+
(0,external_typeorm_.Entity)({
|
|
528
|
+
name: 'folder'
|
|
529
|
+
})
|
|
530
|
+
], Folder);
|
|
531
|
+
|
|
532
|
+
// EXTERNAL MODULE: external "@flusys/nestjs-shared"
|
|
533
|
+
var nestjs_shared_ = __webpack_require__(422);
|
|
534
|
+
;// CONCATENATED MODULE: ./projects/nestjs-storage/src/entities/storage-config.entity.ts
|
|
535
|
+
function storage_config_entity_ts_decorate(decorators, target, key, desc) {
|
|
536
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
537
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
|
|
538
|
+
r = Reflect.decorate(decorators, target, key, desc);
|
|
539
|
+
} else {
|
|
540
|
+
for(var i = decorators.length - 1; i >= 0; i--){
|
|
541
|
+
if (d = decorators[i]) {
|
|
542
|
+
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
543
|
+
}
|
|
544
|
+
}
|
|
545
|
+
}
|
|
546
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
547
|
+
}
|
|
548
|
+
function storage_config_entity_ts_metadata(metadataKey, metadataValue) {
|
|
549
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
|
|
550
|
+
return Reflect.metadata(metadataKey, metadataValue);
|
|
551
|
+
}
|
|
552
|
+
}
|
|
553
|
+
|
|
554
|
+
|
|
555
|
+
|
|
556
|
+
class StorageConfig extends Identity {
|
|
557
|
+
name;
|
|
558
|
+
storage;
|
|
559
|
+
config;
|
|
560
|
+
isActive;
|
|
561
|
+
isDefault;
|
|
562
|
+
}
|
|
563
|
+
storage_config_entity_ts_decorate([
|
|
564
|
+
(0,external_typeorm_.Column)({
|
|
565
|
+
type: 'varchar',
|
|
566
|
+
length: 255,
|
|
567
|
+
nullable: false
|
|
568
|
+
}),
|
|
569
|
+
storage_config_entity_ts_metadata("design:type", String)
|
|
570
|
+
], StorageConfig.prototype, "name", void 0);
|
|
571
|
+
storage_config_entity_ts_decorate([
|
|
572
|
+
(0,external_typeorm_.Column)({
|
|
573
|
+
type: 'varchar',
|
|
574
|
+
length: 50,
|
|
575
|
+
nullable: false
|
|
576
|
+
}),
|
|
577
|
+
storage_config_entity_ts_metadata("design:type", String)
|
|
578
|
+
], StorageConfig.prototype, "storage", void 0);
|
|
579
|
+
storage_config_entity_ts_decorate([
|
|
580
|
+
(0,external_typeorm_.Column)({
|
|
581
|
+
type: (0,nestjs_shared_.getJsonColumnType)(),
|
|
582
|
+
nullable: false
|
|
583
|
+
}),
|
|
584
|
+
storage_config_entity_ts_metadata("design:type", typeof Record === "undefined" ? Object : Record)
|
|
585
|
+
], StorageConfig.prototype, "config", void 0);
|
|
586
|
+
storage_config_entity_ts_decorate([
|
|
587
|
+
(0,external_typeorm_.Column)({
|
|
588
|
+
type: 'boolean',
|
|
589
|
+
default: true,
|
|
590
|
+
name: 'is_active'
|
|
591
|
+
}),
|
|
592
|
+
storage_config_entity_ts_metadata("design:type", Boolean)
|
|
593
|
+
], StorageConfig.prototype, "isActive", void 0);
|
|
594
|
+
storage_config_entity_ts_decorate([
|
|
595
|
+
(0,external_typeorm_.Column)({
|
|
596
|
+
type: 'boolean',
|
|
597
|
+
default: false,
|
|
598
|
+
name: 'is_default'
|
|
599
|
+
}),
|
|
600
|
+
storage_config_entity_ts_metadata("design:type", Boolean)
|
|
601
|
+
], StorageConfig.prototype, "isDefault", void 0);
|
|
602
|
+
StorageConfig = storage_config_entity_ts_decorate([
|
|
603
|
+
(0,external_typeorm_.Entity)({
|
|
604
|
+
name: 'storage_config'
|
|
605
|
+
}),
|
|
606
|
+
(0,external_typeorm_.Index)([
|
|
607
|
+
'name'
|
|
608
|
+
]),
|
|
609
|
+
(0,external_typeorm_.Index)([
|
|
610
|
+
'storage'
|
|
611
|
+
]),
|
|
612
|
+
(0,external_typeorm_.Index)([
|
|
613
|
+
'isActive'
|
|
614
|
+
]),
|
|
615
|
+
(0,external_typeorm_.Index)([
|
|
616
|
+
'isDefault'
|
|
617
|
+
])
|
|
618
|
+
], StorageConfig);
|
|
619
|
+
|
|
620
|
+
;// CONCATENATED MODULE: ./projects/nestjs-storage/src/entities/file-manager-with-company.entity.ts
|
|
621
|
+
function file_manager_with_company_entity_ts_decorate(decorators, target, key, desc) {
|
|
622
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
623
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
|
|
624
|
+
r = Reflect.decorate(decorators, target, key, desc);
|
|
625
|
+
} else {
|
|
626
|
+
for(var i = decorators.length - 1; i >= 0; i--){
|
|
627
|
+
if (d = decorators[i]) {
|
|
628
|
+
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
629
|
+
}
|
|
630
|
+
}
|
|
631
|
+
}
|
|
632
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
633
|
+
}
|
|
634
|
+
function file_manager_with_company_entity_ts_metadata(metadataKey, metadataValue) {
|
|
635
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
|
|
636
|
+
return Reflect.metadata(metadataKey, metadataValue);
|
|
637
|
+
}
|
|
638
|
+
}
|
|
639
|
+
|
|
640
|
+
|
|
641
|
+
class FileManagerWithCompany extends FileManager {
|
|
642
|
+
companyId;
|
|
643
|
+
}
|
|
644
|
+
file_manager_with_company_entity_ts_decorate([
|
|
645
|
+
(0,external_typeorm_.Column)({
|
|
646
|
+
type: 'uuid',
|
|
647
|
+
nullable: true
|
|
648
|
+
}),
|
|
649
|
+
file_manager_with_company_entity_ts_metadata("design:type", Object)
|
|
650
|
+
], FileManagerWithCompany.prototype, "companyId", void 0);
|
|
651
|
+
file_manager_with_company_entity_ts_decorate([
|
|
652
|
+
(0,external_typeorm_.ManyToOne)('FolderWithCompany', (folder)=>folder.fileManager, {
|
|
653
|
+
nullable: true,
|
|
654
|
+
onDelete: 'SET NULL'
|
|
655
|
+
}),
|
|
656
|
+
(0,external_typeorm_.JoinColumn)({
|
|
657
|
+
name: 'folder_id'
|
|
658
|
+
}),
|
|
659
|
+
file_manager_with_company_entity_ts_metadata("design:type", Object)
|
|
660
|
+
], FileManagerWithCompany.prototype, "folder", void 0);
|
|
661
|
+
FileManagerWithCompany = file_manager_with_company_entity_ts_decorate([
|
|
662
|
+
(0,external_typeorm_.Entity)({
|
|
663
|
+
name: 'file_manager'
|
|
664
|
+
})
|
|
665
|
+
], FileManagerWithCompany);
|
|
666
|
+
|
|
667
|
+
;// CONCATENATED MODULE: ./projects/nestjs-storage/src/entities/folder-with-company.entity.ts
|
|
668
|
+
function folder_with_company_entity_ts_decorate(decorators, target, key, desc) {
|
|
669
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
670
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
|
|
671
|
+
r = Reflect.decorate(decorators, target, key, desc);
|
|
672
|
+
} else {
|
|
673
|
+
for(var i = decorators.length - 1; i >= 0; i--){
|
|
674
|
+
if (d = decorators[i]) {
|
|
675
|
+
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
676
|
+
}
|
|
677
|
+
}
|
|
678
|
+
}
|
|
679
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
680
|
+
}
|
|
681
|
+
function folder_with_company_entity_ts_metadata(metadataKey, metadataValue) {
|
|
682
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
|
|
683
|
+
return Reflect.metadata(metadataKey, metadataValue);
|
|
684
|
+
}
|
|
685
|
+
}
|
|
686
|
+
|
|
687
|
+
|
|
688
|
+
class FolderWithCompany extends Folder {
|
|
689
|
+
companyId;
|
|
690
|
+
}
|
|
691
|
+
folder_with_company_entity_ts_decorate([
|
|
692
|
+
(0,external_typeorm_.Column)({
|
|
693
|
+
type: 'uuid',
|
|
694
|
+
nullable: true
|
|
695
|
+
}),
|
|
696
|
+
folder_with_company_entity_ts_metadata("design:type", Object)
|
|
697
|
+
], FolderWithCompany.prototype, "companyId", void 0);
|
|
698
|
+
folder_with_company_entity_ts_decorate([
|
|
699
|
+
(0,external_typeorm_.OneToMany)('FileManagerWithCompany', (fileManager)=>fileManager.folder),
|
|
700
|
+
folder_with_company_entity_ts_metadata("design:type", Array)
|
|
701
|
+
], FolderWithCompany.prototype, "fileManager", void 0);
|
|
702
|
+
FolderWithCompany = folder_with_company_entity_ts_decorate([
|
|
703
|
+
(0,external_typeorm_.Entity)({
|
|
704
|
+
name: 'folder'
|
|
705
|
+
})
|
|
706
|
+
], FolderWithCompany);
|
|
707
|
+
|
|
708
|
+
;// CONCATENATED MODULE: ./projects/nestjs-storage/src/entities/storage-config-with-company.entity.ts
|
|
709
|
+
function storage_config_with_company_entity_ts_decorate(decorators, target, key, desc) {
|
|
710
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
711
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
|
|
712
|
+
r = Reflect.decorate(decorators, target, key, desc);
|
|
713
|
+
} else {
|
|
714
|
+
for(var i = decorators.length - 1; i >= 0; i--){
|
|
715
|
+
if (d = decorators[i]) {
|
|
716
|
+
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
717
|
+
}
|
|
718
|
+
}
|
|
719
|
+
}
|
|
720
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
721
|
+
}
|
|
722
|
+
function storage_config_with_company_entity_ts_metadata(metadataKey, metadataValue) {
|
|
723
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
|
|
724
|
+
return Reflect.metadata(metadataKey, metadataValue);
|
|
725
|
+
}
|
|
726
|
+
}
|
|
727
|
+
|
|
728
|
+
|
|
729
|
+
class StorageConfigWithCompany extends StorageConfig {
|
|
730
|
+
companyId;
|
|
731
|
+
}
|
|
732
|
+
storage_config_with_company_entity_ts_decorate([
|
|
733
|
+
(0,external_typeorm_.Column)({
|
|
734
|
+
type: 'uuid',
|
|
735
|
+
nullable: true
|
|
736
|
+
}),
|
|
737
|
+
storage_config_with_company_entity_ts_metadata("design:type", Object)
|
|
738
|
+
], StorageConfigWithCompany.prototype, "companyId", void 0);
|
|
739
|
+
StorageConfigWithCompany = storage_config_with_company_entity_ts_decorate([
|
|
740
|
+
(0,external_typeorm_.Entity)({
|
|
741
|
+
name: 'storage_config'
|
|
742
|
+
})
|
|
743
|
+
], StorageConfigWithCompany);
|
|
744
|
+
|
|
745
|
+
;// CONCATENATED MODULE: ./projects/nestjs-storage/src/entities/index.ts
|
|
746
|
+
// Entities without company feature
|
|
747
|
+
|
|
748
|
+
|
|
749
|
+
|
|
750
|
+
// Entities with company feature
|
|
751
|
+
|
|
752
|
+
|
|
753
|
+
|
|
754
|
+
|
|
755
|
+
|
|
756
|
+
|
|
757
|
+
|
|
758
|
+
|
|
759
|
+
|
|
760
|
+
// Core entities (no company feature)
|
|
761
|
+
const StorageCoreEntities = [
|
|
762
|
+
FileManager,
|
|
763
|
+
Folder,
|
|
764
|
+
StorageConfig
|
|
765
|
+
];
|
|
766
|
+
// Company-specific entities
|
|
767
|
+
const StorageCompanyEntities = [
|
|
768
|
+
FileManagerWithCompany,
|
|
769
|
+
FolderWithCompany,
|
|
770
|
+
StorageConfigWithCompany
|
|
771
|
+
];
|
|
772
|
+
function getStorageEntitiesByConfig(enableCompanyFeature) {
|
|
773
|
+
return enableCompanyFeature ? StorageCompanyEntities : StorageCoreEntities;
|
|
774
|
+
}
|
|
775
|
+
// Base type aliases for backwards compatibility with services
|
|
776
|
+
|
|
777
|
+
|
|
778
|
+
|
|
779
|
+
|
|
780
|
+
|
|
781
|
+
},
|
|
782
|
+
733(__unused_rspack_module, __webpack_exports__, __webpack_require__) {
|
|
783
|
+
var FileLocationEnum = /*#__PURE__*/ function(FileLocationEnum) {
|
|
784
|
+
FileLocationEnum["AWS"] = "aws";
|
|
785
|
+
FileLocationEnum["AZURE"] = "azure";
|
|
786
|
+
FileLocationEnum["SFTP"] = "sftp";
|
|
787
|
+
FileLocationEnum["LOCAL"] = "local";
|
|
788
|
+
return FileLocationEnum;
|
|
789
|
+
}({});
|
|
790
|
+
|
|
791
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
792
|
+
N: () => (FileLocationEnum)
|
|
793
|
+
});
|
|
794
|
+
|
|
795
|
+
|
|
796
|
+
},
|
|
797
|
+
192(__unused_rspack_module, __webpack_exports__, __webpack_require__) {
|
|
798
|
+
|
|
799
|
+
// EXPORTS
|
|
800
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
801
|
+
L: () => (/* binding */ StorageFactoryService)
|
|
802
|
+
});
|
|
803
|
+
|
|
804
|
+
// EXTERNAL MODULE: external "@flusys/nestjs-shared/constants"
|
|
805
|
+
var constants_ = __webpack_require__(140);
|
|
806
|
+
// EXTERNAL MODULE: external "@nestjs/common"
|
|
807
|
+
var common_ = __webpack_require__(157);
|
|
808
|
+
;// CONCATENATED MODULE: external "crypto"
|
|
809
|
+
|
|
810
|
+
// EXTERNAL MODULE: ./projects/nestjs-storage/src/services/index.ts
|
|
811
|
+
var services = __webpack_require__(148);
|
|
812
|
+
// EXTERNAL MODULE: ./projects/nestjs-storage/src/providers/storage-provider.registry.ts
|
|
813
|
+
var storage_provider_registry = __webpack_require__(264);
|
|
814
|
+
;// CONCATENATED MODULE: ./projects/nestjs-storage/src/providers/storage-factory.service.ts
|
|
815
|
+
function _ts_decorate(decorators, target, key, desc) {
|
|
816
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
817
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
|
|
818
|
+
r = Reflect.decorate(decorators, target, key, desc);
|
|
819
|
+
} else {
|
|
820
|
+
for(var i = decorators.length - 1; i >= 0; i--){
|
|
821
|
+
if (d = decorators[i]) {
|
|
822
|
+
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
823
|
+
}
|
|
824
|
+
}
|
|
825
|
+
}
|
|
826
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
827
|
+
}
|
|
828
|
+
function _ts_metadata(metadataKey, metadataValue) {
|
|
829
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
|
|
830
|
+
return Reflect.metadata(metadataKey, metadataValue);
|
|
831
|
+
}
|
|
832
|
+
}
|
|
833
|
+
function _ts_param(paramIndex, decorator) {
|
|
834
|
+
return function(target, key) {
|
|
835
|
+
decorator(target, key, paramIndex);
|
|
836
|
+
};
|
|
837
|
+
}
|
|
838
|
+
|
|
839
|
+
|
|
840
|
+
|
|
841
|
+
|
|
842
|
+
|
|
843
|
+
class StorageFactoryService {
|
|
844
|
+
configService;
|
|
845
|
+
cache = new Map();
|
|
846
|
+
constructor(configService){
|
|
847
|
+
this.configService = configService;
|
|
848
|
+
}
|
|
849
|
+
async createProvider(config) {
|
|
850
|
+
const cacheKey = this.generateCacheKey(config);
|
|
851
|
+
const cached = this.cache.get(cacheKey);
|
|
852
|
+
if (cached) return cached;
|
|
853
|
+
const ProviderClass = storage_provider_registry/* .StorageProviderRegistry.get */.C.get(config.provider);
|
|
854
|
+
if (!ProviderClass) {
|
|
855
|
+
throw new common_.NotFoundException({
|
|
856
|
+
message: `Storage provider '${config.provider}' not available. Available: ${storage_provider_registry/* .StorageProviderRegistry.getAll */.C.getAll().join(', ')}`,
|
|
857
|
+
messageKey: constants_.SYSTEM_MESSAGES.SERVICE_NOT_AVAILABLE,
|
|
858
|
+
messageVariables: {
|
|
859
|
+
provider: config.provider,
|
|
860
|
+
available: storage_provider_registry/* .StorageProviderRegistry.getAll */.C.getAll().join(', ')
|
|
861
|
+
}
|
|
862
|
+
});
|
|
863
|
+
}
|
|
864
|
+
try {
|
|
865
|
+
const instance = new ProviderClass();
|
|
866
|
+
await this.initializeProvider(instance, config);
|
|
867
|
+
this.cache.set(cacheKey, instance);
|
|
868
|
+
return instance;
|
|
869
|
+
} catch (error) {
|
|
870
|
+
const errorMessage = error instanceof Error ? error.message : 'Unknown error';
|
|
871
|
+
throw new common_.InternalServerErrorException({
|
|
872
|
+
message: `Failed to initialize '${config.provider}': ${errorMessage}`,
|
|
873
|
+
messageKey: constants_.SYSTEM_MESSAGES.INTERNAL_ERROR,
|
|
874
|
+
messageVariables: {
|
|
875
|
+
provider: config.provider,
|
|
876
|
+
error: errorMessage
|
|
877
|
+
}
|
|
878
|
+
});
|
|
879
|
+
}
|
|
880
|
+
}
|
|
881
|
+
async getProvider(providerName) {
|
|
882
|
+
const cachedKey = Array.from(this.cache.keys()).find((k)=>k.startsWith(providerName));
|
|
883
|
+
if (cachedKey) return this.cache.get(cachedKey);
|
|
884
|
+
return this.createProvider({
|
|
885
|
+
provider: providerName,
|
|
886
|
+
config: {}
|
|
887
|
+
});
|
|
888
|
+
}
|
|
889
|
+
getLocalProviderBasePath() {
|
|
890
|
+
const localKey = Array.from(this.cache.keys()).find((k)=>k.startsWith('local'));
|
|
891
|
+
const provider = localKey ? this.cache.get(localKey) : null;
|
|
892
|
+
return provider && 'basePath' in provider ? provider.basePath : null;
|
|
893
|
+
}
|
|
894
|
+
clearCache() {
|
|
895
|
+
this.cache.clear();
|
|
896
|
+
}
|
|
897
|
+
async onModuleDestroy() {
|
|
898
|
+
const closePromises = Array.from(this.cache.entries()).filter(([, p])=>'close' in p && typeof p.close === 'function').map(([, p])=>p.close().catch(()=>{}));
|
|
899
|
+
await Promise.allSettled(closePromises);
|
|
900
|
+
this.cache.clear();
|
|
901
|
+
}
|
|
902
|
+
// ─── Private Helpers ──────────────────────────────────────────────────────────
|
|
903
|
+
generateCacheKey(config) {
|
|
904
|
+
const sortedKeys = Object.keys(config.config || {}).sort();
|
|
905
|
+
const hash = __rspack_external_crypto.createHash('sha256').update(JSON.stringify(config.config, sortedKeys)).digest('hex').substring(0, 16);
|
|
906
|
+
return `${config.provider}-${hash}`;
|
|
907
|
+
}
|
|
908
|
+
async initializeProvider(instance, config) {
|
|
909
|
+
if (!('initialize' in instance) || typeof instance.initialize !== 'function') {
|
|
910
|
+
return;
|
|
911
|
+
}
|
|
912
|
+
let initConfig = config.config;
|
|
913
|
+
// Inject appUrl as baseUrl fallback for local provider
|
|
914
|
+
if (config.provider === 'local' && !config.config?.baseUrl) {
|
|
915
|
+
const appUrl = this.configService.getAppUrl();
|
|
916
|
+
if (appUrl) {
|
|
917
|
+
initConfig = {
|
|
918
|
+
...config.config,
|
|
919
|
+
baseUrl: appUrl
|
|
920
|
+
};
|
|
921
|
+
}
|
|
922
|
+
}
|
|
923
|
+
await instance.initialize(initConfig);
|
|
924
|
+
}
|
|
925
|
+
}
|
|
926
|
+
StorageFactoryService = _ts_decorate([
|
|
927
|
+
(0,common_.Injectable)(),
|
|
928
|
+
_ts_param(0, (0,common_.Inject)(services/* .StorageConfigService */.tP)),
|
|
929
|
+
_ts_metadata("design:type", Function),
|
|
930
|
+
_ts_metadata("design:paramtypes", [
|
|
931
|
+
typeof services/* .StorageConfigService */.tP === "undefined" ? Object : services/* .StorageConfigService */.tP
|
|
932
|
+
])
|
|
933
|
+
], StorageFactoryService);
|
|
934
|
+
|
|
935
|
+
|
|
936
|
+
},
|
|
937
|
+
264(__unused_rspack_module, __webpack_exports__, __webpack_require__) {
|
|
938
|
+
/**
|
|
939
|
+
* Static registry for storage provider classes
|
|
940
|
+
* Allows dynamic registration at runtime
|
|
941
|
+
*/ class StorageProviderRegistry {
|
|
942
|
+
static providers = new Map();
|
|
943
|
+
static register(name, providerClass) {
|
|
944
|
+
this.providers.set(name.toLowerCase(), providerClass);
|
|
945
|
+
}
|
|
946
|
+
static get(name) {
|
|
947
|
+
return this.providers.get(name.toLowerCase());
|
|
948
|
+
}
|
|
949
|
+
static has(name) {
|
|
950
|
+
return this.providers.has(name.toLowerCase());
|
|
951
|
+
}
|
|
952
|
+
static getAll() {
|
|
953
|
+
return Array.from(this.providers.keys());
|
|
954
|
+
}
|
|
955
|
+
static clear() {
|
|
956
|
+
this.providers.clear();
|
|
957
|
+
}
|
|
958
|
+
}
|
|
959
|
+
|
|
960
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
961
|
+
C: () => (StorageProviderRegistry)
|
|
962
|
+
});
|
|
963
|
+
|
|
964
|
+
|
|
965
|
+
},
|
|
966
|
+
955(__unused_rspack_module, __webpack_exports__, __webpack_require__) {
|
|
967
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
968
|
+
D: () => (FileManagerService)
|
|
969
|
+
});
|
|
970
|
+
/* import */ var _flusys_nestjs_shared_classes__rspack_import_0 = __webpack_require__(937);
|
|
971
|
+
/* import */ var _flusys_nestjs_shared_modules__rspack_import_1 = __webpack_require__(236);
|
|
972
|
+
/* import */ var _flusys_nestjs_shared_utils__rspack_import_2 = __webpack_require__(216);
|
|
973
|
+
/* import */ var _nestjs_common__rspack_import_3 = __webpack_require__(157);
|
|
974
|
+
/* import */ var typeorm__rspack_import_4 = __webpack_require__(158);
|
|
975
|
+
/* import */ var _config_index_js__rspack_import_9 = __webpack_require__(884);
|
|
976
|
+
/* import */ var _config_index_js__rspack_import_10 = __webpack_require__(450);
|
|
977
|
+
/* import */ var _entities_index_js__rspack_import_5 = __webpack_require__(975);
|
|
978
|
+
/* import */ var _enums_file_location_enum_js__rspack_import_11 = __webpack_require__(733);
|
|
979
|
+
/* import */ var _storage_config_service_js__rspack_import_6 = __webpack_require__(397);
|
|
980
|
+
/* import */ var _storage_datasource_provider_js__rspack_import_7 = __webpack_require__(616);
|
|
981
|
+
/* import */ var _upload_service_js__rspack_import_8 = __webpack_require__(18);
|
|
982
|
+
function _ts_decorate(decorators, target, key, desc) {
|
|
983
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
984
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
|
|
985
|
+
r = Reflect.decorate(decorators, target, key, desc);
|
|
986
|
+
} else {
|
|
987
|
+
for(var i = decorators.length - 1; i >= 0; i--){
|
|
988
|
+
if (d = decorators[i]) {
|
|
989
|
+
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
990
|
+
}
|
|
991
|
+
}
|
|
992
|
+
}
|
|
993
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
994
|
+
}
|
|
995
|
+
function _ts_metadata(metadataKey, metadataValue) {
|
|
996
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
|
|
997
|
+
return Reflect.metadata(metadataKey, metadataValue);
|
|
998
|
+
}
|
|
999
|
+
}
|
|
1000
|
+
function _ts_param(paramIndex, decorator) {
|
|
1001
|
+
return function(target, key) {
|
|
1002
|
+
decorator(target, key, paramIndex);
|
|
1003
|
+
};
|
|
1004
|
+
}
|
|
1005
|
+
|
|
1006
|
+
|
|
1007
|
+
|
|
1008
|
+
|
|
1009
|
+
|
|
1010
|
+
|
|
1011
|
+
|
|
1012
|
+
|
|
1013
|
+
|
|
1014
|
+
|
|
1015
|
+
|
|
1016
|
+
const URL_EXPIRY_SECONDS = 3600;
|
|
1017
|
+
const DEFAULT_SELECT_FIELDS = [
|
|
1018
|
+
'id',
|
|
1019
|
+
'name',
|
|
1020
|
+
'contentType',
|
|
1021
|
+
'size',
|
|
1022
|
+
'key',
|
|
1023
|
+
'url',
|
|
1024
|
+
'location',
|
|
1025
|
+
'storageConfigId',
|
|
1026
|
+
'isPrivate',
|
|
1027
|
+
'createdAt',
|
|
1028
|
+
'deletedAt'
|
|
1029
|
+
];
|
|
1030
|
+
class FileManagerService extends _flusys_nestjs_shared_classes__rspack_import_0.ApiService {
|
|
1031
|
+
cacheManager;
|
|
1032
|
+
utilsService;
|
|
1033
|
+
uploadService;
|
|
1034
|
+
storageConfig;
|
|
1035
|
+
dataSourceProvider;
|
|
1036
|
+
permissionCacheService;
|
|
1037
|
+
constructor(cacheManager, utilsService, uploadService, storageConfig, dataSourceProvider, permissionCacheService){
|
|
1038
|
+
super(_config_index_js__rspack_import_9/* .STORAGE_EVENT_ENTITIES.FILE */.fR.FILE, cacheManager, utilsService, FileManagerService.name, true, _config_index_js__rspack_import_9/* .STORAGE_EVENT_MODULE */.qh, dataSourceProvider, storageConfig.isCompanyFeatureEnabled() ? _entities_index_js__rspack_import_5.FileManagerWithCompany : _entities_index_js__rspack_import_5.FileManager), this.cacheManager = cacheManager, this.utilsService = utilsService, this.uploadService = uploadService, this.storageConfig = storageConfig, this.dataSourceProvider = dataSourceProvider, this.permissionCacheService = permissionCacheService;
|
|
1039
|
+
}
|
|
1040
|
+
// ─── Override Methods ───────────────────────────────────────────────────────
|
|
1041
|
+
async convertSingleDtoToEntity(dto, user) {
|
|
1042
|
+
let entity = {};
|
|
1043
|
+
if ('id' in dto && dto.id && typeof dto.id === 'string') {
|
|
1044
|
+
const existing = await this.repository.findOne({
|
|
1045
|
+
where: {
|
|
1046
|
+
id: dto.id
|
|
1047
|
+
}
|
|
1048
|
+
});
|
|
1049
|
+
if (!existing) throw new _nestjs_common__rspack_import_3.NotFoundException({
|
|
1050
|
+
message: 'Entity not found for update',
|
|
1051
|
+
messageKey: _config_index_js__rspack_import_10/* .FILE_MESSAGES.NOT_FOUND */.uA.NOT_FOUND
|
|
1052
|
+
});
|
|
1053
|
+
entity = existing;
|
|
1054
|
+
}
|
|
1055
|
+
const validatedFolder = dto.folderId ? await this.validateFolder(dto.folderId, user) : null;
|
|
1056
|
+
const storageLocation = await this.resolveStorageLocation(dto, user);
|
|
1057
|
+
const merged = {
|
|
1058
|
+
...entity,
|
|
1059
|
+
...dto,
|
|
1060
|
+
location: storageLocation,
|
|
1061
|
+
folder: validatedFolder
|
|
1062
|
+
};
|
|
1063
|
+
if (this.storageConfig.isCompanyFeatureEnabled()) {
|
|
1064
|
+
merged.companyId = user?.companyId ?? null;
|
|
1065
|
+
}
|
|
1066
|
+
return merged;
|
|
1067
|
+
}
|
|
1068
|
+
async getSelectQuery(query, _user, select) {
|
|
1069
|
+
const fields = (select?.length ? select : DEFAULT_SELECT_FIELDS).map((f)=>`${this.entityName}.${f}`);
|
|
1070
|
+
if (this.storageConfig.isCompanyFeatureEnabled()) {
|
|
1071
|
+
fields.push('file_manager.companyId');
|
|
1072
|
+
}
|
|
1073
|
+
fields.push('folder.id', 'folder.name');
|
|
1074
|
+
query.leftJoinAndSelect('file_manager.folder', 'folder').select(fields);
|
|
1075
|
+
return {
|
|
1076
|
+
query,
|
|
1077
|
+
isRaw: false
|
|
1078
|
+
};
|
|
1079
|
+
}
|
|
1080
|
+
async getFilterQuery(query, filter, _user) {
|
|
1081
|
+
for (const [key, value] of Object.entries(filter)){
|
|
1082
|
+
if (key === 'contentType' && typeof value === 'string') {
|
|
1083
|
+
this.applyContentTypeFilter(query, value);
|
|
1084
|
+
} else {
|
|
1085
|
+
query.andWhere(`${this.entityName}.${key} = :value`, {
|
|
1086
|
+
value
|
|
1087
|
+
});
|
|
1088
|
+
}
|
|
1089
|
+
}
|
|
1090
|
+
return {
|
|
1091
|
+
query,
|
|
1092
|
+
isRaw: false
|
|
1093
|
+
};
|
|
1094
|
+
}
|
|
1095
|
+
async getExtraManipulateQuery(query, filterDto, user) {
|
|
1096
|
+
const result = await super.getExtraManipulateQuery(query, filterDto, user);
|
|
1097
|
+
(0,_flusys_nestjs_shared_utils__rspack_import_2.applyCompanyFilter)(query, {
|
|
1098
|
+
isCompanyFeatureEnabled: this.storageConfig.isCompanyFeatureEnabled(),
|
|
1099
|
+
entityAlias: 'file_manager'
|
|
1100
|
+
}, user);
|
|
1101
|
+
await this.applyPrivateFileFilter(query, user);
|
|
1102
|
+
return result;
|
|
1103
|
+
}
|
|
1104
|
+
async beforeDeleteOperation(dto, user, _qr) {
|
|
1105
|
+
if (dto.type !== 'permanent') return;
|
|
1106
|
+
const ids = Array.isArray(dto.id) ? dto.id : [
|
|
1107
|
+
dto.id
|
|
1108
|
+
];
|
|
1109
|
+
const files = await this.repository.findBy({
|
|
1110
|
+
id: (0,typeorm__rspack_import_4.In)(ids)
|
|
1111
|
+
});
|
|
1112
|
+
const grouped = this.groupFilesByConfig(files);
|
|
1113
|
+
for (const [configId, { keys, location }] of grouped){
|
|
1114
|
+
let deleteKeys = keys;
|
|
1115
|
+
if (location === _enums_file_location_enum_js__rspack_import_11/* .FileLocationEnum.LOCAL */.N.LOCAL && configId !== 'default') {
|
|
1116
|
+
const basePath = await this.getStorageConfigBasePath(configId);
|
|
1117
|
+
if (basePath) {
|
|
1118
|
+
deleteKeys = keys.map((k)=>k.includes('/') ? k : `${basePath}/${k}`);
|
|
1119
|
+
}
|
|
1120
|
+
}
|
|
1121
|
+
await this.uploadService.deleteMultipleFile(deleteKeys, configId === 'default' ? undefined : configId, user ?? undefined, location);
|
|
1122
|
+
}
|
|
1123
|
+
}
|
|
1124
|
+
// ─── Public Methods ─────────────────────────────────────────────────────────
|
|
1125
|
+
async getFiles(dtos, protocol, host, user) {
|
|
1126
|
+
await this.ensureDataSourceRepository();
|
|
1127
|
+
const ids = dtos.map((d)=>d.id).filter(Boolean);
|
|
1128
|
+
if (!ids.length) throw new _nestjs_common__rspack_import_3.BadRequestException({
|
|
1129
|
+
message: 'No valid file IDs provided',
|
|
1130
|
+
messageKey: _config_index_js__rspack_import_10/* .UPLOAD_MESSAGES.NO_FILES_PROVIDED */.dS.NO_FILES_PROVIDED
|
|
1131
|
+
});
|
|
1132
|
+
const fetched = await this.repository.findBy({
|
|
1133
|
+
id: (0,typeorm__rspack_import_4.In)(ids)
|
|
1134
|
+
});
|
|
1135
|
+
const files = await this.scopeFilesToRequester(fetched, user);
|
|
1136
|
+
const now = Date.now();
|
|
1137
|
+
const updatedFiles = [];
|
|
1138
|
+
const responses = await Promise.all(files.map(async (file)=>{
|
|
1139
|
+
const updated = await this.refreshFileUrl(file, protocol, host, now, user);
|
|
1140
|
+
if (updated) updatedFiles.push(file);
|
|
1141
|
+
return this.toFileResponse(file);
|
|
1142
|
+
}));
|
|
1143
|
+
if (updatedFiles.length) {
|
|
1144
|
+
try {
|
|
1145
|
+
await this.repository.save(updatedFiles);
|
|
1146
|
+
await Promise.all([
|
|
1147
|
+
this.clearCacheForAll(),
|
|
1148
|
+
this.clearCacheForId(updatedFiles)
|
|
1149
|
+
]);
|
|
1150
|
+
} catch {
|
|
1151
|
+
// Silent failure - URL update is non-critical
|
|
1152
|
+
}
|
|
1153
|
+
}
|
|
1154
|
+
return responses;
|
|
1155
|
+
}
|
|
1156
|
+
// ─── Private Helpers ────────────────────────────────────────────────────────
|
|
1157
|
+
buildWhereWithCompany(id, user) {
|
|
1158
|
+
const where = {
|
|
1159
|
+
id
|
|
1160
|
+
};
|
|
1161
|
+
if (this.storageConfig.isCompanyFeatureEnabled() && user?.companyId) {
|
|
1162
|
+
where.companyId = user.companyId;
|
|
1163
|
+
}
|
|
1164
|
+
return where;
|
|
1165
|
+
}
|
|
1166
|
+
async getStorageConfigRepository() {
|
|
1167
|
+
const entity = this.storageConfig.isCompanyFeatureEnabled() ? (await Promise.resolve(/* import() */).then(__webpack_require__.bind(__webpack_require__, 975))).StorageConfigWithCompany : (await Promise.resolve(/* import() */).then(__webpack_require__.bind(__webpack_require__, 975))).StorageConfig;
|
|
1168
|
+
return this.dataSourceProvider.getRepository(entity);
|
|
1169
|
+
}
|
|
1170
|
+
async getStorageConfigBasePath(configId) {
|
|
1171
|
+
try {
|
|
1172
|
+
const repo = await this.getStorageConfigRepository();
|
|
1173
|
+
const config = await repo.findOne({
|
|
1174
|
+
where: {
|
|
1175
|
+
id: configId
|
|
1176
|
+
},
|
|
1177
|
+
select: [
|
|
1178
|
+
'id',
|
|
1179
|
+
'config'
|
|
1180
|
+
]
|
|
1181
|
+
});
|
|
1182
|
+
return config?.config?.basePath?.replace(/^\.\//, '') ?? null;
|
|
1183
|
+
} catch {
|
|
1184
|
+
return null;
|
|
1185
|
+
}
|
|
1186
|
+
}
|
|
1187
|
+
async validateFolder(folderId, user) {
|
|
1188
|
+
const entity = this.storageConfig.isCompanyFeatureEnabled() ? _entities_index_js__rspack_import_5.FolderWithCompany : _entities_index_js__rspack_import_5.Folder;
|
|
1189
|
+
const repo = await this.dataSourceProvider.getRepository(entity);
|
|
1190
|
+
const folder = await repo.findOne({
|
|
1191
|
+
where: this.buildWhereWithCompany(folderId, user)
|
|
1192
|
+
});
|
|
1193
|
+
if (!folder) {
|
|
1194
|
+
throw new _nestjs_common__rspack_import_3.BadRequestException({
|
|
1195
|
+
message: `Folder "${folderId}" not found or access denied`,
|
|
1196
|
+
messageKey: _config_index_js__rspack_import_10/* .FOLDER_MESSAGES.NOT_FOUND */.Ee.NOT_FOUND,
|
|
1197
|
+
messageVariables: {
|
|
1198
|
+
folderId
|
|
1199
|
+
}
|
|
1200
|
+
});
|
|
1201
|
+
}
|
|
1202
|
+
return folder;
|
|
1203
|
+
}
|
|
1204
|
+
async resolveStorageLocation(dto, user) {
|
|
1205
|
+
const configId = dto.storageConfigId;
|
|
1206
|
+
if (!configId) return dto.location || _enums_file_location_enum_js__rspack_import_11/* .FileLocationEnum.LOCAL */.N.LOCAL;
|
|
1207
|
+
try {
|
|
1208
|
+
const repo = await this.getStorageConfigRepository();
|
|
1209
|
+
const config = await repo.findOne({
|
|
1210
|
+
where: this.buildWhereWithCompany(configId, user)
|
|
1211
|
+
});
|
|
1212
|
+
return config?.storage || dto.location || _enums_file_location_enum_js__rspack_import_11/* .FileLocationEnum.LOCAL */.N.LOCAL;
|
|
1213
|
+
} catch {
|
|
1214
|
+
return dto.location || _enums_file_location_enum_js__rspack_import_11/* .FileLocationEnum.LOCAL */.N.LOCAL;
|
|
1215
|
+
}
|
|
1216
|
+
}
|
|
1217
|
+
applyContentTypeFilter(query, value) {
|
|
1218
|
+
const patterns = value.split(',').map((t)=>t.trim().replace('*', '%'));
|
|
1219
|
+
query.where(new typeorm__rspack_import_4.Brackets((qb)=>{
|
|
1220
|
+
patterns.forEach((p, i)=>{
|
|
1221
|
+
const method = i === 0 ? 'where' : 'orWhere';
|
|
1222
|
+
qb[method](`${this.entityName}.contentType LIKE :p${i}`, {
|
|
1223
|
+
[`p${i}`]: p
|
|
1224
|
+
});
|
|
1225
|
+
});
|
|
1226
|
+
}));
|
|
1227
|
+
}
|
|
1228
|
+
/**
|
|
1229
|
+
* Restricts a bulk-fetched file set to what the requester is allowed to see -
|
|
1230
|
+
* same company scoping / private-file gating that getAll/getById apply via
|
|
1231
|
+
* getExtraManipulateQuery. Without this, getFiles() would return a working URL
|
|
1232
|
+
* for any file ID, including other companies' or other users' private files.
|
|
1233
|
+
*/ async scopeFilesToRequester(files, user) {
|
|
1234
|
+
let scoped = files;
|
|
1235
|
+
if (this.storageConfig.isCompanyFeatureEnabled() && user?.companyId) {
|
|
1236
|
+
scoped = scoped.filter((file)=>file.companyId === user.companyId);
|
|
1237
|
+
}
|
|
1238
|
+
const canViewPrivate = user ? await this.permissionCacheService.hasPermission({
|
|
1239
|
+
userId: user.id,
|
|
1240
|
+
companyId: user.companyId,
|
|
1241
|
+
branchId: user.branchId
|
|
1242
|
+
}, _flusys_nestjs_shared_classes__rspack_import_0.FILE_PERMISSIONS.VIEW_PRIVATE_ACTION) : false;
|
|
1243
|
+
if (!canViewPrivate) {
|
|
1244
|
+
scoped = scoped.filter((file)=>!file.isPrivate);
|
|
1245
|
+
}
|
|
1246
|
+
return scoped;
|
|
1247
|
+
}
|
|
1248
|
+
async applyPrivateFileFilter(query, user) {
|
|
1249
|
+
if (!user) {
|
|
1250
|
+
query.andWhere('file_manager.isPrivate = :isPrivate', {
|
|
1251
|
+
isPrivate: false
|
|
1252
|
+
});
|
|
1253
|
+
return;
|
|
1254
|
+
}
|
|
1255
|
+
const canViewPrivate = await this.permissionCacheService.hasPermission({
|
|
1256
|
+
userId: user.id,
|
|
1257
|
+
companyId: user.companyId,
|
|
1258
|
+
branchId: user.branchId
|
|
1259
|
+
}, _flusys_nestjs_shared_classes__rspack_import_0.FILE_PERMISSIONS.VIEW_PRIVATE_ACTION);
|
|
1260
|
+
if (!canViewPrivate) {
|
|
1261
|
+
query.andWhere('file_manager.isPrivate = :isPrivate', {
|
|
1262
|
+
isPrivate: false
|
|
1263
|
+
});
|
|
1264
|
+
}
|
|
1265
|
+
}
|
|
1266
|
+
groupFilesByConfig(files) {
|
|
1267
|
+
const grouped = new Map();
|
|
1268
|
+
for (const file of files){
|
|
1269
|
+
const configId = file.storageConfigId || 'default';
|
|
1270
|
+
if (!grouped.has(configId)) {
|
|
1271
|
+
grouped.set(configId, {
|
|
1272
|
+
keys: [],
|
|
1273
|
+
location: file.location
|
|
1274
|
+
});
|
|
1275
|
+
}
|
|
1276
|
+
grouped.get(configId).keys.push(file.key);
|
|
1277
|
+
}
|
|
1278
|
+
return grouped;
|
|
1279
|
+
}
|
|
1280
|
+
getFileBaseUrl(protocol, host) {
|
|
1281
|
+
const appUrl = this.storageConfig.getAppUrl()?.replace(/\/$/, '');
|
|
1282
|
+
return appUrl || `${protocol}://${host}`;
|
|
1283
|
+
}
|
|
1284
|
+
async refreshFileUrl(file, protocol, host, now, user) {
|
|
1285
|
+
const isCloudProvider = file.location === _enums_file_location_enum_js__rspack_import_11/* .FileLocationEnum.AWS */.N.AWS || file.location === _enums_file_location_enum_js__rspack_import_11/* .FileLocationEnum.AZURE */.N.AZURE;
|
|
1286
|
+
const needsNewUrl = !file.url || isCloudProvider && (typeof file.expiresAt !== 'number' || now >= file.expiresAt);
|
|
1287
|
+
if (needsNewUrl && file.storageConfigId) {
|
|
1288
|
+
try {
|
|
1289
|
+
file.url = await this.uploadService.makeFileUrl(file.key, file.storageConfigId, URL_EXPIRY_SECONDS, user);
|
|
1290
|
+
file.expiresAt = now + URL_EXPIRY_SECONDS * 1000;
|
|
1291
|
+
return true;
|
|
1292
|
+
} catch {
|
|
1293
|
+
file.url = `${this.getFileBaseUrl(protocol, host)}/storage/upload/file/${file.key}`;
|
|
1294
|
+
}
|
|
1295
|
+
}
|
|
1296
|
+
if (file.location === _enums_file_location_enum_js__rspack_import_11/* .FileLocationEnum.SFTP */.N.SFTP || file.location === _enums_file_location_enum_js__rspack_import_11/* .FileLocationEnum.LOCAL */.N.LOCAL) {
|
|
1297
|
+
let fileKey = file.key;
|
|
1298
|
+
if (!fileKey.includes('/') && file.storageConfigId) {
|
|
1299
|
+
const basePath = await this.getStorageConfigBasePath(file.storageConfigId);
|
|
1300
|
+
if (basePath) fileKey = `${basePath}/${file.key}`;
|
|
1301
|
+
}
|
|
1302
|
+
const expectedUrl = `${this.getFileBaseUrl(protocol, host)}/storage/upload/file/${fileKey}`;
|
|
1303
|
+
if (file.url !== expectedUrl) {
|
|
1304
|
+
file.url = expectedUrl;
|
|
1305
|
+
return true;
|
|
1306
|
+
}
|
|
1307
|
+
}
|
|
1308
|
+
return false;
|
|
1309
|
+
}
|
|
1310
|
+
toFileResponse(file) {
|
|
1311
|
+
return {
|
|
1312
|
+
id: file.id,
|
|
1313
|
+
name: file.name,
|
|
1314
|
+
contentType: file.contentType,
|
|
1315
|
+
url: file.url || '',
|
|
1316
|
+
location: file.location,
|
|
1317
|
+
storageConfigId: file.storageConfigId || undefined
|
|
1318
|
+
};
|
|
1319
|
+
}
|
|
1320
|
+
}
|
|
1321
|
+
FileManagerService = _ts_decorate([
|
|
1322
|
+
(0,_nestjs_common__rspack_import_3.Injectable)({
|
|
1323
|
+
scope: _nestjs_common__rspack_import_3.Scope.REQUEST
|
|
1324
|
+
}),
|
|
1325
|
+
_ts_param(0, (0,_nestjs_common__rspack_import_3.Inject)('CACHE_INSTANCE')),
|
|
1326
|
+
_ts_param(1, (0,_nestjs_common__rspack_import_3.Inject)(_flusys_nestjs_shared_modules__rspack_import_1.UtilsService)),
|
|
1327
|
+
_ts_param(2, (0,_nestjs_common__rspack_import_3.Inject)(_upload_service_js__rspack_import_8/* .UploadService */.B)),
|
|
1328
|
+
_ts_param(3, (0,_nestjs_common__rspack_import_3.Inject)(_storage_config_service_js__rspack_import_6/* .StorageConfigService */.t)),
|
|
1329
|
+
_ts_param(4, (0,_nestjs_common__rspack_import_3.Inject)(_storage_datasource_provider_js__rspack_import_7/* .StorageDataSourceProvider */.M)),
|
|
1330
|
+
_ts_param(5, (0,_nestjs_common__rspack_import_3.Inject)(_flusys_nestjs_shared_modules__rspack_import_1.SharedPermissionCacheService)),
|
|
1331
|
+
_ts_metadata("design:type", Function),
|
|
1332
|
+
_ts_metadata("design:paramtypes", [
|
|
1333
|
+
typeof _flusys_nestjs_shared_classes__rspack_import_0.HybridCache === "undefined" ? Object : _flusys_nestjs_shared_classes__rspack_import_0.HybridCache,
|
|
1334
|
+
typeof _flusys_nestjs_shared_modules__rspack_import_1.UtilsService === "undefined" ? Object : _flusys_nestjs_shared_modules__rspack_import_1.UtilsService,
|
|
1335
|
+
typeof _upload_service_js__rspack_import_8/* .UploadService */.B === "undefined" ? Object : _upload_service_js__rspack_import_8/* .UploadService */.B,
|
|
1336
|
+
typeof _storage_config_service_js__rspack_import_6/* .StorageConfigService */.t === "undefined" ? Object : _storage_config_service_js__rspack_import_6/* .StorageConfigService */.t,
|
|
1337
|
+
typeof _storage_datasource_provider_js__rspack_import_7/* .StorageDataSourceProvider */.M === "undefined" ? Object : _storage_datasource_provider_js__rspack_import_7/* .StorageDataSourceProvider */.M,
|
|
1338
|
+
typeof _flusys_nestjs_shared_modules__rspack_import_1.SharedPermissionCacheService === "undefined" ? Object : _flusys_nestjs_shared_modules__rspack_import_1.SharedPermissionCacheService
|
|
1339
|
+
])
|
|
1340
|
+
], FileManagerService);
|
|
1341
|
+
|
|
1342
|
+
|
|
1343
|
+
},
|
|
1344
|
+
195(__unused_rspack_module, __webpack_exports__, __webpack_require__) {
|
|
1345
|
+
/* import */ var _flusys_nestjs_shared_classes__rspack_import_0 = __webpack_require__(937);
|
|
1346
|
+
/* import */ var _flusys_nestjs_shared_modules__rspack_import_1 = __webpack_require__(236);
|
|
1347
|
+
/* import */ var _flusys_nestjs_shared_utils__rspack_import_2 = __webpack_require__(216);
|
|
1348
|
+
/* import */ var _nestjs_common__rspack_import_3 = __webpack_require__(157);
|
|
1349
|
+
/* import */ var _config_index_js__rspack_import_7 = __webpack_require__(884);
|
|
1350
|
+
/* import */ var _entities_index_js__rspack_import_4 = __webpack_require__(975);
|
|
1351
|
+
/* import */ var _storage_config_service_js__rspack_import_5 = __webpack_require__(397);
|
|
1352
|
+
/* import */ var _storage_datasource_provider_js__rspack_import_6 = __webpack_require__(616);
|
|
1353
|
+
function _ts_decorate(decorators, target, key, desc) {
|
|
1354
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
1355
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
|
|
1356
|
+
r = Reflect.decorate(decorators, target, key, desc);
|
|
1357
|
+
} else {
|
|
1358
|
+
for(var i = decorators.length - 1; i >= 0; i--){
|
|
1359
|
+
if (d = decorators[i]) {
|
|
1360
|
+
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
1361
|
+
}
|
|
1362
|
+
}
|
|
1363
|
+
}
|
|
1364
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
1365
|
+
}
|
|
1366
|
+
function _ts_metadata(metadataKey, metadataValue) {
|
|
1367
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
|
|
1368
|
+
return Reflect.metadata(metadataKey, metadataValue);
|
|
1369
|
+
}
|
|
1370
|
+
}
|
|
1371
|
+
function _ts_param(paramIndex, decorator) {
|
|
1372
|
+
return function(target, key) {
|
|
1373
|
+
decorator(target, key, paramIndex);
|
|
1374
|
+
};
|
|
1375
|
+
}
|
|
1376
|
+
|
|
1377
|
+
|
|
1378
|
+
|
|
1379
|
+
|
|
1380
|
+
|
|
1381
|
+
|
|
1382
|
+
|
|
1383
|
+
|
|
1384
|
+
class FolderService extends _flusys_nestjs_shared_classes__rspack_import_0.ApiService {
|
|
1385
|
+
cacheManager;
|
|
1386
|
+
utilsService;
|
|
1387
|
+
storageConfig;
|
|
1388
|
+
constructor(cacheManager, utilsService, storageConfig, dataSourceProvider){
|
|
1389
|
+
super(_config_index_js__rspack_import_7/* .STORAGE_EVENT_ENTITIES.FOLDER */.fR.FOLDER, cacheManager, utilsService, FolderService.name, true, _config_index_js__rspack_import_7/* .STORAGE_EVENT_MODULE */.qh, dataSourceProvider, storageConfig.isCompanyFeatureEnabled() ? _entities_index_js__rspack_import_4.FolderWithCompany : _entities_index_js__rspack_import_4.Folder), this.cacheManager = cacheManager, this.utilsService = utilsService, this.storageConfig = storageConfig;
|
|
1390
|
+
}
|
|
1391
|
+
// ─── Override Methods ───────────────────────────────────────────────────────
|
|
1392
|
+
async convertSingleDtoToEntity(dto, user) {
|
|
1393
|
+
const entity = await super.convertSingleDtoToEntity(dto, user);
|
|
1394
|
+
if (this.storageConfig.isCompanyFeatureEnabled()) {
|
|
1395
|
+
entity.companyId = user?.companyId ?? null;
|
|
1396
|
+
}
|
|
1397
|
+
return entity;
|
|
1398
|
+
}
|
|
1399
|
+
async getSelectQuery(query, _user, select) {
|
|
1400
|
+
if (!select?.length) {
|
|
1401
|
+
select = [
|
|
1402
|
+
'id',
|
|
1403
|
+
'name',
|
|
1404
|
+
'slug',
|
|
1405
|
+
'createdAt',
|
|
1406
|
+
'deletedAt'
|
|
1407
|
+
];
|
|
1408
|
+
if (this.storageConfig.isCompanyFeatureEnabled()) {
|
|
1409
|
+
select.push('companyId');
|
|
1410
|
+
}
|
|
1411
|
+
}
|
|
1412
|
+
query.select(select.map((f)=>`${this.entityName}.${f}`));
|
|
1413
|
+
return {
|
|
1414
|
+
query,
|
|
1415
|
+
isRaw: false
|
|
1416
|
+
};
|
|
1417
|
+
}
|
|
1418
|
+
async getExtraManipulateQuery(query, filterDto, user) {
|
|
1419
|
+
const result = await super.getExtraManipulateQuery(query, filterDto, user);
|
|
1420
|
+
(0,_flusys_nestjs_shared_utils__rspack_import_2.applyCompanyFilter)(query, {
|
|
1421
|
+
isCompanyFeatureEnabled: this.storageConfig.isCompanyFeatureEnabled(),
|
|
1422
|
+
entityAlias: 'folder'
|
|
1423
|
+
}, user);
|
|
1424
|
+
return result;
|
|
1425
|
+
}
|
|
1426
|
+
}
|
|
1427
|
+
FolderService = _ts_decorate([
|
|
1428
|
+
(0,_nestjs_common__rspack_import_3.Injectable)({
|
|
1429
|
+
scope: _nestjs_common__rspack_import_3.Scope.REQUEST
|
|
1430
|
+
}),
|
|
1431
|
+
_ts_param(0, (0,_nestjs_common__rspack_import_3.Inject)('CACHE_INSTANCE')),
|
|
1432
|
+
_ts_param(1, (0,_nestjs_common__rspack_import_3.Inject)(_flusys_nestjs_shared_modules__rspack_import_1.UtilsService)),
|
|
1433
|
+
_ts_param(2, (0,_nestjs_common__rspack_import_3.Inject)(_storage_config_service_js__rspack_import_5/* .StorageConfigService */.t)),
|
|
1434
|
+
_ts_param(3, (0,_nestjs_common__rspack_import_3.Inject)(_storage_datasource_provider_js__rspack_import_6/* .StorageDataSourceProvider */.M)),
|
|
1435
|
+
_ts_metadata("design:type", Function),
|
|
1436
|
+
_ts_metadata("design:paramtypes", [
|
|
1437
|
+
typeof _flusys_nestjs_shared_classes__rspack_import_0.HybridCache === "undefined" ? Object : _flusys_nestjs_shared_classes__rspack_import_0.HybridCache,
|
|
1438
|
+
typeof _flusys_nestjs_shared_modules__rspack_import_1.UtilsService === "undefined" ? Object : _flusys_nestjs_shared_modules__rspack_import_1.UtilsService,
|
|
1439
|
+
typeof _storage_config_service_js__rspack_import_5/* .StorageConfigService */.t === "undefined" ? Object : _storage_config_service_js__rspack_import_5/* .StorageConfigService */.t,
|
|
1440
|
+
typeof _storage_datasource_provider_js__rspack_import_6/* .StorageDataSourceProvider */.M === "undefined" ? Object : _storage_datasource_provider_js__rspack_import_6/* .StorageDataSourceProvider */.M
|
|
1441
|
+
])
|
|
1442
|
+
], FolderService);
|
|
1443
|
+
|
|
1444
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
1445
|
+
k: () => (FolderService)
|
|
1446
|
+
});
|
|
1447
|
+
|
|
1448
|
+
|
|
1449
|
+
},
|
|
1450
|
+
148(__unused_rspack_module, __webpack_exports__, __webpack_require__) {
|
|
1451
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
1452
|
+
BB: () => (/* reexport safe */ _upload_service_js__rspack_import_5.B),
|
|
1453
|
+
DL: () => (/* reexport safe */ _file_manager_service_js__rspack_import_0.D),
|
|
1454
|
+
M0: () => (/* reexport safe */ _storage_datasource_provider_js__rspack_import_4.M),
|
|
1455
|
+
kh: () => (/* reexport safe */ _folder_service_js__rspack_import_1.k),
|
|
1456
|
+
ol: () => (/* reexport safe */ _storage_provider_config_service_js__rspack_import_3.o),
|
|
1457
|
+
tP: () => (/* reexport safe */ _storage_config_service_js__rspack_import_2.t)
|
|
1458
|
+
});
|
|
1459
|
+
/* import */ var _file_manager_service_js__rspack_import_0 = __webpack_require__(955);
|
|
1460
|
+
/* import */ var _folder_service_js__rspack_import_1 = __webpack_require__(195);
|
|
1461
|
+
/* import */ var _storage_config_service_js__rspack_import_2 = __webpack_require__(397);
|
|
1462
|
+
/* import */ var _storage_provider_config_service_js__rspack_import_3 = __webpack_require__(623);
|
|
1463
|
+
/* import */ var _storage_datasource_provider_js__rspack_import_4 = __webpack_require__(616);
|
|
1464
|
+
/* import */ var _upload_service_js__rspack_import_5 = __webpack_require__(18);
|
|
1465
|
+
|
|
1466
|
+
|
|
1467
|
+
|
|
1468
|
+
|
|
1469
|
+
|
|
1470
|
+
|
|
1471
|
+
|
|
1472
|
+
|
|
1473
|
+
},
|
|
1474
|
+
397(__unused_rspack_module, __webpack_exports__, __webpack_require__) {
|
|
1475
|
+
/* import */ var _nestjs_common__rspack_import_0 = __webpack_require__(157);
|
|
1476
|
+
/* import */ var _config_index_js__rspack_import_2 = __webpack_require__(450);
|
|
1477
|
+
/* import */ var _config_storage_constants_js__rspack_import_1 = __webpack_require__(188);
|
|
1478
|
+
function _ts_decorate(decorators, target, key, desc) {
|
|
1479
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
1480
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
|
|
1481
|
+
r = Reflect.decorate(decorators, target, key, desc);
|
|
1482
|
+
} else {
|
|
1483
|
+
for(var i = decorators.length - 1; i >= 0; i--){
|
|
1484
|
+
if (d = decorators[i]) {
|
|
1485
|
+
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
1486
|
+
}
|
|
1487
|
+
}
|
|
1488
|
+
}
|
|
1489
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
1490
|
+
}
|
|
1491
|
+
function _ts_metadata(metadataKey, metadataValue) {
|
|
1492
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
|
|
1493
|
+
return Reflect.metadata(metadataKey, metadataValue);
|
|
1494
|
+
}
|
|
1495
|
+
}
|
|
1496
|
+
function _ts_param(paramIndex, decorator) {
|
|
1497
|
+
return function(target, key) {
|
|
1498
|
+
decorator(target, key, paramIndex);
|
|
1499
|
+
};
|
|
1500
|
+
}
|
|
1501
|
+
|
|
1502
|
+
|
|
1503
|
+
|
|
1504
|
+
const BYTES_PER_MB = 1024 * 1024;
|
|
1505
|
+
const DEFAULT_LOCAL_PATH = './uploads';
|
|
1506
|
+
const DEFAULT_PORT = '3000';
|
|
1507
|
+
class StorageConfigService {
|
|
1508
|
+
options;
|
|
1509
|
+
constructor(options){
|
|
1510
|
+
this.options = options;
|
|
1511
|
+
}
|
|
1512
|
+
// ─── IModuleConfigService Implementation ────────────────────────────────────
|
|
1513
|
+
isCompanyFeatureEnabled() {
|
|
1514
|
+
return this.options.bootstrapAppConfig?.enableCompanyFeature ?? false;
|
|
1515
|
+
}
|
|
1516
|
+
getDatabaseMode() {
|
|
1517
|
+
return this.options.bootstrapAppConfig?.databaseMode ?? 'single';
|
|
1518
|
+
}
|
|
1519
|
+
isMultiTenant() {
|
|
1520
|
+
return this.getDatabaseMode() === 'multi-tenant';
|
|
1521
|
+
}
|
|
1522
|
+
// ─── Config Getters ─────────────────────────────────────────────────────────
|
|
1523
|
+
getMaxFileSize() {
|
|
1524
|
+
return this.options.config?.maxFileSize ?? _config_storage_constants_js__rspack_import_1/* .DEFAULT_MAX_FILE_SIZE */.Sj;
|
|
1525
|
+
}
|
|
1526
|
+
getAllowedFileTypes() {
|
|
1527
|
+
return this.options.config?.allowedFileTypes ?? _config_storage_constants_js__rspack_import_1/* .DEFAULT_ALLOWED_FILE_TYPES */.A_;
|
|
1528
|
+
}
|
|
1529
|
+
getOptions() {
|
|
1530
|
+
return this.options;
|
|
1531
|
+
}
|
|
1532
|
+
getDefaultLocalStoragePath() {
|
|
1533
|
+
return this.options.config?.localStoragePath ?? DEFAULT_LOCAL_PATH;
|
|
1534
|
+
}
|
|
1535
|
+
getAppUrl() {
|
|
1536
|
+
return this.options.config?.appUrl ?? process.env.APP_URL ?? `http://localhost:${process.env.PORT ?? DEFAULT_PORT}`;
|
|
1537
|
+
}
|
|
1538
|
+
// ─── Validation Methods ─────────────────────────────────────────────────────
|
|
1539
|
+
isFileTypeAllowed(mimeType) {
|
|
1540
|
+
const allowedTypes = this.getAllowedFileTypes();
|
|
1541
|
+
if (allowedTypes.includes('*/*')) {
|
|
1542
|
+
return true;
|
|
1543
|
+
}
|
|
1544
|
+
return allowedTypes.some((type)=>type.endsWith('/*') ? mimeType.startsWith(type.slice(0, -2)) : type === mimeType);
|
|
1545
|
+
}
|
|
1546
|
+
validateFileSize(fileSize) {
|
|
1547
|
+
const maxSize = this.getMaxFileSize();
|
|
1548
|
+
if (fileSize > maxSize) {
|
|
1549
|
+
return {
|
|
1550
|
+
valid: false,
|
|
1551
|
+
message: `File size (${this.toMB(fileSize)}MB) exceeds maximum ${this.toMB(maxSize)}MB`,
|
|
1552
|
+
messageKey: _config_index_js__rspack_import_2/* .UPLOAD_MESSAGES.FILE_TOO_LARGE */.dS.FILE_TOO_LARGE,
|
|
1553
|
+
messageVariables: {
|
|
1554
|
+
fileSize: this.toMB(fileSize),
|
|
1555
|
+
maxSize: this.toMB(maxSize)
|
|
1556
|
+
}
|
|
1557
|
+
};
|
|
1558
|
+
}
|
|
1559
|
+
return {
|
|
1560
|
+
valid: true
|
|
1561
|
+
};
|
|
1562
|
+
}
|
|
1563
|
+
validateFileType(mimeType) {
|
|
1564
|
+
if (!this.isFileTypeAllowed(mimeType)) {
|
|
1565
|
+
return {
|
|
1566
|
+
valid: false,
|
|
1567
|
+
message: `File type "${mimeType}" not allowed. Allowed: ${this.getAllowedFileTypes().join(', ')}`,
|
|
1568
|
+
messageKey: _config_index_js__rspack_import_2/* .UPLOAD_MESSAGES.INVALID_TYPE */.dS.INVALID_TYPE,
|
|
1569
|
+
messageVariables: {
|
|
1570
|
+
mimeType,
|
|
1571
|
+
allowedTypes: this.getAllowedFileTypes().join(', ')
|
|
1572
|
+
}
|
|
1573
|
+
};
|
|
1574
|
+
}
|
|
1575
|
+
return {
|
|
1576
|
+
valid: true
|
|
1577
|
+
};
|
|
1578
|
+
}
|
|
1579
|
+
// ─── Private Helpers ────────────────────────────────────────────────────────
|
|
1580
|
+
toMB(bytes) {
|
|
1581
|
+
return (bytes / BYTES_PER_MB).toFixed(2);
|
|
1582
|
+
}
|
|
1583
|
+
}
|
|
1584
|
+
StorageConfigService = _ts_decorate([
|
|
1585
|
+
(0,_nestjs_common__rspack_import_0.Injectable)(),
|
|
1586
|
+
_ts_param(0, (0,_nestjs_common__rspack_import_0.Inject)(_config_storage_constants_js__rspack_import_1/* .STORAGE_MODULE_OPTIONS */.k0)),
|
|
1587
|
+
_ts_metadata("design:type", Function),
|
|
1588
|
+
_ts_metadata("design:paramtypes", [
|
|
1589
|
+
typeof StorageModuleOptions === "undefined" ? Object : StorageModuleOptions
|
|
1590
|
+
])
|
|
1591
|
+
], StorageConfigService);
|
|
1592
|
+
|
|
1593
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
1594
|
+
t: () => (StorageConfigService)
|
|
1595
|
+
});
|
|
1596
|
+
|
|
1597
|
+
|
|
1598
|
+
},
|
|
1599
|
+
616(__unused_rspack_module, __webpack_exports__, __webpack_require__) {
|
|
1600
|
+
|
|
1601
|
+
// EXPORTS
|
|
1602
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
1603
|
+
M: () => (/* binding */ StorageDataSourceProvider)
|
|
1604
|
+
});
|
|
1605
|
+
|
|
1606
|
+
// EXTERNAL MODULE: external "@flusys/nestjs-shared/modules"
|
|
1607
|
+
var modules_ = __webpack_require__(236);
|
|
1608
|
+
// EXTERNAL MODULE: external "@nestjs/common"
|
|
1609
|
+
var common_ = __webpack_require__(157);
|
|
1610
|
+
;// CONCATENATED MODULE: external "@nestjs/core"
|
|
1611
|
+
|
|
1612
|
+
// EXTERNAL MODULE: ./projects/nestjs-storage/src/services/storage-config.service.ts
|
|
1613
|
+
var storage_config_service = __webpack_require__(397);
|
|
1614
|
+
;// CONCATENATED MODULE: ./projects/nestjs-storage/src/services/storage-datasource.provider.ts
|
|
1615
|
+
function _ts_decorate(decorators, target, key, desc) {
|
|
1616
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
1617
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
|
|
1618
|
+
r = Reflect.decorate(decorators, target, key, desc);
|
|
1619
|
+
} else {
|
|
1620
|
+
for(var i = decorators.length - 1; i >= 0; i--){
|
|
1621
|
+
if (d = decorators[i]) {
|
|
1622
|
+
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
1623
|
+
}
|
|
1624
|
+
}
|
|
1625
|
+
}
|
|
1626
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
1627
|
+
}
|
|
1628
|
+
function _ts_metadata(metadataKey, metadataValue) {
|
|
1629
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
|
|
1630
|
+
return Reflect.metadata(metadataKey, metadataValue);
|
|
1631
|
+
}
|
|
1632
|
+
}
|
|
1633
|
+
function _ts_param(paramIndex, decorator) {
|
|
1634
|
+
return function(target, key) {
|
|
1635
|
+
decorator(target, key, paramIndex);
|
|
1636
|
+
};
|
|
1637
|
+
}
|
|
1638
|
+
|
|
1639
|
+
|
|
1640
|
+
|
|
1641
|
+
|
|
1642
|
+
class StorageDataSourceProvider extends modules_.MultiTenantDataSourceService {
|
|
1643
|
+
configService;
|
|
1644
|
+
static tenantConnections = new Map();
|
|
1645
|
+
static singleDataSource = null;
|
|
1646
|
+
static tenantsRegistry = new Map();
|
|
1647
|
+
static initialized = false;
|
|
1648
|
+
static connectionLocks = new Map();
|
|
1649
|
+
static singleConnectionLock = null;
|
|
1650
|
+
constructor(configService, request){
|
|
1651
|
+
super(StorageDataSourceProvider.buildParentOptions(configService.getOptions()), request), this.configService = configService;
|
|
1652
|
+
}
|
|
1653
|
+
static buildParentOptions(options) {
|
|
1654
|
+
return {
|
|
1655
|
+
bootstrapAppConfig: options.bootstrapAppConfig,
|
|
1656
|
+
defaultDatabaseConfig: options.config?.defaultDatabaseConfig,
|
|
1657
|
+
tenantDefaultDatabaseConfig: options.config?.tenantDefaultDatabaseConfig,
|
|
1658
|
+
tenants: options.config?.tenants
|
|
1659
|
+
};
|
|
1660
|
+
}
|
|
1661
|
+
getEnableCompanyFeatureForTenant(tenant) {
|
|
1662
|
+
return tenant?.enableCompanyFeature ?? this.configService.isCompanyFeatureEnabled();
|
|
1663
|
+
}
|
|
1664
|
+
async getStorageEntities(enableCompanyFeature) {
|
|
1665
|
+
const enable = enableCompanyFeature ?? this.configService.isCompanyFeatureEnabled();
|
|
1666
|
+
const entities = await Promise.resolve(/* import() */).then(__webpack_require__.bind(__webpack_require__, 975));
|
|
1667
|
+
return enable ? [
|
|
1668
|
+
entities.FileManagerWithCompany,
|
|
1669
|
+
entities.FolderWithCompany,
|
|
1670
|
+
entities.StorageConfigWithCompany
|
|
1671
|
+
] : [
|
|
1672
|
+
entities.FileManager,
|
|
1673
|
+
entities.Folder,
|
|
1674
|
+
entities.StorageConfig
|
|
1675
|
+
];
|
|
1676
|
+
}
|
|
1677
|
+
async createDataSourceFromConfig(config) {
|
|
1678
|
+
const currentTenant = this.getCurrentTenant();
|
|
1679
|
+
const enableCompanyFeature = this.getEnableCompanyFeatureForTenant(currentTenant ?? undefined);
|
|
1680
|
+
const entities = await this.getStorageEntities(enableCompanyFeature);
|
|
1681
|
+
return super.createDataSourceFromConfig(config, entities);
|
|
1682
|
+
}
|
|
1683
|
+
}
|
|
1684
|
+
StorageDataSourceProvider = _ts_decorate([
|
|
1685
|
+
(0,common_.Injectable)({
|
|
1686
|
+
scope: common_.Scope.REQUEST
|
|
1687
|
+
}),
|
|
1688
|
+
_ts_param(0, (0,common_.Inject)(storage_config_service/* .StorageConfigService */.t)),
|
|
1689
|
+
_ts_param(1, (0,common_.Optional)()),
|
|
1690
|
+
_ts_param(1, (0,common_.Inject)(__rspack_external__nestjs_core_d7b00a1a.REQUEST)),
|
|
1691
|
+
_ts_metadata("design:type", Function),
|
|
1692
|
+
_ts_metadata("design:paramtypes", [
|
|
1693
|
+
typeof storage_config_service/* .StorageConfigService */.t === "undefined" ? Object : storage_config_service/* .StorageConfigService */.t,
|
|
1694
|
+
typeof Request === "undefined" ? Object : Request
|
|
1695
|
+
])
|
|
1696
|
+
], StorageDataSourceProvider);
|
|
1697
|
+
|
|
1698
|
+
|
|
1699
|
+
},
|
|
1700
|
+
623(__unused_rspack_module, __webpack_exports__, __webpack_require__) {
|
|
1701
|
+
/* import */ var _flusys_nestjs_shared_classes__rspack_import_0 = __webpack_require__(937);
|
|
1702
|
+
/* import */ var _flusys_nestjs_shared_modules__rspack_import_1 = __webpack_require__(236);
|
|
1703
|
+
/* import */ var _flusys_nestjs_shared_utils__rspack_import_2 = __webpack_require__(216);
|
|
1704
|
+
/* import */ var _nestjs_common__rspack_import_3 = __webpack_require__(157);
|
|
1705
|
+
/* import */ var typeorm__rspack_import_4 = __webpack_require__(158);
|
|
1706
|
+
/* import */ var _config_index_js__rspack_import_8 = __webpack_require__(884);
|
|
1707
|
+
/* import */ var _config_index_js__rspack_import_9 = __webpack_require__(450);
|
|
1708
|
+
/* import */ var _entities_index_js__rspack_import_5 = __webpack_require__(975);
|
|
1709
|
+
/* import */ var _storage_config_service_js__rspack_import_6 = __webpack_require__(397);
|
|
1710
|
+
/* import */ var _storage_datasource_provider_js__rspack_import_7 = __webpack_require__(616);
|
|
1711
|
+
function _ts_decorate(decorators, target, key, desc) {
|
|
1712
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
1713
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
|
|
1714
|
+
r = Reflect.decorate(decorators, target, key, desc);
|
|
1715
|
+
} else {
|
|
1716
|
+
for(var i = decorators.length - 1; i >= 0; i--){
|
|
1717
|
+
if (d = decorators[i]) {
|
|
1718
|
+
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
1719
|
+
}
|
|
1720
|
+
}
|
|
1721
|
+
}
|
|
1722
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
1723
|
+
}
|
|
1724
|
+
function _ts_metadata(metadataKey, metadataValue) {
|
|
1725
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
|
|
1726
|
+
return Reflect.metadata(metadataKey, metadataValue);
|
|
1727
|
+
}
|
|
1728
|
+
}
|
|
1729
|
+
function _ts_param(paramIndex, decorator) {
|
|
1730
|
+
return function(target, key) {
|
|
1731
|
+
decorator(target, key, paramIndex);
|
|
1732
|
+
};
|
|
1733
|
+
}
|
|
1734
|
+
|
|
1735
|
+
|
|
1736
|
+
|
|
1737
|
+
|
|
1738
|
+
|
|
1739
|
+
|
|
1740
|
+
|
|
1741
|
+
|
|
1742
|
+
|
|
1743
|
+
class StorageProviderConfigService extends _flusys_nestjs_shared_classes__rspack_import_0.ApiService {
|
|
1744
|
+
cacheManager;
|
|
1745
|
+
utilsService;
|
|
1746
|
+
storageConfig;
|
|
1747
|
+
constructor(cacheManager, utilsService, storageConfig, dataSourceProvider){
|
|
1748
|
+
super(_config_index_js__rspack_import_8/* .STORAGE_EVENT_ENTITIES.STORAGE_CONFIG */.fR.STORAGE_CONFIG, cacheManager, utilsService, StorageProviderConfigService.name, true, _config_index_js__rspack_import_8/* .STORAGE_EVENT_MODULE */.qh, dataSourceProvider, storageConfig.isCompanyFeatureEnabled() ? _entities_index_js__rspack_import_5.StorageConfigWithCompany : _entities_index_js__rspack_import_5.StorageConfig), this.cacheManager = cacheManager, this.utilsService = utilsService, this.storageConfig = storageConfig;
|
|
1749
|
+
}
|
|
1750
|
+
async beforeDeleteOperation(dto, _user, _queryRunner) {
|
|
1751
|
+
const ids = Array.isArray(dto.id) ? dto.id : [
|
|
1752
|
+
dto.id
|
|
1753
|
+
];
|
|
1754
|
+
await this.ensureDataSourceRepository();
|
|
1755
|
+
const defaultConfigs = await this.repository.find({
|
|
1756
|
+
where: {
|
|
1757
|
+
id: (0,typeorm__rspack_import_4.In)(ids),
|
|
1758
|
+
isDefault: true,
|
|
1759
|
+
deletedAt: (0,typeorm__rspack_import_4.IsNull)()
|
|
1760
|
+
}
|
|
1761
|
+
});
|
|
1762
|
+
if (defaultConfigs.length > 0) {
|
|
1763
|
+
const names = defaultConfigs.map((c)=>c.name).join(', ');
|
|
1764
|
+
throw new _nestjs_common__rspack_import_3.ForbiddenException({
|
|
1765
|
+
message: `Cannot delete the default storage config(s): ${names}. Set another config as default first.`,
|
|
1766
|
+
messageKey: _config_index_js__rspack_import_9/* .STORAGE_CONFIG_MESSAGES.DEFAULT_DELETE_FORBIDDEN */.Y8.DEFAULT_DELETE_FORBIDDEN,
|
|
1767
|
+
messageVariables: {
|
|
1768
|
+
names
|
|
1769
|
+
}
|
|
1770
|
+
});
|
|
1771
|
+
}
|
|
1772
|
+
}
|
|
1773
|
+
// ─── Override Methods ───────────────────────────────────────────────────────
|
|
1774
|
+
async convertSingleDtoToEntity(dto, user) {
|
|
1775
|
+
const entity = await super.convertSingleDtoToEntity(dto, user);
|
|
1776
|
+
if (this.storageConfig.isCompanyFeatureEnabled()) {
|
|
1777
|
+
entity.companyId = user?.companyId ?? null;
|
|
1778
|
+
}
|
|
1779
|
+
return entity;
|
|
1780
|
+
}
|
|
1781
|
+
async getSelectQuery(query, _user, select) {
|
|
1782
|
+
if (!select?.length) {
|
|
1783
|
+
select = [
|
|
1784
|
+
'id',
|
|
1785
|
+
'name',
|
|
1786
|
+
'storage',
|
|
1787
|
+
'config',
|
|
1788
|
+
'isActive',
|
|
1789
|
+
'isDefault',
|
|
1790
|
+
'createdAt',
|
|
1791
|
+
'updatedAt'
|
|
1792
|
+
];
|
|
1793
|
+
if (this.storageConfig.isCompanyFeatureEnabled()) {
|
|
1794
|
+
select.push('companyId');
|
|
1795
|
+
}
|
|
1796
|
+
}
|
|
1797
|
+
query.select(select.map((f)=>`${this.entityName}.${f}`));
|
|
1798
|
+
return {
|
|
1799
|
+
query,
|
|
1800
|
+
isRaw: false
|
|
1801
|
+
};
|
|
1802
|
+
}
|
|
1803
|
+
async getExtraManipulateQuery(query, filterDto, user) {
|
|
1804
|
+
const result = await super.getExtraManipulateQuery(query, filterDto, user);
|
|
1805
|
+
(0,_flusys_nestjs_shared_utils__rspack_import_2.applyCompanyFilter)(query, {
|
|
1806
|
+
isCompanyFeatureEnabled: this.storageConfig.isCompanyFeatureEnabled(),
|
|
1807
|
+
entityAlias: 'storageConfig'
|
|
1808
|
+
}, user);
|
|
1809
|
+
query.orderBy(`${this.entityName}.createdAt`, 'DESC');
|
|
1810
|
+
return result;
|
|
1811
|
+
}
|
|
1812
|
+
async findByIdDirect(id) {
|
|
1813
|
+
await this.ensureDataSourceRepository();
|
|
1814
|
+
return await this.repository.findOne({
|
|
1815
|
+
where: {
|
|
1816
|
+
id
|
|
1817
|
+
}
|
|
1818
|
+
});
|
|
1819
|
+
}
|
|
1820
|
+
async getDefaultConfig(user) {
|
|
1821
|
+
await this.ensureDataSourceRepository();
|
|
1822
|
+
const baseWhere = (0,_flusys_nestjs_shared_utils__rspack_import_2.buildCompanyWhereCondition)({
|
|
1823
|
+
isActive: true
|
|
1824
|
+
}, this.storageConfig.isCompanyFeatureEnabled(), user);
|
|
1825
|
+
const defaultConfig = await this.repository.findOne({
|
|
1826
|
+
where: {
|
|
1827
|
+
...baseWhere,
|
|
1828
|
+
isDefault: true
|
|
1829
|
+
},
|
|
1830
|
+
order: {
|
|
1831
|
+
createdAt: 'ASC'
|
|
1832
|
+
}
|
|
1833
|
+
});
|
|
1834
|
+
if (defaultConfig) {
|
|
1835
|
+
return defaultConfig;
|
|
1836
|
+
}
|
|
1837
|
+
return await this.repository.findOne({
|
|
1838
|
+
where: baseWhere,
|
|
1839
|
+
order: {
|
|
1840
|
+
createdAt: 'ASC'
|
|
1841
|
+
}
|
|
1842
|
+
});
|
|
1843
|
+
}
|
|
1844
|
+
async getConfigByType(storage, user) {
|
|
1845
|
+
await this.ensureDataSourceRepository();
|
|
1846
|
+
const where = (0,_flusys_nestjs_shared_utils__rspack_import_2.buildCompanyWhereCondition)({
|
|
1847
|
+
storage,
|
|
1848
|
+
isActive: true
|
|
1849
|
+
}, this.storageConfig.isCompanyFeatureEnabled(), user);
|
|
1850
|
+
return await this.repository.find({
|
|
1851
|
+
where
|
|
1852
|
+
});
|
|
1853
|
+
}
|
|
1854
|
+
}
|
|
1855
|
+
StorageProviderConfigService = _ts_decorate([
|
|
1856
|
+
(0,_nestjs_common__rspack_import_3.Injectable)({
|
|
1857
|
+
scope: _nestjs_common__rspack_import_3.Scope.REQUEST
|
|
1858
|
+
}),
|
|
1859
|
+
_ts_param(0, (0,_nestjs_common__rspack_import_3.Inject)('CACHE_INSTANCE')),
|
|
1860
|
+
_ts_param(1, (0,_nestjs_common__rspack_import_3.Inject)(_flusys_nestjs_shared_modules__rspack_import_1.UtilsService)),
|
|
1861
|
+
_ts_param(2, (0,_nestjs_common__rspack_import_3.Inject)(_storage_config_service_js__rspack_import_6/* .StorageConfigService */.t)),
|
|
1862
|
+
_ts_param(3, (0,_nestjs_common__rspack_import_3.Inject)(_storage_datasource_provider_js__rspack_import_7/* .StorageDataSourceProvider */.M)),
|
|
1863
|
+
_ts_metadata("design:type", Function),
|
|
1864
|
+
_ts_metadata("design:paramtypes", [
|
|
1865
|
+
typeof _flusys_nestjs_shared_classes__rspack_import_0.HybridCache === "undefined" ? Object : _flusys_nestjs_shared_classes__rspack_import_0.HybridCache,
|
|
1866
|
+
typeof _flusys_nestjs_shared_modules__rspack_import_1.UtilsService === "undefined" ? Object : _flusys_nestjs_shared_modules__rspack_import_1.UtilsService,
|
|
1867
|
+
typeof _storage_config_service_js__rspack_import_6/* .StorageConfigService */.t === "undefined" ? Object : _storage_config_service_js__rspack_import_6/* .StorageConfigService */.t,
|
|
1868
|
+
typeof _storage_datasource_provider_js__rspack_import_7/* .StorageDataSourceProvider */.M === "undefined" ? Object : _storage_datasource_provider_js__rspack_import_7/* .StorageDataSourceProvider */.M
|
|
1869
|
+
])
|
|
1870
|
+
], StorageProviderConfigService);
|
|
1871
|
+
|
|
1872
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
1873
|
+
o: () => (StorageProviderConfigService)
|
|
1874
|
+
});
|
|
1875
|
+
|
|
1876
|
+
|
|
1877
|
+
},
|
|
1878
|
+
18(__unused_rspack_module, __webpack_exports__, __webpack_require__) {
|
|
1879
|
+
|
|
1880
|
+
// EXPORTS
|
|
1881
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
1882
|
+
B: () => (/* binding */ UploadService)
|
|
1883
|
+
});
|
|
1884
|
+
|
|
1885
|
+
// EXTERNAL MODULE: external "@flusys/nestjs-shared"
|
|
1886
|
+
var nestjs_shared_ = __webpack_require__(422);
|
|
1887
|
+
// EXTERNAL MODULE: external "@flusys/nestjs-shared/classes"
|
|
1888
|
+
var classes_ = __webpack_require__(937);
|
|
1889
|
+
// EXTERNAL MODULE: external "@flusys/nestjs-shared/utils"
|
|
1890
|
+
var utils_ = __webpack_require__(216);
|
|
1891
|
+
// EXTERNAL MODULE: external "@nestjs/common"
|
|
1892
|
+
var common_ = __webpack_require__(157);
|
|
1893
|
+
// EXTERNAL MODULE: ./projects/nestjs-storage/src/config/message-keys.ts
|
|
1894
|
+
var message_keys = __webpack_require__(450);
|
|
1895
|
+
// EXTERNAL MODULE: ./projects/nestjs-storage/src/config/event-actions.ts
|
|
1896
|
+
var event_actions = __webpack_require__(884);
|
|
1897
|
+
// EXTERNAL MODULE: ./projects/nestjs-storage/src/dtos/upload.dto.ts
|
|
1898
|
+
var upload_dto = __webpack_require__(322);
|
|
1899
|
+
// EXTERNAL MODULE: ./projects/nestjs-storage/src/enums/file-location.enum.ts
|
|
1900
|
+
var file_location_enum = __webpack_require__(733);
|
|
1901
|
+
// EXTERNAL MODULE: ./projects/nestjs-storage/src/providers/storage-factory.service.ts + 1 modules
|
|
1902
|
+
var storage_factory_service = __webpack_require__(192);
|
|
1903
|
+
;// CONCATENATED MODULE: ./projects/nestjs-storage/src/utils/file-validator.util.ts
|
|
1904
|
+
/**
|
|
1905
|
+
* Result of file content validation.
|
|
1906
|
+
*/ /**
|
|
1907
|
+
* Magic byte signatures for common file types.
|
|
1908
|
+
* Each entry maps a hex signature pattern to its MIME type.
|
|
1909
|
+
*/ const MAGIC_BYTES = [
|
|
1910
|
+
// Images
|
|
1911
|
+
{
|
|
1912
|
+
signature: [
|
|
1913
|
+
0xff,
|
|
1914
|
+
0xd8,
|
|
1915
|
+
0xff
|
|
1916
|
+
],
|
|
1917
|
+
offset: 0,
|
|
1918
|
+
mimeType: 'image/jpeg'
|
|
1919
|
+
},
|
|
1920
|
+
{
|
|
1921
|
+
signature: [
|
|
1922
|
+
0x89,
|
|
1923
|
+
0x50,
|
|
1924
|
+
0x4e,
|
|
1925
|
+
0x47,
|
|
1926
|
+
0x0d,
|
|
1927
|
+
0x0a,
|
|
1928
|
+
0x1a,
|
|
1929
|
+
0x0a
|
|
1930
|
+
],
|
|
1931
|
+
offset: 0,
|
|
1932
|
+
mimeType: 'image/png'
|
|
1933
|
+
},
|
|
1934
|
+
{
|
|
1935
|
+
signature: [
|
|
1936
|
+
0x47,
|
|
1937
|
+
0x49,
|
|
1938
|
+
0x46,
|
|
1939
|
+
0x38,
|
|
1940
|
+
0x37,
|
|
1941
|
+
0x61
|
|
1942
|
+
],
|
|
1943
|
+
offset: 0,
|
|
1944
|
+
mimeType: 'image/gif'
|
|
1945
|
+
},
|
|
1946
|
+
{
|
|
1947
|
+
signature: [
|
|
1948
|
+
0x47,
|
|
1949
|
+
0x49,
|
|
1950
|
+
0x46,
|
|
1951
|
+
0x38,
|
|
1952
|
+
0x39,
|
|
1953
|
+
0x61
|
|
1954
|
+
],
|
|
1955
|
+
offset: 0,
|
|
1956
|
+
mimeType: 'image/gif'
|
|
1957
|
+
},
|
|
1958
|
+
{
|
|
1959
|
+
signature: [
|
|
1960
|
+
0x42,
|
|
1961
|
+
0x4d
|
|
1962
|
+
],
|
|
1963
|
+
offset: 0,
|
|
1964
|
+
mimeType: 'image/bmp'
|
|
1965
|
+
},
|
|
1966
|
+
{
|
|
1967
|
+
signature: [
|
|
1968
|
+
0x52,
|
|
1969
|
+
0x49,
|
|
1970
|
+
0x46,
|
|
1971
|
+
0x46
|
|
1972
|
+
],
|
|
1973
|
+
offset: 0,
|
|
1974
|
+
mimeType: 'image/webp'
|
|
1975
|
+
},
|
|
1976
|
+
{
|
|
1977
|
+
signature: [
|
|
1978
|
+
0x00,
|
|
1979
|
+
0x00,
|
|
1980
|
+
0x01,
|
|
1981
|
+
0x00
|
|
1982
|
+
],
|
|
1983
|
+
offset: 0,
|
|
1984
|
+
mimeType: 'image/x-icon'
|
|
1985
|
+
},
|
|
1986
|
+
{
|
|
1987
|
+
signature: [
|
|
1988
|
+
0x00,
|
|
1989
|
+
0x00,
|
|
1990
|
+
0x02,
|
|
1991
|
+
0x00
|
|
1992
|
+
],
|
|
1993
|
+
offset: 0,
|
|
1994
|
+
mimeType: 'image/x-icon'
|
|
1995
|
+
},
|
|
1996
|
+
// Documents
|
|
1997
|
+
{
|
|
1998
|
+
signature: [
|
|
1999
|
+
0x25,
|
|
2000
|
+
0x50,
|
|
2001
|
+
0x44,
|
|
2002
|
+
0x46
|
|
2003
|
+
],
|
|
2004
|
+
offset: 0,
|
|
2005
|
+
mimeType: 'application/pdf'
|
|
2006
|
+
},
|
|
2007
|
+
{
|
|
2008
|
+
signature: [
|
|
2009
|
+
0x50,
|
|
2010
|
+
0x4b,
|
|
2011
|
+
0x03,
|
|
2012
|
+
0x04
|
|
2013
|
+
],
|
|
2014
|
+
offset: 0,
|
|
2015
|
+
mimeType: 'application/zip'
|
|
2016
|
+
},
|
|
2017
|
+
// Audio
|
|
2018
|
+
{
|
|
2019
|
+
signature: [
|
|
2020
|
+
0x49,
|
|
2021
|
+
0x44,
|
|
2022
|
+
0x33
|
|
2023
|
+
],
|
|
2024
|
+
offset: 0,
|
|
2025
|
+
mimeType: 'audio/mpeg'
|
|
2026
|
+
},
|
|
2027
|
+
{
|
|
2028
|
+
signature: [
|
|
2029
|
+
0xff,
|
|
2030
|
+
0xfb
|
|
2031
|
+
],
|
|
2032
|
+
offset: 0,
|
|
2033
|
+
mimeType: 'audio/mpeg'
|
|
2034
|
+
},
|
|
2035
|
+
{
|
|
2036
|
+
signature: [
|
|
2037
|
+
0xff,
|
|
2038
|
+
0xfa
|
|
2039
|
+
],
|
|
2040
|
+
offset: 0,
|
|
2041
|
+
mimeType: 'audio/mpeg'
|
|
2042
|
+
},
|
|
2043
|
+
{
|
|
2044
|
+
signature: [
|
|
2045
|
+
0x4f,
|
|
2046
|
+
0x67,
|
|
2047
|
+
0x67,
|
|
2048
|
+
0x53
|
|
2049
|
+
],
|
|
2050
|
+
offset: 0,
|
|
2051
|
+
mimeType: 'audio/ogg'
|
|
2052
|
+
},
|
|
2053
|
+
{
|
|
2054
|
+
signature: [
|
|
2055
|
+
0x66,
|
|
2056
|
+
0x4c,
|
|
2057
|
+
0x61,
|
|
2058
|
+
0x43
|
|
2059
|
+
],
|
|
2060
|
+
offset: 0,
|
|
2061
|
+
mimeType: 'audio/flac'
|
|
2062
|
+
},
|
|
2063
|
+
// Video
|
|
2064
|
+
{
|
|
2065
|
+
signature: [
|
|
2066
|
+
0x00,
|
|
2067
|
+
0x00,
|
|
2068
|
+
0x00,
|
|
2069
|
+
0x1c,
|
|
2070
|
+
0x66,
|
|
2071
|
+
0x74,
|
|
2072
|
+
0x79,
|
|
2073
|
+
0x70
|
|
2074
|
+
],
|
|
2075
|
+
offset: 0,
|
|
2076
|
+
mimeType: 'video/mp4'
|
|
2077
|
+
},
|
|
2078
|
+
{
|
|
2079
|
+
signature: [
|
|
2080
|
+
0x00,
|
|
2081
|
+
0x00,
|
|
2082
|
+
0x00,
|
|
2083
|
+
0x20,
|
|
2084
|
+
0x66,
|
|
2085
|
+
0x74,
|
|
2086
|
+
0x79,
|
|
2087
|
+
0x70
|
|
2088
|
+
],
|
|
2089
|
+
offset: 0,
|
|
2090
|
+
mimeType: 'video/mp4'
|
|
2091
|
+
},
|
|
2092
|
+
{
|
|
2093
|
+
signature: [
|
|
2094
|
+
0x1a,
|
|
2095
|
+
0x45,
|
|
2096
|
+
0xdf,
|
|
2097
|
+
0xa3
|
|
2098
|
+
],
|
|
2099
|
+
offset: 0,
|
|
2100
|
+
mimeType: 'video/webm'
|
|
2101
|
+
},
|
|
2102
|
+
{
|
|
2103
|
+
signature: [
|
|
2104
|
+
0x52,
|
|
2105
|
+
0x49,
|
|
2106
|
+
0x46,
|
|
2107
|
+
0x46
|
|
2108
|
+
],
|
|
2109
|
+
offset: 0,
|
|
2110
|
+
mimeType: 'video/avi'
|
|
2111
|
+
},
|
|
2112
|
+
// Archives
|
|
2113
|
+
{
|
|
2114
|
+
signature: [
|
|
2115
|
+
0x1f,
|
|
2116
|
+
0x8b
|
|
2117
|
+
],
|
|
2118
|
+
offset: 0,
|
|
2119
|
+
mimeType: 'application/gzip'
|
|
2120
|
+
},
|
|
2121
|
+
{
|
|
2122
|
+
signature: [
|
|
2123
|
+
0x37,
|
|
2124
|
+
0x7a,
|
|
2125
|
+
0xbc,
|
|
2126
|
+
0xaf,
|
|
2127
|
+
0x27,
|
|
2128
|
+
0x1c
|
|
2129
|
+
],
|
|
2130
|
+
offset: 0,
|
|
2131
|
+
mimeType: 'application/x-7z-compressed'
|
|
2132
|
+
},
|
|
2133
|
+
{
|
|
2134
|
+
signature: [
|
|
2135
|
+
0x52,
|
|
2136
|
+
0x61,
|
|
2137
|
+
0x72,
|
|
2138
|
+
0x21,
|
|
2139
|
+
0x1a,
|
|
2140
|
+
0x07
|
|
2141
|
+
],
|
|
2142
|
+
offset: 0,
|
|
2143
|
+
mimeType: 'application/x-rar-compressed'
|
|
2144
|
+
}
|
|
2145
|
+
];
|
|
2146
|
+
/**
|
|
2147
|
+
* MIME type aliases - types that are equivalent.
|
|
2148
|
+
*/ const MIME_ALIASES = {
|
|
2149
|
+
'image/jpeg': [
|
|
2150
|
+
'image/jpg'
|
|
2151
|
+
],
|
|
2152
|
+
'image/jpg': [
|
|
2153
|
+
'image/jpeg'
|
|
2154
|
+
],
|
|
2155
|
+
'video/mp4': [
|
|
2156
|
+
'video/quicktime'
|
|
2157
|
+
],
|
|
2158
|
+
'application/zip': [
|
|
2159
|
+
'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
|
|
2160
|
+
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
|
|
2161
|
+
'application/vnd.openxmlformats-officedocument.presentationml.presentation'
|
|
2162
|
+
]
|
|
2163
|
+
};
|
|
2164
|
+
/**
|
|
2165
|
+
* File types that are text-based and don't have magic bytes.
|
|
2166
|
+
* SECURITY NOTE: Dangerous types (HTML, JS, SVG) are excluded as they can contain scripts.
|
|
2167
|
+
* These types require explicit allowlisting and additional content scanning.
|
|
2168
|
+
*/ const TEXT_BASED_TYPES = [
|
|
2169
|
+
'text/plain',
|
|
2170
|
+
'text/csv',
|
|
2171
|
+
'text/markdown',
|
|
2172
|
+
'application/json',
|
|
2173
|
+
'application/xml',
|
|
2174
|
+
'application/typescript',
|
|
2175
|
+
'text/css'
|
|
2176
|
+
];
|
|
2177
|
+
/**
|
|
2178
|
+
* Dangerous text-based types that can execute scripts.
|
|
2179
|
+
* These bypass magic-bytes validation but require explicit allowlisting.
|
|
2180
|
+
*/ const DANGEROUS_TEXT_TYPES = [
|
|
2181
|
+
'text/html',
|
|
2182
|
+
'application/javascript',
|
|
2183
|
+
'text/javascript',
|
|
2184
|
+
'image/svg+xml',
|
|
2185
|
+
'application/xhtml+xml'
|
|
2186
|
+
];
|
|
2187
|
+
/**
|
|
2188
|
+
* ZIP-based format prefixes that are valid when detected as application/zip.
|
|
2189
|
+
*/ const ZIP_VARIANT_PREFIXES = [
|
|
2190
|
+
'application/vnd.openxmlformats-officedocument',
|
|
2191
|
+
'application/x-zip',
|
|
2192
|
+
'application/x-compressed'
|
|
2193
|
+
];
|
|
2194
|
+
/**
|
|
2195
|
+
* Utility class for validating file content using magic bytes.
|
|
2196
|
+
* Prevents file type spoofing by checking actual file content.
|
|
2197
|
+
*/ class FileValidator {
|
|
2198
|
+
// Result Helpers
|
|
2199
|
+
static failureResult(message, detectedType, declaredType) {
|
|
2200
|
+
return {
|
|
2201
|
+
valid: false,
|
|
2202
|
+
detectedType,
|
|
2203
|
+
declaredType,
|
|
2204
|
+
message
|
|
2205
|
+
};
|
|
2206
|
+
}
|
|
2207
|
+
static successResult(detectedType, declaredType) {
|
|
2208
|
+
return {
|
|
2209
|
+
valid: true,
|
|
2210
|
+
detectedType,
|
|
2211
|
+
declaredType
|
|
2212
|
+
};
|
|
2213
|
+
}
|
|
2214
|
+
/**
|
|
2215
|
+
* Detect file type from buffer using magic bytes.
|
|
2216
|
+
* @param buffer - File buffer to analyze
|
|
2217
|
+
* @returns Detected MIME type or null if unknown
|
|
2218
|
+
*/ static detectFileType(buffer) {
|
|
2219
|
+
for (const { signature, offset, mimeType } of MAGIC_BYTES){
|
|
2220
|
+
if (buffer.length < offset + signature.length) continue;
|
|
2221
|
+
let matches = true;
|
|
2222
|
+
for(let i = 0; i < signature.length; i++){
|
|
2223
|
+
if (buffer[offset + i] !== signature[i]) {
|
|
2224
|
+
matches = false;
|
|
2225
|
+
break;
|
|
2226
|
+
}
|
|
2227
|
+
}
|
|
2228
|
+
if (matches) {
|
|
2229
|
+
return mimeType;
|
|
2230
|
+
}
|
|
2231
|
+
}
|
|
2232
|
+
return null;
|
|
2233
|
+
}
|
|
2234
|
+
/**
|
|
2235
|
+
* Check if a MIME type is text-based (doesn't have magic bytes).
|
|
2236
|
+
*/ static isTextBasedType(mimeType) {
|
|
2237
|
+
return TEXT_BASED_TYPES.some((t)=>mimeType.startsWith(t) || mimeType === t);
|
|
2238
|
+
}
|
|
2239
|
+
/**
|
|
2240
|
+
* Check if a MIME type is a dangerous text type that can execute scripts.
|
|
2241
|
+
*/ static isDangerousTextType(mimeType) {
|
|
2242
|
+
return DANGEROUS_TEXT_TYPES.some((t)=>mimeType === t);
|
|
2243
|
+
}
|
|
2244
|
+
/**
|
|
2245
|
+
* Check if two MIME types are compatible (exact match or aliases).
|
|
2246
|
+
*/ static mimeTypesMatch(detected, declared) {
|
|
2247
|
+
// Exact match
|
|
2248
|
+
if (detected === declared) return true;
|
|
2249
|
+
// Check aliases
|
|
2250
|
+
const aliases = MIME_ALIASES[detected];
|
|
2251
|
+
if (aliases?.includes(declared)) return true;
|
|
2252
|
+
// Check reverse aliases
|
|
2253
|
+
const reverseAliases = MIME_ALIASES[declared];
|
|
2254
|
+
if (reverseAliases?.includes(detected)) return true;
|
|
2255
|
+
// Check if both are in same category (e.g., both images)
|
|
2256
|
+
const detectedCategory = detected.split('/')[0];
|
|
2257
|
+
const declaredCategory = declared.split('/')[0];
|
|
2258
|
+
// For ZIP-based formats, allow any ZIP-detected file if declared is a ZIP variant
|
|
2259
|
+
if (detected === 'application/zip' && ZIP_VARIANT_PREFIXES.some((v)=>declared.startsWith(v))) {
|
|
2260
|
+
return true;
|
|
2261
|
+
}
|
|
2262
|
+
return detectedCategory === declaredCategory;
|
|
2263
|
+
}
|
|
2264
|
+
/**
|
|
2265
|
+
* Check if a MIME type is in the allowed list.
|
|
2266
|
+
*/ static isTypeAllowed(mimeType, allowedTypes) {
|
|
2267
|
+
// Wildcard allows all
|
|
2268
|
+
if (allowedTypes.includes('*/*')) return true;
|
|
2269
|
+
return allowedTypes.some((allowed)=>{
|
|
2270
|
+
// Category wildcard (e.g., "image/*")
|
|
2271
|
+
if (allowed.endsWith('/*')) {
|
|
2272
|
+
const category = allowed.slice(0, -2);
|
|
2273
|
+
return mimeType.startsWith(category);
|
|
2274
|
+
}
|
|
2275
|
+
return allowed === mimeType;
|
|
2276
|
+
});
|
|
2277
|
+
}
|
|
2278
|
+
/**
|
|
2279
|
+
* Validate file content matches declared MIME type using magic bytes.
|
|
2280
|
+
* @param buffer - File buffer
|
|
2281
|
+
* @param declaredMimeType - MIME type declared by client
|
|
2282
|
+
* @param allowedTypes - List of allowed MIME types/patterns
|
|
2283
|
+
* @returns Validation result
|
|
2284
|
+
*/ static validateFileContent(buffer, declaredMimeType, allowedTypes = [
|
|
2285
|
+
'*/*'
|
|
2286
|
+
]) {
|
|
2287
|
+
try {
|
|
2288
|
+
const detectedType = this.detectFileType(buffer);
|
|
2289
|
+
// No magic bytes detected - handle text-based types
|
|
2290
|
+
if (!detectedType) {
|
|
2291
|
+
return this.validateUndetectedType(declaredMimeType, allowedTypes);
|
|
2292
|
+
}
|
|
2293
|
+
// Verify detected type matches declared type
|
|
2294
|
+
if (!this.mimeTypesMatch(detectedType, declaredMimeType)) {
|
|
2295
|
+
return this.failureResult(`File content does not match declared type. Detected: ${detectedType}, Declared: ${declaredMimeType}`, detectedType, declaredMimeType);
|
|
2296
|
+
}
|
|
2297
|
+
// Verify type is in allowed list
|
|
2298
|
+
if (!this.isTypeAllowed(detectedType, allowedTypes)) {
|
|
2299
|
+
return this.failureResult(`File type "${detectedType}" is not allowed`, detectedType, declaredMimeType);
|
|
2300
|
+
}
|
|
2301
|
+
return this.successResult(detectedType, declaredMimeType);
|
|
2302
|
+
} catch {
|
|
2303
|
+
return this.failureResult('File validation failed');
|
|
2304
|
+
}
|
|
2305
|
+
}
|
|
2306
|
+
/**
|
|
2307
|
+
* Handle validation for files without detectable magic bytes.
|
|
2308
|
+
*/ static validateUndetectedType(declaredMimeType, allowedTypes) {
|
|
2309
|
+
// Check for dangerous text types first (HTML, JS, SVG)
|
|
2310
|
+
if (this.isDangerousTextType(declaredMimeType)) {
|
|
2311
|
+
const explicitlyAllowed = allowedTypes.some((t)=>t === declaredMimeType && t !== '*/*' && !t.endsWith('/*'));
|
|
2312
|
+
if (!explicitlyAllowed) {
|
|
2313
|
+
return this.failureResult(`File type "${declaredMimeType}" is potentially dangerous and not explicitly allowed`, declaredMimeType, declaredMimeType);
|
|
2314
|
+
}
|
|
2315
|
+
}
|
|
2316
|
+
// Safe text-based files don't have magic bytes, trust declared type
|
|
2317
|
+
if (this.isTextBasedType(declaredMimeType)) {
|
|
2318
|
+
const isAllowed = this.isTypeAllowed(declaredMimeType, allowedTypes);
|
|
2319
|
+
return isAllowed ? this.successResult(declaredMimeType, declaredMimeType) : this.failureResult(`File type "${declaredMimeType}" is not allowed`, declaredMimeType, declaredMimeType);
|
|
2320
|
+
}
|
|
2321
|
+
// Binary files without recognized signatures - be cautious
|
|
2322
|
+
return this.failureResult('Unable to verify file type. File may be corrupted or unsupported.', undefined, declaredMimeType);
|
|
2323
|
+
}
|
|
2324
|
+
/**
|
|
2325
|
+
* Sanitize filename to prevent path traversal and special character issues.
|
|
2326
|
+
* @param filename - Original filename
|
|
2327
|
+
* @returns Sanitized filename
|
|
2328
|
+
*/ static sanitizeFilename(filename) {
|
|
2329
|
+
return filename// Remove path components (prevent traversal)
|
|
2330
|
+
.replace(/^.*[\\/]/, '')// Remove null bytes
|
|
2331
|
+
.replace(/\0/g, '')// Replace multiple dots with single
|
|
2332
|
+
.replace(/\.{2,}/g, '.')// Remove special characters except allowed ones
|
|
2333
|
+
.replace(/[^a-zA-Z0-9._-]/g, '_')// Limit length
|
|
2334
|
+
.substring(0, 255);
|
|
2335
|
+
}
|
|
2336
|
+
}
|
|
2337
|
+
|
|
2338
|
+
// EXTERNAL MODULE: ./projects/nestjs-storage/src/services/storage-config.service.ts
|
|
2339
|
+
var storage_config_service = __webpack_require__(397);
|
|
2340
|
+
// EXTERNAL MODULE: ./projects/nestjs-storage/src/services/storage-provider-config.service.ts
|
|
2341
|
+
var storage_provider_config_service = __webpack_require__(623);
|
|
2342
|
+
;// CONCATENATED MODULE: ./projects/nestjs-storage/src/services/upload.service.ts
|
|
2343
|
+
function _ts_decorate(decorators, target, key, desc) {
|
|
2344
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
2345
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
|
|
2346
|
+
r = Reflect.decorate(decorators, target, key, desc);
|
|
2347
|
+
} else {
|
|
2348
|
+
for(var i = decorators.length - 1; i >= 0; i--){
|
|
2349
|
+
if (d = decorators[i]) {
|
|
2350
|
+
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
2351
|
+
}
|
|
2352
|
+
}
|
|
2353
|
+
}
|
|
2354
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
2355
|
+
}
|
|
2356
|
+
function _ts_metadata(metadataKey, metadataValue) {
|
|
2357
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
|
|
2358
|
+
return Reflect.metadata(metadataKey, metadataValue);
|
|
2359
|
+
}
|
|
2360
|
+
}
|
|
2361
|
+
function _ts_param(paramIndex, decorator) {
|
|
2362
|
+
return function(target, key) {
|
|
2363
|
+
decorator(target, key, paramIndex);
|
|
2364
|
+
};
|
|
2365
|
+
}
|
|
2366
|
+
|
|
2367
|
+
|
|
2368
|
+
|
|
2369
|
+
|
|
2370
|
+
|
|
2371
|
+
|
|
2372
|
+
|
|
2373
|
+
|
|
2374
|
+
|
|
2375
|
+
|
|
2376
|
+
|
|
2377
|
+
class UploadService {
|
|
2378
|
+
storageFactory;
|
|
2379
|
+
storageConfigService;
|
|
2380
|
+
storageProviderConfigService;
|
|
2381
|
+
// NOTE: @Inject() required for bundled code - type metadata may be lost during esbuild
|
|
2382
|
+
constructor(storageFactory, storageConfigService, storageProviderConfigService){
|
|
2383
|
+
this.storageFactory = storageFactory;
|
|
2384
|
+
this.storageConfigService = storageConfigService;
|
|
2385
|
+
this.storageProviderConfigService = storageProviderConfigService;
|
|
2386
|
+
}
|
|
2387
|
+
/**
|
|
2388
|
+
* Validate file before upload - includes size, type, and content validation.
|
|
2389
|
+
* Uses magic bytes to verify file content matches declared MIME type.
|
|
2390
|
+
*/ validateFile(file) {
|
|
2391
|
+
// Validate file size
|
|
2392
|
+
const sizeValidation = this.storageConfigService.validateFileSize(file.size);
|
|
2393
|
+
if (!sizeValidation.valid) {
|
|
2394
|
+
throw new common_.BadRequestException({
|
|
2395
|
+
message: sizeValidation.message,
|
|
2396
|
+
messageKey: sizeValidation.messageKey,
|
|
2397
|
+
messageVariables: sizeValidation.messageVariables
|
|
2398
|
+
});
|
|
2399
|
+
}
|
|
2400
|
+
// Validate declared file type (MIME)
|
|
2401
|
+
const typeValidation = this.storageConfigService.validateFileType(file.mimetype);
|
|
2402
|
+
if (!typeValidation.valid) {
|
|
2403
|
+
throw new common_.BadRequestException({
|
|
2404
|
+
message: typeValidation.message,
|
|
2405
|
+
messageKey: typeValidation.messageKey,
|
|
2406
|
+
messageVariables: typeValidation.messageVariables
|
|
2407
|
+
});
|
|
2408
|
+
}
|
|
2409
|
+
// Validate file content matches declared type (magic bytes check)
|
|
2410
|
+
// This prevents MIME type spoofing attacks
|
|
2411
|
+
const allowedTypes = this.storageConfigService.getAllowedFileTypes();
|
|
2412
|
+
const contentValidation = FileValidator.validateFileContent(file.buffer, file.mimetype, allowedTypes);
|
|
2413
|
+
if (!contentValidation.valid) {
|
|
2414
|
+
throw new common_.BadRequestException({
|
|
2415
|
+
message: contentValidation.message || 'File content validation failed',
|
|
2416
|
+
messageKey: message_keys/* .UPLOAD_MESSAGES.INVALID_TYPE */.dS.INVALID_TYPE,
|
|
2417
|
+
messageVariables: {
|
|
2418
|
+
mimeType: file.mimetype,
|
|
2419
|
+
allowedTypes: allowedTypes.join(', ')
|
|
2420
|
+
}
|
|
2421
|
+
});
|
|
2422
|
+
}
|
|
2423
|
+
// Sanitize filename to prevent path traversal attacks
|
|
2424
|
+
file.originalname = FileValidator.sanitizeFilename(file.originalname);
|
|
2425
|
+
}
|
|
2426
|
+
/**
|
|
2427
|
+
* Create provider from storage config entity
|
|
2428
|
+
*/ async createProviderFromConfig(config) {
|
|
2429
|
+
return this.storageFactory.createProvider({
|
|
2430
|
+
provider: config.storage,
|
|
2431
|
+
config: config.config
|
|
2432
|
+
});
|
|
2433
|
+
}
|
|
2434
|
+
/**
|
|
2435
|
+
* Create fallback local provider
|
|
2436
|
+
*/ async createFallbackLocalProvider() {
|
|
2437
|
+
return this.storageFactory.createProvider({
|
|
2438
|
+
provider: file_location_enum/* .FileLocationEnum.LOCAL */.N.LOCAL,
|
|
2439
|
+
config: {
|
|
2440
|
+
basePath: this.storageConfigService.getDefaultLocalStoragePath()
|
|
2441
|
+
}
|
|
2442
|
+
});
|
|
2443
|
+
}
|
|
2444
|
+
/**
|
|
2445
|
+
* Get storage provider and config info based on storage config ID
|
|
2446
|
+
* Validates company ownership when company feature is enabled
|
|
2447
|
+
*/ async getStorageProviderWithConfig(storageConfigId, user) {
|
|
2448
|
+
let storageConfig;
|
|
2449
|
+
// Get storage config from database
|
|
2450
|
+
if (storageConfigId) {
|
|
2451
|
+
// Use direct lookup (bypasses company filtering, returns null instead of throwing)
|
|
2452
|
+
const config = await this.storageProviderConfigService.findByIdDirect(storageConfigId);
|
|
2453
|
+
if (!config) {
|
|
2454
|
+
throw new common_.NotFoundException({
|
|
2455
|
+
message: 'Storage configuration not found',
|
|
2456
|
+
messageKey: message_keys/* .UPLOAD_MESSAGES.CONFIG_NOT_FOUND */.dS.CONFIG_NOT_FOUND
|
|
2457
|
+
});
|
|
2458
|
+
}
|
|
2459
|
+
// Validate company ownership using shared utility
|
|
2460
|
+
(0,utils_.validateCompanyOwnership)(config, user, this.storageConfigService.isCompanyFeatureEnabled(), 'Storage configuration');
|
|
2461
|
+
storageConfig = config;
|
|
2462
|
+
} else {
|
|
2463
|
+
// Use default config (scoped to user's company/branch)
|
|
2464
|
+
const defaultConfig = await this.storageProviderConfigService.getDefaultConfig(user);
|
|
2465
|
+
if (!defaultConfig) {
|
|
2466
|
+
throw new common_.NotFoundException({
|
|
2467
|
+
message: 'No default storage configuration found for your company/branch. Please create one.',
|
|
2468
|
+
messageKey: message_keys/* .UPLOAD_MESSAGES.CONFIG_NOT_FOUND */.dS.CONFIG_NOT_FOUND
|
|
2469
|
+
});
|
|
2470
|
+
}
|
|
2471
|
+
storageConfig = defaultConfig;
|
|
2472
|
+
}
|
|
2473
|
+
const provider = await this.createProviderFromConfig(storageConfig);
|
|
2474
|
+
return {
|
|
2475
|
+
provider,
|
|
2476
|
+
location: storageConfig.storage,
|
|
2477
|
+
configId: storageConfig.id
|
|
2478
|
+
};
|
|
2479
|
+
}
|
|
2480
|
+
/**
|
|
2481
|
+
* Get storage provider for delete operations with fallback
|
|
2482
|
+
* If the original storage config doesn't exist, falls back based on locationHint
|
|
2483
|
+
*/ async getStorageProviderForDelete(storageConfigId, user, locationHint) {
|
|
2484
|
+
// Try to find by storageConfigId
|
|
2485
|
+
if (storageConfigId) {
|
|
2486
|
+
const config = await this.storageProviderConfigService.findByIdDirect(storageConfigId);
|
|
2487
|
+
if (config) {
|
|
2488
|
+
return this.createProviderFromConfig(config);
|
|
2489
|
+
}
|
|
2490
|
+
}
|
|
2491
|
+
// Fallback: Use locationHint to find a matching config
|
|
2492
|
+
if (locationHint) {
|
|
2493
|
+
const matchingConfigs = await this.storageProviderConfigService.getConfigByType(locationHint, user);
|
|
2494
|
+
if (matchingConfigs.length > 0) {
|
|
2495
|
+
return this.createProviderFromConfig(matchingConfigs[0]);
|
|
2496
|
+
}
|
|
2497
|
+
if (locationHint === file_location_enum/* .FileLocationEnum.LOCAL */.N.LOCAL) {
|
|
2498
|
+
return this.createFallbackLocalProvider();
|
|
2499
|
+
}
|
|
2500
|
+
}
|
|
2501
|
+
// Last resort: Try default config
|
|
2502
|
+
const defaultConfig = await this.storageProviderConfigService.getDefaultConfig(user);
|
|
2503
|
+
if (defaultConfig) {
|
|
2504
|
+
return this.createProviderFromConfig(defaultConfig);
|
|
2505
|
+
}
|
|
2506
|
+
return this.createFallbackLocalProvider();
|
|
2507
|
+
}
|
|
2508
|
+
async uploadSingleFile(file, options, user) {
|
|
2509
|
+
this.validateFile(file);
|
|
2510
|
+
const { provider, location, configId } = await this.getStorageProviderWithConfig(options.storageConfigId, user);
|
|
2511
|
+
const result = await provider.uploadFile(file, options);
|
|
2512
|
+
await this.publishFileEvent(event_actions/* .STORAGE_EVENT_ACTIONS.UPLOADED */.hw.UPLOADED, [
|
|
2513
|
+
result.key
|
|
2514
|
+
], user, {
|
|
2515
|
+
location,
|
|
2516
|
+
storageConfigId: configId,
|
|
2517
|
+
totalSize: result.size,
|
|
2518
|
+
count: 1
|
|
2519
|
+
});
|
|
2520
|
+
return {
|
|
2521
|
+
...result,
|
|
2522
|
+
location,
|
|
2523
|
+
storageConfigId: configId
|
|
2524
|
+
};
|
|
2525
|
+
}
|
|
2526
|
+
async uploadMultipleFiles(files, options, user) {
|
|
2527
|
+
for (const file of files){
|
|
2528
|
+
this.validateFile(file);
|
|
2529
|
+
}
|
|
2530
|
+
const { provider, location, configId } = await this.getStorageProviderWithConfig(options.storageConfigId, user);
|
|
2531
|
+
const results = await provider.uploadMultipleFiles(files, options);
|
|
2532
|
+
await this.publishFileEvent(event_actions/* .STORAGE_EVENT_ACTIONS.UPLOADED */.hw.UPLOADED, results.map((result)=>result.key), user, {
|
|
2533
|
+
location,
|
|
2534
|
+
storageConfigId: configId,
|
|
2535
|
+
totalSize: results.reduce((sum, result)=>sum + (result.size ?? 0), 0),
|
|
2536
|
+
count: results.length
|
|
2537
|
+
});
|
|
2538
|
+
return results.map((result)=>({
|
|
2539
|
+
...result,
|
|
2540
|
+
location,
|
|
2541
|
+
storageConfigId: configId
|
|
2542
|
+
}));
|
|
2543
|
+
}
|
|
2544
|
+
async deleteSingleFile(key, storageConfigId, user, locationHint) {
|
|
2545
|
+
if (!key) throw new common_.BadRequestException({
|
|
2546
|
+
message: 'No file path provided',
|
|
2547
|
+
messageKey: message_keys/* .UPLOAD_MESSAGES.NO_FILE_PATH */.dS.NO_FILE_PATH
|
|
2548
|
+
});
|
|
2549
|
+
const provider = await this.getStorageProviderForDelete(storageConfigId, user, locationHint);
|
|
2550
|
+
await provider.deleteFile(key);
|
|
2551
|
+
await this.publishFileEvent(event_actions/* .STORAGE_EVENT_ACTIONS.REMOVED */.hw.REMOVED, [
|
|
2552
|
+
key
|
|
2553
|
+
], user, {
|
|
2554
|
+
storageConfigId,
|
|
2555
|
+
count: 1
|
|
2556
|
+
});
|
|
2557
|
+
return true;
|
|
2558
|
+
}
|
|
2559
|
+
async deleteMultipleFile(keys, storageConfigId, user, locationHint) {
|
|
2560
|
+
if (!keys || !keys.length) throw new common_.BadRequestException({
|
|
2561
|
+
message: 'No file paths provided',
|
|
2562
|
+
messageKey: message_keys/* .UPLOAD_MESSAGES.NO_FILE_PATH */.dS.NO_FILE_PATH
|
|
2563
|
+
});
|
|
2564
|
+
const provider = await this.getStorageProviderForDelete(storageConfigId, user, locationHint);
|
|
2565
|
+
await provider.deleteMultipleFiles(keys);
|
|
2566
|
+
await this.publishFileEvent(event_actions/* .STORAGE_EVENT_ACTIONS.REMOVED */.hw.REMOVED, keys, user, {
|
|
2567
|
+
storageConfigId,
|
|
2568
|
+
count: keys.length
|
|
2569
|
+
});
|
|
2570
|
+
return true;
|
|
2571
|
+
}
|
|
2572
|
+
async publishFileEvent(action, keys, user, metadata) {
|
|
2573
|
+
await (0,classes_.publishDomainEvent)({
|
|
2574
|
+
module: event_actions/* .STORAGE_EVENT_MODULE */.qh,
|
|
2575
|
+
entity: event_actions/* .STORAGE_EVENT_ENTITIES.FILE */.fR.FILE,
|
|
2576
|
+
action,
|
|
2577
|
+
ids: keys,
|
|
2578
|
+
metadata,
|
|
2579
|
+
user: user ?? null
|
|
2580
|
+
});
|
|
2581
|
+
}
|
|
2582
|
+
bytesToKb(bytes) {
|
|
2583
|
+
return Number((bytes * 0.001).toFixed(2));
|
|
2584
|
+
}
|
|
2585
|
+
/**
|
|
2586
|
+
* Get local storage basePath from DB config
|
|
2587
|
+
* Initializes local provider if not cached, ensuring basePath is from DB
|
|
2588
|
+
*/ async getLocalStorageBasePath() {
|
|
2589
|
+
try {
|
|
2590
|
+
// First check if already cached
|
|
2591
|
+
const cachedPath = this.storageFactory.getLocalProviderBasePath();
|
|
2592
|
+
if (cachedPath) {
|
|
2593
|
+
return cachedPath;
|
|
2594
|
+
}
|
|
2595
|
+
// Get local config from DB (without user context for public access)
|
|
2596
|
+
const localConfigs = await this.storageProviderConfigService.getConfigByType(file_location_enum/* .FileLocationEnum.LOCAL */.N.LOCAL);
|
|
2597
|
+
if (localConfigs.length > 0) {
|
|
2598
|
+
const localConfig = localConfigs[0];
|
|
2599
|
+
// Initialize provider to cache it
|
|
2600
|
+
await this.storageFactory.createProvider({
|
|
2601
|
+
provider: file_location_enum/* .FileLocationEnum.LOCAL */.N.LOCAL,
|
|
2602
|
+
config: localConfig.config
|
|
2603
|
+
});
|
|
2604
|
+
// Now get the cached basePath
|
|
2605
|
+
return this.storageFactory.getLocalProviderBasePath();
|
|
2606
|
+
}
|
|
2607
|
+
return null;
|
|
2608
|
+
} catch {
|
|
2609
|
+
return null;
|
|
2610
|
+
}
|
|
2611
|
+
}
|
|
2612
|
+
async makeFileUrl(key, storageConfigId, expiresIn = 3600, user) {
|
|
2613
|
+
const { provider } = await this.getStorageProviderWithConfig(storageConfigId, user);
|
|
2614
|
+
// Check if provider supports presigned URLs
|
|
2615
|
+
if (provider.generatePresignedUrl) {
|
|
2616
|
+
return await provider.generatePresignedUrl(key, expiresIn);
|
|
2617
|
+
}
|
|
2618
|
+
// For SFTP or other providers without presigned URLs
|
|
2619
|
+
return key;
|
|
2620
|
+
}
|
|
2621
|
+
}
|
|
2622
|
+
_ts_decorate([
|
|
2623
|
+
(0,nestjs_shared_.LogAction)({
|
|
2624
|
+
action: 'storage.uploadSingle',
|
|
2625
|
+
module: 'storage'
|
|
2626
|
+
}),
|
|
2627
|
+
_ts_metadata("design:type", Function),
|
|
2628
|
+
_ts_metadata("design:paramtypes", [
|
|
2629
|
+
typeof Express === "undefined" || typeof Express.Multer === "undefined" || typeof Express.Multer.File === "undefined" ? Object : Express.Multer.File,
|
|
2630
|
+
typeof upload_dto/* .UploadOptionsDto */.hL === "undefined" ? Object : upload_dto/* .UploadOptionsDto */.hL,
|
|
2631
|
+
typeof ILoggedUserInfo === "undefined" ? Object : ILoggedUserInfo
|
|
2632
|
+
]),
|
|
2633
|
+
_ts_metadata("design:returntype", Promise)
|
|
2634
|
+
], UploadService.prototype, "uploadSingleFile", null);
|
|
2635
|
+
_ts_decorate([
|
|
2636
|
+
(0,nestjs_shared_.LogAction)({
|
|
2637
|
+
action: 'storage.uploadMultiple',
|
|
2638
|
+
module: 'storage'
|
|
2639
|
+
}),
|
|
2640
|
+
_ts_metadata("design:type", Function),
|
|
2641
|
+
_ts_metadata("design:paramtypes", [
|
|
2642
|
+
Array,
|
|
2643
|
+
typeof upload_dto/* .UploadOptionsDto */.hL === "undefined" ? Object : upload_dto/* .UploadOptionsDto */.hL,
|
|
2644
|
+
typeof ILoggedUserInfo === "undefined" ? Object : ILoggedUserInfo
|
|
2645
|
+
]),
|
|
2646
|
+
_ts_metadata("design:returntype", Promise)
|
|
2647
|
+
], UploadService.prototype, "uploadMultipleFiles", null);
|
|
2648
|
+
_ts_decorate([
|
|
2649
|
+
(0,nestjs_shared_.LogAction)({
|
|
2650
|
+
action: 'storage.deleteSingle',
|
|
2651
|
+
module: 'storage'
|
|
2652
|
+
}),
|
|
2653
|
+
_ts_metadata("design:type", Function),
|
|
2654
|
+
_ts_metadata("design:paramtypes", [
|
|
2655
|
+
String,
|
|
2656
|
+
String,
|
|
2657
|
+
typeof ILoggedUserInfo === "undefined" ? Object : ILoggedUserInfo,
|
|
2658
|
+
String
|
|
2659
|
+
]),
|
|
2660
|
+
_ts_metadata("design:returntype", Promise)
|
|
2661
|
+
], UploadService.prototype, "deleteSingleFile", null);
|
|
2662
|
+
_ts_decorate([
|
|
2663
|
+
(0,nestjs_shared_.LogAction)({
|
|
2664
|
+
action: 'storage.deleteMultiple',
|
|
2665
|
+
module: 'storage'
|
|
2666
|
+
}),
|
|
2667
|
+
_ts_metadata("design:type", Function),
|
|
2668
|
+
_ts_metadata("design:paramtypes", [
|
|
2669
|
+
Array,
|
|
2670
|
+
String,
|
|
2671
|
+
typeof ILoggedUserInfo === "undefined" ? Object : ILoggedUserInfo,
|
|
2672
|
+
String
|
|
2673
|
+
]),
|
|
2674
|
+
_ts_metadata("design:returntype", Promise)
|
|
2675
|
+
], UploadService.prototype, "deleteMultipleFile", null);
|
|
2676
|
+
_ts_decorate([
|
|
2677
|
+
(0,nestjs_shared_.LogAction)({
|
|
2678
|
+
action: 'storage.makeFileUrl',
|
|
2679
|
+
module: 'storage'
|
|
2680
|
+
}),
|
|
2681
|
+
_ts_metadata("design:type", Function),
|
|
2682
|
+
_ts_metadata("design:paramtypes", [
|
|
2683
|
+
String,
|
|
2684
|
+
String,
|
|
2685
|
+
Number,
|
|
2686
|
+
typeof ILoggedUserInfo === "undefined" ? Object : ILoggedUserInfo
|
|
2687
|
+
]),
|
|
2688
|
+
_ts_metadata("design:returntype", Promise)
|
|
2689
|
+
], UploadService.prototype, "makeFileUrl", null);
|
|
2690
|
+
UploadService = _ts_decorate([
|
|
2691
|
+
(0,common_.Injectable)({
|
|
2692
|
+
scope: common_.Scope.REQUEST
|
|
2693
|
+
}),
|
|
2694
|
+
_ts_param(0, (0,common_.Inject)(storage_factory_service/* .StorageFactoryService */.L)),
|
|
2695
|
+
_ts_param(1, (0,common_.Inject)(storage_config_service/* .StorageConfigService */.t)),
|
|
2696
|
+
_ts_param(2, (0,common_.Inject)(storage_provider_config_service/* .StorageProviderConfigService */.o)),
|
|
2697
|
+
_ts_metadata("design:type", Function),
|
|
2698
|
+
_ts_metadata("design:paramtypes", [
|
|
2699
|
+
typeof storage_factory_service/* .StorageFactoryService */.L === "undefined" ? Object : storage_factory_service/* .StorageFactoryService */.L,
|
|
2700
|
+
typeof storage_config_service/* .StorageConfigService */.t === "undefined" ? Object : storage_config_service/* .StorageConfigService */.t,
|
|
2701
|
+
typeof storage_provider_config_service/* .StorageProviderConfigService */.o === "undefined" ? Object : storage_provider_config_service/* .StorageProviderConfigService */.o
|
|
2702
|
+
])
|
|
2703
|
+
], UploadService);
|
|
2704
|
+
|
|
2705
|
+
|
|
2706
|
+
},
|
|
2707
|
+
422(module) {
|
|
2708
|
+
|
|
2709
|
+
module.exports = __rspack_external__flusys_nestjs_shared_393d2cae;
|
|
2710
|
+
|
|
2711
|
+
|
|
2712
|
+
},
|
|
2713
|
+
937(module) {
|
|
2714
|
+
|
|
2715
|
+
module.exports = __rspack_external__flusys_nestjs_shared_classes_6076a329;
|
|
2716
|
+
|
|
2717
|
+
|
|
2718
|
+
},
|
|
2719
|
+
140(module) {
|
|
2720
|
+
|
|
2721
|
+
module.exports = __rspack_external__flusys_nestjs_shared_constants_81f33d5b;
|
|
2722
|
+
|
|
2723
|
+
|
|
2724
|
+
},
|
|
2725
|
+
236(module) {
|
|
2726
|
+
|
|
2727
|
+
module.exports = __rspack_external__flusys_nestjs_shared_modules_24702bee;
|
|
2728
|
+
|
|
2729
|
+
|
|
2730
|
+
},
|
|
2731
|
+
216(module) {
|
|
2732
|
+
|
|
2733
|
+
module.exports = __rspack_external__flusys_nestjs_shared_utils_9125c1f1;
|
|
2734
|
+
|
|
2735
|
+
|
|
2736
|
+
},
|
|
2737
|
+
157(module) {
|
|
2738
|
+
|
|
2739
|
+
module.exports = __rspack_external__nestjs_common_a04939da;
|
|
2740
|
+
|
|
2741
|
+
|
|
2742
|
+
},
|
|
2743
|
+
176(module) {
|
|
2744
|
+
|
|
2745
|
+
module.exports = __rspack_external__nestjs_swagger_7cd450b5;
|
|
2746
|
+
|
|
2747
|
+
|
|
2748
|
+
},
|
|
2749
|
+
812(module) {
|
|
2750
|
+
|
|
2751
|
+
module.exports = __rspack_external_class_transformer_c5a479fb;
|
|
2752
|
+
|
|
2753
|
+
|
|
2754
|
+
},
|
|
2755
|
+
421(module) {
|
|
2756
|
+
|
|
2757
|
+
module.exports = __rspack_external_class_validator_7b99ef4d;
|
|
2758
|
+
|
|
2759
|
+
|
|
2760
|
+
},
|
|
2761
|
+
158(module) {
|
|
2762
|
+
|
|
2763
|
+
module.exports = __rspack_external_typeorm;
|
|
2764
|
+
|
|
2765
|
+
|
|
2766
|
+
},
|
|
2767
|
+
|
|
2768
|
+
};
|