@flusys/nestjs-storage 1.1.0-beta → 2.0.0-rc.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/README.md +148 -6
- package/cjs/config/index.js +0 -1
- package/cjs/config/storage.constants.js +0 -17
- package/cjs/controllers/file-manager.controller.js +44 -1
- package/cjs/controllers/folder.controller.js +44 -1
- package/cjs/controllers/storage-config.controller.js +44 -1
- package/cjs/controllers/upload.controller.js +18 -29
- package/cjs/docs/storage-swagger.config.js +24 -136
- package/cjs/dtos/file-manager.dto.js +70 -34
- package/cjs/dtos/folder.dto.js +15 -9
- package/cjs/dtos/storage-config.dto.js +4 -85
- package/cjs/dtos/upload.dto.js +24 -17
- package/cjs/entities/file-manager-with-company.entity.js +3 -4
- package/cjs/entities/file-manager.entity.js +71 -3
- package/cjs/entities/folder-with-company.entity.js +3 -4
- package/cjs/entities/folder.entity.js +19 -3
- package/cjs/entities/index.js +9 -10
- package/cjs/entities/storage-config-with-company.entity.js +3 -4
- package/cjs/entities/storage-config.entity.js +74 -3
- package/cjs/interfaces/index.js +0 -1
- package/cjs/middlewares/file-serve.middleware.js +113 -100
- package/cjs/modules/storage.module.js +82 -136
- package/cjs/providers/azure-provider.optional.js +10 -38
- package/cjs/providers/local-provider.js +38 -31
- package/cjs/providers/s3-provider.optional.js +19 -40
- package/cjs/providers/storage-factory.service.js +54 -99
- package/cjs/providers/storage-provider.registry.js +8 -18
- package/cjs/services/file-manager.service.js +238 -323
- package/cjs/services/folder.service.js +8 -11
- package/cjs/services/index.js +1 -0
- package/cjs/{config → services}/storage-config.service.js +32 -76
- package/cjs/services/storage-datasource.provider.js +16 -26
- package/cjs/services/storage-provider-config.service.js +15 -37
- package/cjs/services/upload.service.js +72 -88
- package/cjs/utils/file-validator.util.js +458 -0
- package/cjs/utils/image-compressor.util.js +3 -8
- package/config/index.d.ts +0 -1
- package/config/storage.constants.d.ts +0 -8
- package/controllers/upload.controller.d.ts +3 -6
- package/dtos/file-manager.dto.d.ts +12 -5
- package/dtos/folder.dto.d.ts +5 -5
- package/dtos/storage-config.dto.d.ts +7 -13
- package/entities/file-manager-with-company.entity.d.ts +2 -2
- package/entities/file-manager.entity.d.ts +12 -2
- package/entities/folder-with-company.entity.d.ts +2 -2
- package/entities/folder.entity.d.ts +4 -2
- package/entities/index.d.ts +3 -4
- package/entities/storage-config-with-company.entity.d.ts +2 -2
- package/entities/storage-config.entity.d.ts +8 -2
- package/fesm/config/index.js +0 -1
- package/fesm/config/storage.constants.js +0 -8
- package/fesm/controllers/file-manager.controller.js +45 -2
- package/fesm/controllers/folder.controller.js +45 -2
- package/fesm/controllers/storage-config.controller.js +45 -2
- package/fesm/controllers/upload.controller.js +19 -30
- package/fesm/docs/storage-swagger.config.js +27 -142
- package/fesm/dtos/file-manager.dto.js +71 -35
- package/fesm/dtos/folder.dto.js +16 -10
- package/fesm/dtos/storage-config.dto.js +8 -95
- package/fesm/dtos/upload.dto.js +25 -19
- package/fesm/entities/file-manager-with-company.entity.js +3 -4
- package/fesm/entities/file-manager.entity.js +72 -4
- package/fesm/entities/folder-with-company.entity.js +3 -4
- package/fesm/entities/folder.entity.js +20 -4
- package/fesm/entities/index.js +5 -13
- package/fesm/entities/storage-config-with-company.entity.js +3 -4
- package/fesm/entities/storage-config.entity.js +75 -4
- package/fesm/interfaces/index.js +0 -1
- package/fesm/interfaces/storage-config.interface.js +1 -3
- package/fesm/middlewares/file-serve.middleware.js +114 -101
- package/fesm/modules/storage.module.js +83 -136
- package/fesm/providers/azure-provider.optional.js +11 -42
- package/fesm/providers/local-provider.js +38 -31
- package/fesm/providers/s3-provider.optional.js +20 -44
- package/fesm/providers/storage-factory.service.js +52 -97
- package/fesm/providers/storage-provider.registry.js +10 -20
- package/fesm/services/file-manager.service.js +237 -322
- package/fesm/services/folder.service.js +6 -9
- package/fesm/services/index.js +1 -0
- package/fesm/{config → services}/storage-config.service.js +32 -76
- package/fesm/services/storage-datasource.provider.js +16 -26
- package/fesm/services/storage-provider-config.service.js +13 -35
- package/fesm/services/upload.service.js +71 -87
- package/fesm/utils/file-validator.util.js +451 -0
- package/fesm/utils/image-compressor.util.js +3 -8
- package/interfaces/file-manager.interface.d.ts +7 -4
- package/interfaces/index.d.ts +0 -1
- package/interfaces/storage-config.interface.d.ts +0 -20
- package/interfaces/storage-module-options.interface.d.ts +0 -5
- package/middlewares/file-serve.middleware.d.ts +9 -1
- package/modules/storage.module.d.ts +1 -2
- package/package.json +6 -6
- package/providers/azure-provider.optional.d.ts +8 -6
- package/providers/local-provider.d.ts +2 -7
- package/providers/s3-provider.optional.d.ts +9 -7
- package/providers/storage-factory.service.d.ts +8 -9
- package/providers/storage-provider.registry.d.ts +4 -4
- package/services/file-manager.service.d.ts +23 -16
- package/services/folder.service.d.ts +4 -4
- package/services/index.d.ts +1 -0
- package/services/storage-config.service.d.ts +24 -0
- package/services/storage-datasource.provider.d.ts +3 -4
- package/services/storage-provider-config.service.d.ts +4 -4
- package/services/upload.service.d.ts +3 -2
- package/utils/file-validator.util.d.ts +19 -0
- package/cjs/entities/file-manager-base.entity.js +0 -115
- package/cjs/entities/folder-base.entity.js +0 -55
- package/cjs/entities/storage-config-base.entity.js +0 -93
- package/cjs/interfaces/file-upload-response.interface.js +0 -4
- package/config/storage-config.service.d.ts +0 -22
- package/entities/file-manager-base.entity.d.ts +0 -13
- package/entities/folder-base.entity.d.ts +0 -5
- package/entities/storage-config-base.entity.d.ts +0 -9
- package/fesm/entities/file-manager-base.entity.js +0 -108
- package/fesm/entities/folder-base.entity.js +0 -48
- package/fesm/entities/storage-config-base.entity.js +0 -83
- package/fesm/interfaces/file-upload-response.interface.js +0 -1
- package/interfaces/file-upload-response.interface.d.ts +0 -6
|
@@ -1,15 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Storage Module Constants
|
|
3
3
|
*/ export const STORAGE_MODULE_OPTIONS = 'STORAGE_MODULE_OPTIONS';
|
|
4
|
-
export const STORAGE_CONFIG_SERVICE = 'STORAGE_CONFIG_SERVICE';
|
|
5
|
-
export const STORAGE_DATA_SOURCE_PROVIDER = 'STORAGE_DATA_SOURCE_PROVIDER';
|
|
6
4
|
export const DEFAULT_MAX_FILE_SIZE = 100 * 1024 * 1024; // 100MB
|
|
7
5
|
export const DEFAULT_ALLOWED_FILE_TYPES = [
|
|
8
6
|
'*/*'
|
|
9
7
|
]; // All file types
|
|
10
|
-
export const FILE_VALIDATION_MESSAGES = {
|
|
11
|
-
FILE_TOO_LARGE: 'File size exceeds the maximum allowed size',
|
|
12
|
-
INVALID_FILE_TYPE: 'File type is not allowed',
|
|
13
|
-
NO_FILE_PROVIDED: 'No file was provided',
|
|
14
|
-
UPLOAD_FAILED: 'File upload failed'
|
|
15
|
-
};
|
|
@@ -26,7 +26,7 @@ function _ts_param(paramIndex, decorator) {
|
|
|
26
26
|
};
|
|
27
27
|
}
|
|
28
28
|
import { BadRequestException, Body, Controller, HttpCode, Inject, Post, Req, UseGuards } from '@nestjs/common';
|
|
29
|
-
import { createApiController } from '@flusys/nestjs-shared/classes';
|
|
29
|
+
import { createApiController, FILE_PERMISSIONS } from '@flusys/nestjs-shared/classes';
|
|
30
30
|
import { CurrentUser } from '@flusys/nestjs-shared/decorators';
|
|
31
31
|
import { SingleResponseDto } from '@flusys/nestjs-shared/dtos';
|
|
32
32
|
import { JwtAuthGuard } from '@flusys/nestjs-shared/guards';
|
|
@@ -36,7 +36,50 @@ import { ApiBearerAuth, ApiBody, ApiOperation, ApiResponse, ApiTags } from '@nes
|
|
|
36
36
|
import { Request } from 'express';
|
|
37
37
|
import { FileManagerService } from '../services/file-manager.service';
|
|
38
38
|
export class FileManagerController extends createApiController(CreateFileManagerDto, UpdateFileManagerDto, FileManagerResponseDto, {
|
|
39
|
-
security:
|
|
39
|
+
security: {
|
|
40
|
+
insert: {
|
|
41
|
+
level: 'permission',
|
|
42
|
+
permissions: [
|
|
43
|
+
FILE_PERMISSIONS.CREATE
|
|
44
|
+
]
|
|
45
|
+
},
|
|
46
|
+
insertMany: {
|
|
47
|
+
level: 'permission',
|
|
48
|
+
permissions: [
|
|
49
|
+
FILE_PERMISSIONS.CREATE
|
|
50
|
+
]
|
|
51
|
+
},
|
|
52
|
+
getById: {
|
|
53
|
+
level: 'permission',
|
|
54
|
+
permissions: [
|
|
55
|
+
FILE_PERMISSIONS.READ
|
|
56
|
+
]
|
|
57
|
+
},
|
|
58
|
+
getAll: {
|
|
59
|
+
level: 'permission',
|
|
60
|
+
permissions: [
|
|
61
|
+
FILE_PERMISSIONS.READ
|
|
62
|
+
]
|
|
63
|
+
},
|
|
64
|
+
update: {
|
|
65
|
+
level: 'permission',
|
|
66
|
+
permissions: [
|
|
67
|
+
FILE_PERMISSIONS.UPDATE
|
|
68
|
+
]
|
|
69
|
+
},
|
|
70
|
+
updateMany: {
|
|
71
|
+
level: 'permission',
|
|
72
|
+
permissions: [
|
|
73
|
+
FILE_PERMISSIONS.UPDATE
|
|
74
|
+
]
|
|
75
|
+
},
|
|
76
|
+
delete: {
|
|
77
|
+
level: 'permission',
|
|
78
|
+
permissions: [
|
|
79
|
+
FILE_PERMISSIONS.DELETE
|
|
80
|
+
]
|
|
81
|
+
}
|
|
82
|
+
}
|
|
40
83
|
}) {
|
|
41
84
|
async getFiles(dto, req, user) {
|
|
42
85
|
if (!dto || !dto.length) {
|
|
@@ -25,13 +25,56 @@ function _ts_param(paramIndex, decorator) {
|
|
|
25
25
|
decorator(target, key, paramIndex);
|
|
26
26
|
};
|
|
27
27
|
}
|
|
28
|
-
import { createApiController } from '@flusys/nestjs-shared/classes';
|
|
28
|
+
import { createApiController, FOLDER_PERMISSIONS } from '@flusys/nestjs-shared/classes';
|
|
29
29
|
import { CreateFolderDto, FolderResponseDto, UpdateFolderDto } from '../dtos';
|
|
30
30
|
import { Controller, Inject } from '@nestjs/common';
|
|
31
31
|
import { ApiTags } from '@nestjs/swagger';
|
|
32
32
|
import { FolderService } from '../services/folder.service';
|
|
33
33
|
export class FolderController extends createApiController(CreateFolderDto, UpdateFolderDto, FolderResponseDto, {
|
|
34
|
-
security:
|
|
34
|
+
security: {
|
|
35
|
+
insert: {
|
|
36
|
+
level: 'permission',
|
|
37
|
+
permissions: [
|
|
38
|
+
FOLDER_PERMISSIONS.CREATE
|
|
39
|
+
]
|
|
40
|
+
},
|
|
41
|
+
insertMany: {
|
|
42
|
+
level: 'permission',
|
|
43
|
+
permissions: [
|
|
44
|
+
FOLDER_PERMISSIONS.CREATE
|
|
45
|
+
]
|
|
46
|
+
},
|
|
47
|
+
getById: {
|
|
48
|
+
level: 'permission',
|
|
49
|
+
permissions: [
|
|
50
|
+
FOLDER_PERMISSIONS.READ
|
|
51
|
+
]
|
|
52
|
+
},
|
|
53
|
+
getAll: {
|
|
54
|
+
level: 'permission',
|
|
55
|
+
permissions: [
|
|
56
|
+
FOLDER_PERMISSIONS.READ
|
|
57
|
+
]
|
|
58
|
+
},
|
|
59
|
+
update: {
|
|
60
|
+
level: 'permission',
|
|
61
|
+
permissions: [
|
|
62
|
+
FOLDER_PERMISSIONS.UPDATE
|
|
63
|
+
]
|
|
64
|
+
},
|
|
65
|
+
updateMany: {
|
|
66
|
+
level: 'permission',
|
|
67
|
+
permissions: [
|
|
68
|
+
FOLDER_PERMISSIONS.UPDATE
|
|
69
|
+
]
|
|
70
|
+
},
|
|
71
|
+
delete: {
|
|
72
|
+
level: 'permission',
|
|
73
|
+
permissions: [
|
|
74
|
+
FOLDER_PERMISSIONS.DELETE
|
|
75
|
+
]
|
|
76
|
+
}
|
|
77
|
+
}
|
|
35
78
|
}) {
|
|
36
79
|
constructor(folderService){
|
|
37
80
|
super(folderService), _define_property(this, "folderService", void 0), this.folderService = folderService;
|
|
@@ -25,13 +25,56 @@ function _ts_param(paramIndex, decorator) {
|
|
|
25
25
|
decorator(target, key, paramIndex);
|
|
26
26
|
};
|
|
27
27
|
}
|
|
28
|
-
import { createApiController } from '@flusys/nestjs-shared/classes';
|
|
28
|
+
import { createApiController, STORAGE_CONFIG_PERMISSIONS } from '@flusys/nestjs-shared/classes';
|
|
29
29
|
import { CreateStorageConfigDto, StorageConfigResponseDto, UpdateStorageConfigDto } from '../dtos';
|
|
30
30
|
import { Controller, Inject } from '@nestjs/common';
|
|
31
31
|
import { ApiTags } from '@nestjs/swagger';
|
|
32
32
|
import { StorageProviderConfigService } from '../services/storage-provider-config.service';
|
|
33
33
|
export class StorageConfigController extends createApiController(CreateStorageConfigDto, UpdateStorageConfigDto, StorageConfigResponseDto, {
|
|
34
|
-
security:
|
|
34
|
+
security: {
|
|
35
|
+
insert: {
|
|
36
|
+
level: 'permission',
|
|
37
|
+
permissions: [
|
|
38
|
+
STORAGE_CONFIG_PERMISSIONS.CREATE
|
|
39
|
+
]
|
|
40
|
+
},
|
|
41
|
+
insertMany: {
|
|
42
|
+
level: 'permission',
|
|
43
|
+
permissions: [
|
|
44
|
+
STORAGE_CONFIG_PERMISSIONS.CREATE
|
|
45
|
+
]
|
|
46
|
+
},
|
|
47
|
+
getById: {
|
|
48
|
+
level: 'permission',
|
|
49
|
+
permissions: [
|
|
50
|
+
STORAGE_CONFIG_PERMISSIONS.READ
|
|
51
|
+
]
|
|
52
|
+
},
|
|
53
|
+
getAll: {
|
|
54
|
+
level: 'permission',
|
|
55
|
+
permissions: [
|
|
56
|
+
STORAGE_CONFIG_PERMISSIONS.READ
|
|
57
|
+
]
|
|
58
|
+
},
|
|
59
|
+
update: {
|
|
60
|
+
level: 'permission',
|
|
61
|
+
permissions: [
|
|
62
|
+
STORAGE_CONFIG_PERMISSIONS.UPDATE
|
|
63
|
+
]
|
|
64
|
+
},
|
|
65
|
+
updateMany: {
|
|
66
|
+
level: 'permission',
|
|
67
|
+
permissions: [
|
|
68
|
+
STORAGE_CONFIG_PERMISSIONS.UPDATE
|
|
69
|
+
]
|
|
70
|
+
},
|
|
71
|
+
delete: {
|
|
72
|
+
level: 'permission',
|
|
73
|
+
permissions: [
|
|
74
|
+
STORAGE_CONFIG_PERMISSIONS.DELETE
|
|
75
|
+
]
|
|
76
|
+
}
|
|
77
|
+
}
|
|
35
78
|
}) {
|
|
36
79
|
constructor(storageConfigService){
|
|
37
80
|
super(storageConfigService), _define_property(this, "storageConfigService", void 0), this.storageConfigService = storageConfigService;
|
|
@@ -26,45 +26,38 @@ function _ts_param(paramIndex, decorator) {
|
|
|
26
26
|
};
|
|
27
27
|
}
|
|
28
28
|
import { JwtAuthGuard } from '@flusys/nestjs-shared/guards';
|
|
29
|
-
import { ApiResponseDto, CurrentUser } from '@flusys/nestjs-shared/decorators';
|
|
29
|
+
import { ApiResponseDto, CurrentUser, RequirePermission } from '@flusys/nestjs-shared/decorators';
|
|
30
30
|
import { ILoggedUserInfo } from '@flusys/nestjs-shared/interfaces';
|
|
31
31
|
import { DeleteMultipleFileDto, DeleteSingleFileDto, FileUploadResponsePayloadDto, UploadOptionsDto } from '../dtos';
|
|
32
32
|
import { Body, Controller, Inject, Post, Query, UploadedFile, UploadedFiles, UseGuards, UseInterceptors } from '@nestjs/common';
|
|
33
33
|
import { FileInterceptor, FilesInterceptor } from '@nestjs/platform-express';
|
|
34
34
|
import { ApiBearerAuth, ApiBody, ApiConsumes, ApiOperation, ApiQuery, ApiTags } from '@nestjs/swagger';
|
|
35
35
|
import { UploadService } from '../services/upload.service';
|
|
36
|
-
import { StorageConfigService } from '../config';
|
|
37
|
-
import { StorageFactoryService } from '../providers/storage-factory.service';
|
|
38
36
|
export class UploadController {
|
|
37
|
+
toFileUploadResponse(file) {
|
|
38
|
+
return {
|
|
39
|
+
size: this.uploadService.bytesToKb(file.size),
|
|
40
|
+
name: file.name,
|
|
41
|
+
key: file.key,
|
|
42
|
+
contentType: file.contentType,
|
|
43
|
+
location: file.location || 'local',
|
|
44
|
+
storageConfigId: file.storageConfigId || ''
|
|
45
|
+
};
|
|
46
|
+
}
|
|
39
47
|
async uploadSingleFile(file, options, user) {
|
|
40
48
|
const result = await this.uploadService.uploadSingleFile(file, options, user);
|
|
41
49
|
return {
|
|
42
50
|
success: true,
|
|
43
51
|
message: 'File uploaded successfully',
|
|
44
|
-
data:
|
|
45
|
-
size: this.uploadService.bytesToKb(result.size),
|
|
46
|
-
name: result.name,
|
|
47
|
-
key: result.key,
|
|
48
|
-
contentType: result.contentType,
|
|
49
|
-
location: result.location || 'local',
|
|
50
|
-
storageConfigId: result.storageConfigId || ''
|
|
51
|
-
}
|
|
52
|
+
data: this.toFileUploadResponse(result)
|
|
52
53
|
};
|
|
53
54
|
}
|
|
54
55
|
async uploadMultipleFiles(files, options, user) {
|
|
55
56
|
const uploadResponses = await this.uploadService.uploadMultipleFiles(files, options, user);
|
|
56
|
-
const responseData = uploadResponses.map((file)=>({
|
|
57
|
-
size: this.uploadService.bytesToKb(file.size),
|
|
58
|
-
name: file.name,
|
|
59
|
-
key: file.key,
|
|
60
|
-
contentType: file.contentType,
|
|
61
|
-
location: file.location || 'local',
|
|
62
|
-
storageConfigId: file.storageConfigId || ''
|
|
63
|
-
}));
|
|
64
57
|
return {
|
|
65
58
|
success: true,
|
|
66
59
|
message: 'Files uploaded successfully',
|
|
67
|
-
data:
|
|
60
|
+
data: uploadResponses.map((file)=>this.toFileUploadResponse(file))
|
|
68
61
|
};
|
|
69
62
|
}
|
|
70
63
|
async deleteSingleFile(dto, user) {
|
|
@@ -83,17 +76,14 @@ export class UploadController {
|
|
|
83
76
|
data
|
|
84
77
|
};
|
|
85
78
|
}
|
|
86
|
-
constructor(uploadService
|
|
79
|
+
constructor(uploadService){
|
|
87
80
|
_define_property(this, "uploadService", void 0);
|
|
88
|
-
_define_property(this, "storageConfigService", void 0);
|
|
89
|
-
_define_property(this, "storageFactoryService", void 0);
|
|
90
81
|
this.uploadService = uploadService;
|
|
91
|
-
this.storageConfigService = storageConfigService;
|
|
92
|
-
this.storageFactoryService = storageFactoryService;
|
|
93
82
|
}
|
|
94
83
|
}
|
|
95
84
|
_ts_decorate([
|
|
96
85
|
Post('single-file'),
|
|
86
|
+
RequirePermission('file.upload'),
|
|
97
87
|
ApiResponseDto(FileUploadResponsePayloadDto, false),
|
|
98
88
|
ApiOperation({
|
|
99
89
|
summary: 'Upload a single file'
|
|
@@ -135,6 +125,7 @@ _ts_decorate([
|
|
|
135
125
|
], UploadController.prototype, "uploadSingleFile", null);
|
|
136
126
|
_ts_decorate([
|
|
137
127
|
Post('multiple-file'),
|
|
128
|
+
RequirePermission('file.upload'),
|
|
138
129
|
ApiOperation({
|
|
139
130
|
summary: 'Upload multiple files (up to 50)'
|
|
140
131
|
}),
|
|
@@ -179,6 +170,7 @@ _ts_decorate([
|
|
|
179
170
|
], UploadController.prototype, "uploadMultipleFiles", null);
|
|
180
171
|
_ts_decorate([
|
|
181
172
|
Post('delete-single-file'),
|
|
173
|
+
RequirePermission('file.delete'),
|
|
182
174
|
ApiOperation({
|
|
183
175
|
summary: 'Delete a single file'
|
|
184
176
|
}),
|
|
@@ -196,6 +188,7 @@ _ts_decorate([
|
|
|
196
188
|
], UploadController.prototype, "deleteSingleFile", null);
|
|
197
189
|
_ts_decorate([
|
|
198
190
|
Post('delete-multiple-file'),
|
|
191
|
+
RequirePermission('file.delete'),
|
|
199
192
|
ApiOperation({
|
|
200
193
|
summary: 'Delete multiple files'
|
|
201
194
|
}),
|
|
@@ -217,12 +210,8 @@ UploadController = _ts_decorate([
|
|
|
217
210
|
Controller('storage/upload'),
|
|
218
211
|
UseGuards(JwtAuthGuard),
|
|
219
212
|
_ts_param(0, Inject(UploadService)),
|
|
220
|
-
_ts_param(1, Inject(StorageConfigService)),
|
|
221
|
-
_ts_param(2, Inject(StorageFactoryService)),
|
|
222
213
|
_ts_metadata("design:type", Function),
|
|
223
214
|
_ts_metadata("design:paramtypes", [
|
|
224
|
-
typeof UploadService === "undefined" ? Object : UploadService
|
|
225
|
-
typeof StorageConfigService === "undefined" ? Object : StorageConfigService,
|
|
226
|
-
typeof StorageFactoryService === "undefined" ? Object : StorageFactoryService
|
|
215
|
+
typeof UploadService === "undefined" ? Object : UploadService
|
|
227
216
|
])
|
|
228
217
|
], UploadController);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
const COMPANY_SCHEMA_EXCLUSIONS = [
|
|
2
2
|
{
|
|
3
3
|
schemaName: 'FileManagerResponseDto',
|
|
4
4
|
properties: [
|
|
@@ -18,126 +18,18 @@
|
|
|
18
18
|
]
|
|
19
19
|
}
|
|
20
20
|
];
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
* @param bootstrapConfig - Bootstrap configuration to determine feature visibility
|
|
26
|
-
* @returns Swagger configuration with appropriate excludeSchemaProperties based on enableCompanyFeature
|
|
27
|
-
*/ export function storageSwaggerConfig(bootstrapConfig) {
|
|
28
|
-
const enableCompanyFeature = bootstrapConfig?.enableCompanyFeature ?? true;
|
|
29
|
-
return {
|
|
30
|
-
title: 'Storage API',
|
|
31
|
-
description: enableCompanyFeature ? `
|
|
32
|
-
# Storage Management API
|
|
33
|
-
|
|
34
|
-
Complete file storage and management system with multi-tenant support.
|
|
35
|
-
|
|
36
|
-
## Features
|
|
37
|
-
|
|
38
|
-
### 📁 File Management
|
|
39
|
-
- Upload single or multiple files
|
|
40
|
-
- Download files with presigned URLs
|
|
41
|
-
- Delete files (single or batch)
|
|
42
|
-
- File metadata management
|
|
43
|
-
- Automatic compression and optimization
|
|
44
|
-
- **Company isolation**
|
|
45
|
-
|
|
46
|
-
### 🗂️ Folder Company
|
|
47
|
-
- Create folder hierarchies
|
|
48
|
-
- Organize files by folders
|
|
49
|
-
- **Company-level permissions**
|
|
50
|
-
- Automatic context filtering
|
|
51
|
-
|
|
52
|
-
### ⚙️ Storage Configuration
|
|
53
|
-
- Multiple storage providers (AWS S3, Azure, SFTP, Local)
|
|
54
|
-
- Provider-specific configurations
|
|
55
|
-
- Default storage settings
|
|
56
|
-
- Dynamic provider switching
|
|
57
|
-
|
|
58
|
-
### 🔒 Security
|
|
59
|
-
- JWT authentication required
|
|
60
|
-
- **Company isolation**
|
|
61
|
-
- File access control
|
|
62
|
-
- Presigned URL generation
|
|
63
|
-
|
|
64
|
-
## Storage Providers
|
|
65
|
-
|
|
66
|
-
### AWS S3
|
|
67
|
-
- Scalable cloud storage
|
|
68
|
-
- Automatic redundancy
|
|
69
|
-
- Global CDN integration
|
|
70
|
-
|
|
71
|
-
### Azure Blob Storage
|
|
72
|
-
- Microsoft Azure integration
|
|
73
|
-
- Geo-redundant storage
|
|
74
|
-
- Advanced security features
|
|
75
|
-
|
|
76
|
-
### SFTP
|
|
77
|
-
- Secure file transfer
|
|
78
|
-
- Legacy system integration
|
|
79
|
-
- Custom server support
|
|
80
|
-
|
|
81
|
-
### Local Storage
|
|
82
|
-
- Same-server storage
|
|
83
|
-
- Fast access
|
|
84
|
-
- No external dependencies
|
|
85
|
-
|
|
21
|
+
function buildDescription(enableCompanyFeature) {
|
|
22
|
+
const companyIsolation = enableCompanyFeature ? '\n- **Company isolation**' : '';
|
|
23
|
+
const companyPermissions = enableCompanyFeature ? '\n- **Company-level permissions**' : '';
|
|
24
|
+
const multiTenantSection = enableCompanyFeature ? `
|
|
86
25
|
## Multi-Tenant Support
|
|
87
26
|
|
|
88
27
|
Files are automatically isolated by:
|
|
89
28
|
- **Company ID**: Company-level storage
|
|
90
29
|
|
|
91
30
|
All queries automatically filter by current user's company context.
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
### Size Limits
|
|
96
|
-
Configure maximum file size per upload (default: 10MB)
|
|
97
|
-
|
|
98
|
-
### File Types
|
|
99
|
-
Restrict allowed file types (default: images, PDFs)
|
|
100
|
-
|
|
101
|
-
### Image Compression
|
|
102
|
-
- Automatic image optimization
|
|
103
|
-
- Format conversion (JPEG, PNG, WebP, AVIF)
|
|
104
|
-
- Resize to maximum dimensions
|
|
105
|
-
- Quality control
|
|
106
|
-
|
|
107
|
-
## Response Format
|
|
108
|
-
|
|
109
|
-
All endpoints return standardized responses with success status, data, message, and timestamp.
|
|
110
|
-
|
|
111
|
-
## Error Handling
|
|
112
|
-
|
|
113
|
-
Errors return structured responses with success false, error message, error code, and timestamp.
|
|
114
|
-
|
|
115
|
-
## Common Error Codes
|
|
116
|
-
|
|
117
|
-
- **400 Bad Request**: Invalid input data
|
|
118
|
-
- **401 Unauthorized**: Missing or invalid authentication
|
|
119
|
-
- **403 Forbidden**: Insufficient permissions
|
|
120
|
-
- **404 Not Found**: Resource not found
|
|
121
|
-
- **413 Payload Too Large**: File exceeds size limit
|
|
122
|
-
- **415 Unsupported Media Type**: File type not allowed
|
|
123
|
-
- **500 Internal Server Error**: Server error
|
|
124
|
-
|
|
125
|
-
## Getting Started
|
|
126
|
-
|
|
127
|
-
1. **Authenticate**: Obtain JWT token from /auth/login
|
|
128
|
-
2. **Configure Storage**: Create storage configuration via /storage/storage-config/insert
|
|
129
|
-
3. **Create Folders**: Organize files with /storage/folder/insert
|
|
130
|
-
4. **Upload Files**: Upload files via /storage/upload/single-file
|
|
131
|
-
5. **Manage Files**: Track uploads in /storage/file-manager
|
|
132
|
-
|
|
133
|
-
## API Endpoints
|
|
134
|
-
|
|
135
|
-
All storage endpoints are prefixed with \`/storage\`:
|
|
136
|
-
- \`/storage/file-manager/*\` - File metadata management
|
|
137
|
-
- \`/storage/folder/*\` - Folder organization
|
|
138
|
-
- \`/storage/storage-config/*\` - Storage configuration
|
|
139
|
-
- \`/storage/upload/*\` - File upload/download
|
|
140
|
-
|
|
31
|
+
` : '';
|
|
32
|
+
const examplesSection = enableCompanyFeature ? `
|
|
141
33
|
## Examples
|
|
142
34
|
|
|
143
35
|
### Upload a File
|
|
@@ -151,27 +43,11 @@ POST /storage/file-manager/get-all with JSON body containing page and pageSize p
|
|
|
151
43
|
### Create Folder
|
|
152
44
|
|
|
153
45
|
POST /storage/folder/insert with JSON body containing folder name
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
1. **Always authenticate**: Include JWT token in Authorization header
|
|
158
|
-
2. **Use folders**: Organize files hierarchically
|
|
159
|
-
3. **Check file size**: Validate before upload
|
|
160
|
-
4. **Handle errors**: Implement proper error handling
|
|
161
|
-
5. **Clean up**: Delete unused files regularly
|
|
162
|
-
6. **Use presigned URLs**: Generate temporary URLs for file access
|
|
163
|
-
7. **Compress images**: Enable compression for faster loading
|
|
164
|
-
|
|
165
|
-
## Rate Limiting
|
|
166
|
-
|
|
167
|
-
All endpoints are rate-limited to prevent abuse. Default limits:
|
|
168
|
-
- **Upload**: 100 requests per hour
|
|
169
|
-
- **Download**: 1000 requests per hour
|
|
170
|
-
- **Delete**: 50 requests per hour
|
|
171
|
-
` : `
|
|
46
|
+
` : '';
|
|
47
|
+
return `
|
|
172
48
|
# Storage Management API
|
|
173
49
|
|
|
174
|
-
Complete file storage and management system.
|
|
50
|
+
Complete file storage and management system${enableCompanyFeature ? ' with multi-tenant support' : ''}.
|
|
175
51
|
|
|
176
52
|
## Features
|
|
177
53
|
|
|
@@ -180,12 +56,12 @@ Complete file storage and management system.
|
|
|
180
56
|
- Download files with presigned URLs
|
|
181
57
|
- Delete files (single or batch)
|
|
182
58
|
- File metadata management
|
|
183
|
-
- Automatic compression and optimization
|
|
59
|
+
- Automatic compression and optimization${companyIsolation}
|
|
184
60
|
|
|
185
|
-
### 🗂️ Folder
|
|
61
|
+
### 🗂️ Folder Organization
|
|
186
62
|
- Create folder hierarchies
|
|
187
|
-
- Organize files by folders
|
|
188
|
-
-
|
|
63
|
+
- Organize files by folders${companyPermissions}
|
|
64
|
+
- Automatic context filtering
|
|
189
65
|
|
|
190
66
|
### ⚙️ Storage Configuration
|
|
191
67
|
- Multiple storage providers (AWS S3, Azure, SFTP, Local)
|
|
@@ -194,7 +70,7 @@ Complete file storage and management system.
|
|
|
194
70
|
- Dynamic provider switching
|
|
195
71
|
|
|
196
72
|
### 🔒 Security
|
|
197
|
-
- JWT authentication required
|
|
73
|
+
- JWT authentication required${companyIsolation}
|
|
198
74
|
- File access control
|
|
199
75
|
- Presigned URL generation
|
|
200
76
|
|
|
@@ -219,7 +95,7 @@ Complete file storage and management system.
|
|
|
219
95
|
- Same-server storage
|
|
220
96
|
- Fast access
|
|
221
97
|
- No external dependencies
|
|
222
|
-
|
|
98
|
+
${multiTenantSection}
|
|
223
99
|
## File Validation
|
|
224
100
|
|
|
225
101
|
### Size Limits
|
|
@@ -267,7 +143,7 @@ All storage endpoints are prefixed with \`/storage\`:
|
|
|
267
143
|
- \`/storage/folder/*\` - Folder organization
|
|
268
144
|
- \`/storage/storage-config/*\` - Storage configuration
|
|
269
145
|
- \`/storage/upload/*\` - File upload/download
|
|
270
|
-
|
|
146
|
+
${examplesSection}
|
|
271
147
|
## Best Practices
|
|
272
148
|
|
|
273
149
|
1. **Always authenticate**: Include JWT token in Authorization header
|
|
@@ -284,7 +160,16 @@ All endpoints are rate-limited to prevent abuse. Default limits:
|
|
|
284
160
|
- **Upload**: 100 requests per hour
|
|
285
161
|
- **Download**: 1000 requests per hour
|
|
286
162
|
- **Delete**: 50 requests per hour
|
|
287
|
-
|
|
163
|
+
`;
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Storage Module Swagger Configuration
|
|
167
|
+
* Use this with setupSwaggerDocs() from @flusys/nestjs-core
|
|
168
|
+
*/ export function storageSwaggerConfig(bootstrapConfig) {
|
|
169
|
+
const enableCompanyFeature = bootstrapConfig?.enableCompanyFeature ?? true;
|
|
170
|
+
return {
|
|
171
|
+
title: 'Storage API',
|
|
172
|
+
description: buildDescription(enableCompanyFeature),
|
|
288
173
|
version: '1.0',
|
|
289
174
|
path: 'api/docs/storage',
|
|
290
175
|
bearerAuth: true,
|