@flusys/nestjs-storage 7.1.0 → 8.0.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/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
|
@@ -1,366 +0,0 @@
|
|
|
1
|
-
function _define_property(obj, key, value) {
|
|
2
|
-
if (key in obj) {
|
|
3
|
-
Object.defineProperty(obj, key, {
|
|
4
|
-
value: value,
|
|
5
|
-
enumerable: true,
|
|
6
|
-
configurable: true,
|
|
7
|
-
writable: true
|
|
8
|
-
});
|
|
9
|
-
} else {
|
|
10
|
-
obj[key] = value;
|
|
11
|
-
}
|
|
12
|
-
return obj;
|
|
13
|
-
}
|
|
14
|
-
function _ts_decorate(decorators, target, key, desc) {
|
|
15
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
16
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
17
|
-
else for(var i = decorators.length - 1; i >= 0; i--)if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
18
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
19
|
-
}
|
|
20
|
-
function _ts_metadata(k, v) {
|
|
21
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
22
|
-
}
|
|
23
|
-
function _ts_param(paramIndex, decorator) {
|
|
24
|
-
return function(target, key) {
|
|
25
|
-
decorator(target, key, paramIndex);
|
|
26
|
-
};
|
|
27
|
-
}
|
|
28
|
-
import { LogAction } from '@flusys/nestjs-shared';
|
|
29
|
-
import { publishDomainEvent } from '@flusys/nestjs-shared/classes';
|
|
30
|
-
import { ILoggedUserInfo } from '@flusys/nestjs-shared/interfaces';
|
|
31
|
-
import { validateCompanyOwnership } from '@flusys/nestjs-shared/utils';
|
|
32
|
-
import { BadRequestException, Inject, Injectable, NotFoundException, Scope } from '@nestjs/common';
|
|
33
|
-
import { STORAGE_EVENT_ACTIONS, STORAGE_EVENT_ENTITIES, STORAGE_EVENT_MODULE, UPLOAD_MESSAGES } from '../config';
|
|
34
|
-
import { UploadOptionsDto } from '../dtos/upload.dto';
|
|
35
|
-
import { FileLocationEnum } from '../enums/file-location.enum';
|
|
36
|
-
import { StorageFactoryService } from '../providers/storage-factory.service';
|
|
37
|
-
import { FileValidator } from '../utils/file-validator.util';
|
|
38
|
-
import { StorageConfigService } from './storage-config.service';
|
|
39
|
-
import { StorageProviderConfigService } from './storage-provider-config.service';
|
|
40
|
-
export class UploadService {
|
|
41
|
-
/**
|
|
42
|
-
* Validate file before upload - includes size, type, and content validation.
|
|
43
|
-
* Uses magic bytes to verify file content matches declared MIME type.
|
|
44
|
-
*/ validateFile(file) {
|
|
45
|
-
// Validate file size
|
|
46
|
-
const sizeValidation = this.storageConfigService.validateFileSize(file.size);
|
|
47
|
-
if (!sizeValidation.valid) {
|
|
48
|
-
throw new BadRequestException({
|
|
49
|
-
message: sizeValidation.message,
|
|
50
|
-
messageKey: sizeValidation.messageKey,
|
|
51
|
-
messageVariables: sizeValidation.messageVariables
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
|
-
// Validate declared file type (MIME)
|
|
55
|
-
const typeValidation = this.storageConfigService.validateFileType(file.mimetype);
|
|
56
|
-
if (!typeValidation.valid) {
|
|
57
|
-
throw new BadRequestException({
|
|
58
|
-
message: typeValidation.message,
|
|
59
|
-
messageKey: typeValidation.messageKey,
|
|
60
|
-
messageVariables: typeValidation.messageVariables
|
|
61
|
-
});
|
|
62
|
-
}
|
|
63
|
-
// Validate file content matches declared type (magic bytes check)
|
|
64
|
-
// This prevents MIME type spoofing attacks
|
|
65
|
-
const allowedTypes = this.storageConfigService.getAllowedFileTypes();
|
|
66
|
-
const contentValidation = FileValidator.validateFileContent(file.buffer, file.mimetype, allowedTypes);
|
|
67
|
-
if (!contentValidation.valid) {
|
|
68
|
-
throw new BadRequestException({
|
|
69
|
-
message: contentValidation.message || 'File content validation failed',
|
|
70
|
-
messageKey: UPLOAD_MESSAGES.INVALID_TYPE,
|
|
71
|
-
messageVariables: {
|
|
72
|
-
mimeType: file.mimetype,
|
|
73
|
-
allowedTypes: allowedTypes.join(', ')
|
|
74
|
-
}
|
|
75
|
-
});
|
|
76
|
-
}
|
|
77
|
-
// Sanitize filename to prevent path traversal attacks
|
|
78
|
-
file.originalname = FileValidator.sanitizeFilename(file.originalname);
|
|
79
|
-
}
|
|
80
|
-
/**
|
|
81
|
-
* Create provider from storage config entity
|
|
82
|
-
*/ async createProviderFromConfig(config) {
|
|
83
|
-
return this.storageFactory.createProvider({
|
|
84
|
-
provider: config.storage,
|
|
85
|
-
config: config.config
|
|
86
|
-
});
|
|
87
|
-
}
|
|
88
|
-
/**
|
|
89
|
-
* Create fallback local provider
|
|
90
|
-
*/ async createFallbackLocalProvider() {
|
|
91
|
-
return this.storageFactory.createProvider({
|
|
92
|
-
provider: FileLocationEnum.LOCAL,
|
|
93
|
-
config: {
|
|
94
|
-
basePath: this.storageConfigService.getDefaultLocalStoragePath()
|
|
95
|
-
}
|
|
96
|
-
});
|
|
97
|
-
}
|
|
98
|
-
/**
|
|
99
|
-
* Get storage provider and config info based on storage config ID
|
|
100
|
-
* Validates company ownership when company feature is enabled
|
|
101
|
-
*/ async getStorageProviderWithConfig(storageConfigId, user) {
|
|
102
|
-
let storageConfig;
|
|
103
|
-
// Get storage config from database
|
|
104
|
-
if (storageConfigId) {
|
|
105
|
-
// Use direct lookup (bypasses company filtering, returns null instead of throwing)
|
|
106
|
-
const config = await this.storageProviderConfigService.findByIdDirect(storageConfigId);
|
|
107
|
-
if (!config) {
|
|
108
|
-
throw new NotFoundException({
|
|
109
|
-
message: 'Storage configuration not found',
|
|
110
|
-
messageKey: UPLOAD_MESSAGES.CONFIG_NOT_FOUND
|
|
111
|
-
});
|
|
112
|
-
}
|
|
113
|
-
// Validate company ownership using shared utility
|
|
114
|
-
validateCompanyOwnership(config, user, this.storageConfigService.isCompanyFeatureEnabled(), 'Storage configuration');
|
|
115
|
-
storageConfig = config;
|
|
116
|
-
} else {
|
|
117
|
-
// Use default config (scoped to user's company/branch)
|
|
118
|
-
const defaultConfig = await this.storageProviderConfigService.getDefaultConfig(user);
|
|
119
|
-
if (!defaultConfig) {
|
|
120
|
-
throw new NotFoundException({
|
|
121
|
-
message: 'No default storage configuration found for your company/branch. Please create one.',
|
|
122
|
-
messageKey: UPLOAD_MESSAGES.CONFIG_NOT_FOUND
|
|
123
|
-
});
|
|
124
|
-
}
|
|
125
|
-
storageConfig = defaultConfig;
|
|
126
|
-
}
|
|
127
|
-
const provider = await this.createProviderFromConfig(storageConfig);
|
|
128
|
-
return {
|
|
129
|
-
provider,
|
|
130
|
-
location: storageConfig.storage,
|
|
131
|
-
configId: storageConfig.id
|
|
132
|
-
};
|
|
133
|
-
}
|
|
134
|
-
/**
|
|
135
|
-
* Get storage provider for delete operations with fallback
|
|
136
|
-
* If the original storage config doesn't exist, falls back based on locationHint
|
|
137
|
-
*/ async getStorageProviderForDelete(storageConfigId, user, locationHint) {
|
|
138
|
-
// Try to find by storageConfigId
|
|
139
|
-
if (storageConfigId) {
|
|
140
|
-
const config = await this.storageProviderConfigService.findByIdDirect(storageConfigId);
|
|
141
|
-
if (config) {
|
|
142
|
-
return this.createProviderFromConfig(config);
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
// Fallback: Use locationHint to find a matching config
|
|
146
|
-
if (locationHint) {
|
|
147
|
-
const matchingConfigs = await this.storageProviderConfigService.getConfigByType(locationHint, user);
|
|
148
|
-
if (matchingConfigs.length > 0) {
|
|
149
|
-
return this.createProviderFromConfig(matchingConfigs[0]);
|
|
150
|
-
}
|
|
151
|
-
if (locationHint === FileLocationEnum.LOCAL) {
|
|
152
|
-
return this.createFallbackLocalProvider();
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
// Last resort: Try default config
|
|
156
|
-
const defaultConfig = await this.storageProviderConfigService.getDefaultConfig(user);
|
|
157
|
-
if (defaultConfig) {
|
|
158
|
-
return this.createProviderFromConfig(defaultConfig);
|
|
159
|
-
}
|
|
160
|
-
return this.createFallbackLocalProvider();
|
|
161
|
-
}
|
|
162
|
-
async uploadSingleFile(file, options, user) {
|
|
163
|
-
this.validateFile(file);
|
|
164
|
-
const { provider, location, configId } = await this.getStorageProviderWithConfig(options.storageConfigId, user);
|
|
165
|
-
const result = await provider.uploadFile(file, options);
|
|
166
|
-
await this.publishFileEvent(STORAGE_EVENT_ACTIONS.UPLOADED, [
|
|
167
|
-
result.key
|
|
168
|
-
], user, {
|
|
169
|
-
location,
|
|
170
|
-
storageConfigId: configId,
|
|
171
|
-
totalSize: result.size,
|
|
172
|
-
count: 1
|
|
173
|
-
});
|
|
174
|
-
return {
|
|
175
|
-
...result,
|
|
176
|
-
location,
|
|
177
|
-
storageConfigId: configId
|
|
178
|
-
};
|
|
179
|
-
}
|
|
180
|
-
async uploadMultipleFiles(files, options, user) {
|
|
181
|
-
for (const file of files){
|
|
182
|
-
this.validateFile(file);
|
|
183
|
-
}
|
|
184
|
-
const { provider, location, configId } = await this.getStorageProviderWithConfig(options.storageConfigId, user);
|
|
185
|
-
const results = await provider.uploadMultipleFiles(files, options);
|
|
186
|
-
await this.publishFileEvent(STORAGE_EVENT_ACTIONS.UPLOADED, results.map((result)=>result.key), user, {
|
|
187
|
-
location,
|
|
188
|
-
storageConfigId: configId,
|
|
189
|
-
totalSize: results.reduce((sum, result)=>sum + (result.size ?? 0), 0),
|
|
190
|
-
count: results.length
|
|
191
|
-
});
|
|
192
|
-
return results.map((result)=>({
|
|
193
|
-
...result,
|
|
194
|
-
location,
|
|
195
|
-
storageConfigId: configId
|
|
196
|
-
}));
|
|
197
|
-
}
|
|
198
|
-
async deleteSingleFile(key, storageConfigId, user, locationHint) {
|
|
199
|
-
if (!key) throw new BadRequestException({
|
|
200
|
-
message: 'No file path provided',
|
|
201
|
-
messageKey: UPLOAD_MESSAGES.NO_FILE_PATH
|
|
202
|
-
});
|
|
203
|
-
const provider = await this.getStorageProviderForDelete(storageConfigId, user, locationHint);
|
|
204
|
-
await provider.deleteFile(key);
|
|
205
|
-
await this.publishFileEvent(STORAGE_EVENT_ACTIONS.REMOVED, [
|
|
206
|
-
key
|
|
207
|
-
], user, {
|
|
208
|
-
storageConfigId,
|
|
209
|
-
count: 1
|
|
210
|
-
});
|
|
211
|
-
return true;
|
|
212
|
-
}
|
|
213
|
-
async deleteMultipleFile(keys, storageConfigId, user, locationHint) {
|
|
214
|
-
if (!keys || !keys.length) throw new BadRequestException({
|
|
215
|
-
message: 'No file paths provided',
|
|
216
|
-
messageKey: UPLOAD_MESSAGES.NO_FILE_PATH
|
|
217
|
-
});
|
|
218
|
-
const provider = await this.getStorageProviderForDelete(storageConfigId, user, locationHint);
|
|
219
|
-
await provider.deleteMultipleFiles(keys);
|
|
220
|
-
await this.publishFileEvent(STORAGE_EVENT_ACTIONS.REMOVED, keys, user, {
|
|
221
|
-
storageConfigId,
|
|
222
|
-
count: keys.length
|
|
223
|
-
});
|
|
224
|
-
return true;
|
|
225
|
-
}
|
|
226
|
-
async publishFileEvent(action, keys, user, metadata) {
|
|
227
|
-
await publishDomainEvent({
|
|
228
|
-
module: STORAGE_EVENT_MODULE,
|
|
229
|
-
entity: STORAGE_EVENT_ENTITIES.FILE,
|
|
230
|
-
action,
|
|
231
|
-
ids: keys,
|
|
232
|
-
metadata,
|
|
233
|
-
user: user ?? null
|
|
234
|
-
});
|
|
235
|
-
}
|
|
236
|
-
bytesToKb(bytes) {
|
|
237
|
-
return Number((bytes * 0.001).toFixed(2));
|
|
238
|
-
}
|
|
239
|
-
/**
|
|
240
|
-
* Get local storage basePath from DB config
|
|
241
|
-
* Initializes local provider if not cached, ensuring basePath is from DB
|
|
242
|
-
*/ async getLocalStorageBasePath() {
|
|
243
|
-
try {
|
|
244
|
-
// First check if already cached
|
|
245
|
-
const cachedPath = this.storageFactory.getLocalProviderBasePath();
|
|
246
|
-
if (cachedPath) {
|
|
247
|
-
return cachedPath;
|
|
248
|
-
}
|
|
249
|
-
// Get local config from DB (without user context for public access)
|
|
250
|
-
const localConfigs = await this.storageProviderConfigService.getConfigByType(FileLocationEnum.LOCAL);
|
|
251
|
-
if (localConfigs.length > 0) {
|
|
252
|
-
const localConfig = localConfigs[0];
|
|
253
|
-
// Initialize provider to cache it
|
|
254
|
-
await this.storageFactory.createProvider({
|
|
255
|
-
provider: FileLocationEnum.LOCAL,
|
|
256
|
-
config: localConfig.config
|
|
257
|
-
});
|
|
258
|
-
// Now get the cached basePath
|
|
259
|
-
return this.storageFactory.getLocalProviderBasePath();
|
|
260
|
-
}
|
|
261
|
-
return null;
|
|
262
|
-
} catch {
|
|
263
|
-
return null;
|
|
264
|
-
}
|
|
265
|
-
}
|
|
266
|
-
async makeFileUrl(key, storageConfigId, expiresIn = 3600, user) {
|
|
267
|
-
const { provider } = await this.getStorageProviderWithConfig(storageConfigId, user);
|
|
268
|
-
// Check if provider supports presigned URLs
|
|
269
|
-
if (provider.generatePresignedUrl) {
|
|
270
|
-
return await provider.generatePresignedUrl(key, expiresIn);
|
|
271
|
-
}
|
|
272
|
-
// For SFTP or other providers without presigned URLs
|
|
273
|
-
return key;
|
|
274
|
-
}
|
|
275
|
-
// NOTE: @Inject() required for bundled code - type metadata may be lost during esbuild
|
|
276
|
-
constructor(storageFactory, storageConfigService, storageProviderConfigService){
|
|
277
|
-
_define_property(this, "storageFactory", void 0);
|
|
278
|
-
_define_property(this, "storageConfigService", void 0);
|
|
279
|
-
_define_property(this, "storageProviderConfigService", void 0);
|
|
280
|
-
this.storageFactory = storageFactory;
|
|
281
|
-
this.storageConfigService = storageConfigService;
|
|
282
|
-
this.storageProviderConfigService = storageProviderConfigService;
|
|
283
|
-
}
|
|
284
|
-
}
|
|
285
|
-
_ts_decorate([
|
|
286
|
-
LogAction({
|
|
287
|
-
action: 'storage.uploadSingle',
|
|
288
|
-
module: 'storage'
|
|
289
|
-
}),
|
|
290
|
-
_ts_metadata("design:type", Function),
|
|
291
|
-
_ts_metadata("design:paramtypes", [
|
|
292
|
-
typeof Express === "undefined" || typeof Express.Multer === "undefined" || typeof Express.Multer.File === "undefined" ? Object : Express.Multer.File,
|
|
293
|
-
typeof UploadOptionsDto === "undefined" ? Object : UploadOptionsDto,
|
|
294
|
-
typeof ILoggedUserInfo === "undefined" ? Object : ILoggedUserInfo
|
|
295
|
-
]),
|
|
296
|
-
_ts_metadata("design:returntype", Promise)
|
|
297
|
-
], UploadService.prototype, "uploadSingleFile", null);
|
|
298
|
-
_ts_decorate([
|
|
299
|
-
LogAction({
|
|
300
|
-
action: 'storage.uploadMultiple',
|
|
301
|
-
module: 'storage'
|
|
302
|
-
}),
|
|
303
|
-
_ts_metadata("design:type", Function),
|
|
304
|
-
_ts_metadata("design:paramtypes", [
|
|
305
|
-
Array,
|
|
306
|
-
typeof UploadOptionsDto === "undefined" ? Object : UploadOptionsDto,
|
|
307
|
-
typeof ILoggedUserInfo === "undefined" ? Object : ILoggedUserInfo
|
|
308
|
-
]),
|
|
309
|
-
_ts_metadata("design:returntype", Promise)
|
|
310
|
-
], UploadService.prototype, "uploadMultipleFiles", null);
|
|
311
|
-
_ts_decorate([
|
|
312
|
-
LogAction({
|
|
313
|
-
action: 'storage.deleteSingle',
|
|
314
|
-
module: 'storage'
|
|
315
|
-
}),
|
|
316
|
-
_ts_metadata("design:type", Function),
|
|
317
|
-
_ts_metadata("design:paramtypes", [
|
|
318
|
-
String,
|
|
319
|
-
String,
|
|
320
|
-
typeof ILoggedUserInfo === "undefined" ? Object : ILoggedUserInfo,
|
|
321
|
-
String
|
|
322
|
-
]),
|
|
323
|
-
_ts_metadata("design:returntype", Promise)
|
|
324
|
-
], UploadService.prototype, "deleteSingleFile", null);
|
|
325
|
-
_ts_decorate([
|
|
326
|
-
LogAction({
|
|
327
|
-
action: 'storage.deleteMultiple',
|
|
328
|
-
module: 'storage'
|
|
329
|
-
}),
|
|
330
|
-
_ts_metadata("design:type", Function),
|
|
331
|
-
_ts_metadata("design:paramtypes", [
|
|
332
|
-
Array,
|
|
333
|
-
String,
|
|
334
|
-
typeof ILoggedUserInfo === "undefined" ? Object : ILoggedUserInfo,
|
|
335
|
-
String
|
|
336
|
-
]),
|
|
337
|
-
_ts_metadata("design:returntype", Promise)
|
|
338
|
-
], UploadService.prototype, "deleteMultipleFile", null);
|
|
339
|
-
_ts_decorate([
|
|
340
|
-
LogAction({
|
|
341
|
-
action: 'storage.makeFileUrl',
|
|
342
|
-
module: 'storage'
|
|
343
|
-
}),
|
|
344
|
-
_ts_metadata("design:type", Function),
|
|
345
|
-
_ts_metadata("design:paramtypes", [
|
|
346
|
-
String,
|
|
347
|
-
String,
|
|
348
|
-
Number,
|
|
349
|
-
typeof ILoggedUserInfo === "undefined" ? Object : ILoggedUserInfo
|
|
350
|
-
]),
|
|
351
|
-
_ts_metadata("design:returntype", Promise)
|
|
352
|
-
], UploadService.prototype, "makeFileUrl", null);
|
|
353
|
-
UploadService = _ts_decorate([
|
|
354
|
-
Injectable({
|
|
355
|
-
scope: Scope.REQUEST
|
|
356
|
-
}),
|
|
357
|
-
_ts_param(0, Inject(StorageFactoryService)),
|
|
358
|
-
_ts_param(1, Inject(StorageConfigService)),
|
|
359
|
-
_ts_param(2, Inject(StorageProviderConfigService)),
|
|
360
|
-
_ts_metadata("design:type", Function),
|
|
361
|
-
_ts_metadata("design:paramtypes", [
|
|
362
|
-
typeof StorageFactoryService === "undefined" ? Object : StorageFactoryService,
|
|
363
|
-
typeof StorageConfigService === "undefined" ? Object : StorageConfigService,
|
|
364
|
-
typeof StorageProviderConfigService === "undefined" ? Object : StorageProviderConfigService
|
|
365
|
-
])
|
|
366
|
-
], UploadService);
|