@flusys/nestjs-storage 1.1.0-beta → 1.1.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.
Files changed (118) hide show
  1. package/README.md +153 -8
  2. package/cjs/config/index.js +0 -1
  3. package/cjs/config/storage.constants.js +0 -17
  4. package/cjs/controllers/file-manager.controller.js +44 -1
  5. package/cjs/controllers/folder.controller.js +44 -1
  6. package/cjs/controllers/storage-config.controller.js +44 -1
  7. package/cjs/controllers/upload.controller.js +18 -29
  8. package/cjs/docs/storage-swagger.config.js +24 -136
  9. package/cjs/dtos/file-manager.dto.js +71 -35
  10. package/cjs/dtos/folder.dto.js +15 -9
  11. package/cjs/dtos/storage-config.dto.js +5 -86
  12. package/cjs/dtos/upload.dto.js +24 -17
  13. package/cjs/entities/file-manager-with-company.entity.js +3 -4
  14. package/cjs/entities/file-manager.entity.js +71 -3
  15. package/cjs/entities/folder-with-company.entity.js +3 -4
  16. package/cjs/entities/folder.entity.js +19 -3
  17. package/cjs/entities/index.js +9 -10
  18. package/cjs/entities/storage-config-with-company.entity.js +3 -4
  19. package/cjs/entities/storage-config.entity.js +73 -3
  20. package/cjs/interfaces/index.js +0 -1
  21. package/cjs/middlewares/file-serve.middleware.js +113 -100
  22. package/cjs/modules/storage.module.js +82 -136
  23. package/cjs/providers/azure-provider.optional.js +10 -38
  24. package/cjs/providers/local-provider.js +38 -31
  25. package/cjs/providers/s3-provider.optional.js +19 -40
  26. package/cjs/providers/storage-factory.service.js +54 -99
  27. package/cjs/providers/storage-provider.registry.js +8 -18
  28. package/cjs/services/file-manager.service.js +238 -323
  29. package/cjs/services/folder.service.js +8 -11
  30. package/cjs/services/index.js +1 -0
  31. package/cjs/{config → services}/storage-config.service.js +32 -76
  32. package/cjs/services/storage-datasource.provider.js +16 -26
  33. package/cjs/services/storage-provider-config.service.js +15 -37
  34. package/cjs/services/upload.service.js +72 -88
  35. package/cjs/utils/file-validator.util.js +458 -0
  36. package/cjs/utils/image-compressor.util.js +3 -8
  37. package/config/index.d.ts +0 -1
  38. package/config/storage.constants.d.ts +0 -8
  39. package/controllers/upload.controller.d.ts +3 -6
  40. package/dtos/file-manager.dto.d.ts +13 -7
  41. package/dtos/folder.dto.d.ts +5 -5
  42. package/dtos/storage-config.dto.d.ts +9 -16
  43. package/entities/file-manager-with-company.entity.d.ts +2 -2
  44. package/entities/file-manager.entity.d.ts +11 -2
  45. package/entities/folder-with-company.entity.d.ts +2 -2
  46. package/entities/folder.entity.d.ts +4 -2
  47. package/entities/index.d.ts +3 -4
  48. package/entities/storage-config-with-company.entity.d.ts +2 -2
  49. package/entities/storage-config.entity.d.ts +7 -2
  50. package/fesm/config/index.js +0 -1
  51. package/fesm/config/storage.constants.js +0 -8
  52. package/fesm/controllers/file-manager.controller.js +45 -2
  53. package/fesm/controllers/folder.controller.js +45 -2
  54. package/fesm/controllers/storage-config.controller.js +45 -2
  55. package/fesm/controllers/upload.controller.js +19 -30
  56. package/fesm/docs/storage-swagger.config.js +27 -142
  57. package/fesm/dtos/file-manager.dto.js +72 -36
  58. package/fesm/dtos/folder.dto.js +16 -10
  59. package/fesm/dtos/storage-config.dto.js +9 -96
  60. package/fesm/dtos/upload.dto.js +25 -19
  61. package/fesm/entities/file-manager-with-company.entity.js +3 -4
  62. package/fesm/entities/file-manager.entity.js +72 -4
  63. package/fesm/entities/folder-with-company.entity.js +3 -4
  64. package/fesm/entities/folder.entity.js +20 -4
  65. package/fesm/entities/index.js +5 -13
  66. package/fesm/entities/storage-config-with-company.entity.js +3 -4
  67. package/fesm/entities/storage-config.entity.js +74 -4
  68. package/fesm/interfaces/index.js +0 -1
  69. package/fesm/interfaces/storage-config.interface.js +1 -3
  70. package/fesm/middlewares/file-serve.middleware.js +114 -101
  71. package/fesm/modules/storage.module.js +83 -136
  72. package/fesm/providers/azure-provider.optional.js +14 -45
  73. package/fesm/providers/local-provider.js +38 -31
  74. package/fesm/providers/s3-provider.optional.js +23 -47
  75. package/fesm/providers/storage-factory.service.js +52 -97
  76. package/fesm/providers/storage-provider.registry.js +10 -20
  77. package/fesm/services/file-manager.service.js +237 -322
  78. package/fesm/services/folder.service.js +6 -9
  79. package/fesm/services/index.js +1 -0
  80. package/fesm/{config → services}/storage-config.service.js +32 -76
  81. package/fesm/services/storage-datasource.provider.js +16 -26
  82. package/fesm/services/storage-provider-config.service.js +13 -35
  83. package/fesm/services/upload.service.js +71 -87
  84. package/fesm/utils/file-validator.util.js +451 -0
  85. package/fesm/utils/image-compressor.util.js +3 -8
  86. package/interfaces/file-manager.interface.d.ts +7 -4
  87. package/interfaces/index.d.ts +0 -1
  88. package/interfaces/storage-config.interface.d.ts +1 -22
  89. package/interfaces/storage-module-options.interface.d.ts +0 -5
  90. package/middlewares/file-serve.middleware.d.ts +9 -1
  91. package/modules/storage.module.d.ts +1 -2
  92. package/package.json +6 -6
  93. package/providers/azure-provider.optional.d.ts +8 -6
  94. package/providers/local-provider.d.ts +2 -7
  95. package/providers/s3-provider.optional.d.ts +9 -7
  96. package/providers/storage-factory.service.d.ts +8 -9
  97. package/providers/storage-provider.registry.d.ts +4 -4
  98. package/services/file-manager.service.d.ts +23 -16
  99. package/services/folder.service.d.ts +4 -4
  100. package/services/index.d.ts +1 -0
  101. package/services/storage-config.service.d.ts +24 -0
  102. package/services/storage-datasource.provider.d.ts +3 -4
  103. package/services/storage-provider-config.service.d.ts +5 -6
  104. package/services/upload.service.d.ts +5 -5
  105. package/utils/file-validator.util.d.ts +19 -0
  106. package/cjs/entities/file-manager-base.entity.js +0 -115
  107. package/cjs/entities/folder-base.entity.js +0 -55
  108. package/cjs/entities/storage-config-base.entity.js +0 -93
  109. package/cjs/interfaces/file-upload-response.interface.js +0 -4
  110. package/config/storage-config.service.d.ts +0 -22
  111. package/entities/file-manager-base.entity.d.ts +0 -13
  112. package/entities/folder-base.entity.d.ts +0 -5
  113. package/entities/storage-config-base.entity.d.ts +0 -9
  114. package/fesm/entities/file-manager-base.entity.js +0 -108
  115. package/fesm/entities/folder-base.entity.js +0 -48
  116. package/fesm/entities/storage-config-base.entity.js +0 -83
  117. package/fesm/interfaces/file-upload-response.interface.js +0 -1
  118. package/interfaces/file-upload-response.interface.d.ts +0 -6
package/README.md CHANGED
@@ -1,6 +1,7 @@
1
1
  # Storage Package Guide
2
2
 
3
3
  > **Package:** `@flusys/nestjs-storage`
4
+ > **Version:** 1.1.0
4
5
  > **Type:** File storage system with pluggable providers and multi-tenant support
5
6
 
6
7
  This comprehensive guide covers the storage package - flexible file storage with multiple provider support.
@@ -9,8 +10,10 @@ This comprehensive guide covers the storage package - flexible file storage with
9
10
 
10
11
  - [Overview](#overview)
11
12
  - [Installation](#installation)
13
+ - [Constants](#constants)
12
14
  - [Package Architecture](#package-architecture)
13
15
  - [Module Setup](#module-setup)
16
+ - [Entities](#entities)
14
17
  - [Storage Providers](#storage-providers)
15
18
  - [Storage Configuration](#storage-configuration)
16
19
  - [File Manager](#file-manager)
@@ -62,6 +65,19 @@ npm install ssh2-sftp-client # For SFTP
62
65
 
63
66
  ---
64
67
 
68
+ ## Constants
69
+
70
+ ```typescript
71
+ // Injection Token
72
+ export const STORAGE_MODULE_OPTIONS = 'STORAGE_MODULE_OPTIONS';
73
+
74
+ // Default Configuration
75
+ export const DEFAULT_MAX_FILE_SIZE = 100 * 1024 * 1024; // 100MB
76
+ export const DEFAULT_ALLOWED_FILE_TYPES = ['*/*']; // All file types
77
+ ```
78
+
79
+ ---
80
+
65
81
  ## Package Architecture
66
82
 
67
83
  ```
@@ -89,6 +105,7 @@ nestjs-storage/
89
105
  │ │ ├── file-manager.service.ts # File metadata CRUD
90
106
  │ │ ├── folder.service.ts # Folder CRUD
91
107
  │ │ ├── storage-provider-config.service.ts
108
+ │ │ ├── storage-datasource.provider.ts # Dynamic entity loading
92
109
  │ │ └── index.ts
93
110
  │ │
94
111
  │ ├── controllers/
@@ -99,13 +116,12 @@ nestjs-storage/
99
116
  │ │ └── index.ts
100
117
  │ │
101
118
  │ ├── entities/
102
- │ │ ├── file-manager.entity.ts # File metadata
103
- │ │ ├── file-manager-base.entity.ts
119
+ │ │ ├── file-manager.entity.ts # FileManager (core), aliased as FileManagerBase
104
120
  │ │ ├── file-manager-with-company.entity.ts
105
- │ │ ├── folder.entity.ts # Folder structure
106
- │ │ ├── folder-base.entity.ts
121
+ │ │ ├── folder.entity.ts # Folder (core), aliased as FolderBase
107
122
  │ │ ├── folder-with-company.entity.ts
108
- │ │ ├── storage-config.entity.ts # Provider configs
123
+ │ │ ├── storage-config.entity.ts # StorageConfig (core), aliased as StorageConfigBase
124
+ │ │ ├── storage-config-with-company.entity.ts
109
125
  │ │ └── index.ts
110
126
  │ │
111
127
  │ ├── dtos/
@@ -116,15 +132,23 @@ nestjs-storage/
116
132
  │ │ └── index.ts
117
133
  │ │
118
134
  │ ├── interfaces/
119
- │ │ ├── storage-provider.interface.ts
135
+ │ │ ├── file-manager.interface.ts
136
+ │ │ ├── folder.interface.ts
137
+ │ │ ├── storage-config.interface.ts
120
138
  │ │ ├── storage-module-options.interface.ts
139
+ │ │ ├── storage-provider.interface.ts
121
140
  │ │ └── index.ts
122
141
  │ │
123
142
  │ ├── enums/
124
143
  │ │ ├── file-location.enum.ts
125
144
  │ │ └── index.ts
126
145
  │ │
146
+ │ ├── middlewares/
147
+ │ │ ├── file-serve.middleware.ts
148
+ │ │ └── index.ts
149
+ │ │
127
150
  │ └── utils/
151
+ │ ├── file-validator.util.ts
128
152
  │ ├── image-compressor.util.ts
129
153
  │ └── index.ts
130
154
  ```
@@ -253,6 +277,34 @@ This ensures the API documentation accurately reflects the available fields base
253
277
 
254
278
  ---
255
279
 
280
+ ## Entities
281
+
282
+ ### Entity Groups
283
+
284
+ ```typescript
285
+ // Core entities (no company feature)
286
+ export const StorageCoreEntities = [FileManager, Folder, StorageConfig];
287
+
288
+ // Company-specific entities
289
+ export const StorageCompanyEntities = [
290
+ FileManagerWithCompany,
291
+ FolderWithCompany,
292
+ StorageConfigWithCompany,
293
+ ];
294
+
295
+ // Helper function
296
+ export function getStorageEntitiesByConfig(enableCompanyFeature: boolean): any[] {
297
+ return enableCompanyFeature ? StorageCompanyEntities : StorageCoreEntities;
298
+ }
299
+
300
+ // Base type aliases for backwards compatibility
301
+ export { FileManager as FileManagerBase } from './file-manager.entity';
302
+ export { Folder as FolderBase } from './folder.entity';
303
+ export { StorageConfig as StorageConfigBase } from './storage-config.entity';
304
+ ```
305
+
306
+ ---
307
+
256
308
  ## Storage Providers
257
309
 
258
310
  ### Provider Types
@@ -470,6 +522,93 @@ export class SetupService {
470
522
  }
471
523
  ```
472
524
 
525
+ ### Storage Provider Resolution Flow
526
+
527
+ When performing upload operations, the `UploadService` resolves the storage provider using a multi-level fallback strategy:
528
+
529
+ **Resolution Flow Diagram:**
530
+
531
+ ```
532
+ Upload Request (with optional storageConfigId)
533
+
534
+
535
+ ┌─────────────────────────────────────────────────────────┐
536
+ │ 1. Check if storageConfigId provided │
537
+ └─────────────────────────────────────────────────────────┘
538
+
539
+ provided? ─┴── no ──┐
540
+ │ │
541
+ ▼ ▼
542
+ ┌──────────────────┐ ┌─────────────────────────────────────┐
543
+ │ 2. Lookup config │ │ 3. Get default config for company │
544
+ │ by ID │ │ - Priority 1: isDefault=true │
545
+ └────────┬─────────┘ │ - Priority 2: oldest active │
546
+ │ └─────────────────────────────────────┘
547
+ │ │
548
+ ▼ ▼
549
+ ┌─────────────────────────────────────────────────────────┐
550
+ │ 4. Validate company ownership (if company feature) │
551
+ │ - Throws BadRequestException if wrong company │
552
+ └─────────────────────────────────────────────────────────┘
553
+
554
+
555
+ ┌─────────────────────────────────────────────────────────┐
556
+ │ 5. Create/reuse storage provider instance │
557
+ │ - Check provider cache by config hash │
558
+ │ - Create new if not cached │
559
+ └─────────────────────────────────────────────────────────┘
560
+
561
+
562
+ [Perform Upload]
563
+ ```
564
+
565
+ **Code Implementation:**
566
+
567
+ ```typescript
568
+ // UploadService
569
+ private async getStorageProvider(
570
+ storageConfigId?: string,
571
+ user?: ILoggedUserInfo,
572
+ ): Promise<{ provider: IStorageProvider; config: StorageConfigBase }> {
573
+ let config: StorageConfigBase | null = null;
574
+
575
+ // Step 1: Try to get by ID or fallback to default
576
+ if (storageConfigId) {
577
+ config = await this.storageProviderConfigService.findByIdDirect(storageConfigId);
578
+ }
579
+
580
+ if (!config) {
581
+ config = await this.storageProviderConfigService.getDefaultConfig(user);
582
+ }
583
+
584
+ if (!config) {
585
+ throw new BadRequestException('No storage configuration available');
586
+ }
587
+
588
+ // Step 2: Validate company ownership
589
+ if (this.storageConfigService.isCompanyFeatureEnabled() && user?.companyId) {
590
+ const configWithCompany = config as StorageConfigWithCompany;
591
+ if (configWithCompany.companyId && configWithCompany.companyId !== user.companyId) {
592
+ throw new BadRequestException('Storage configuration belongs to another company');
593
+ }
594
+ }
595
+
596
+ // Step 3: Get or create provider instance
597
+ const provider = await this.storageFactory.createProvider({
598
+ provider: config.storage,
599
+ config: config.config,
600
+ });
601
+
602
+ return { provider, config };
603
+ }
604
+ ```
605
+
606
+ **Key Points:**
607
+ - Always specify `storageConfigId` for deterministic behavior
608
+ - Without `storageConfigId`, system uses company's default config
609
+ - Company ownership is always validated when company feature is enabled
610
+ - Provider instances are cached for connection reuse
611
+
473
612
  ### Default Configuration Resolution
474
613
 
475
614
  When `storageConfigId` is not provided for uploads, the system automatically resolves the default config:
@@ -879,7 +1018,7 @@ curl -X POST http://localhost:3000/upload/single-file \
879
1018
 
880
1019
  ---
881
1020
 
882
- ## DataSource Provider Pattern (Updated 2026-01-16)
1021
+ ## DataSource Provider Pattern
883
1022
 
884
1023
  ### Overview
885
1024
 
@@ -1230,6 +1369,7 @@ import {
1230
1369
  FileManagerService,
1231
1370
  FolderService,
1232
1371
  StorageProviderConfigService,
1372
+ StorageDataSourceProvider,
1233
1373
  } from '@flusys/nestjs-storage/services';
1234
1374
 
1235
1375
  // Entities
@@ -1260,10 +1400,15 @@ import {
1260
1400
 
1261
1401
  // Interfaces
1262
1402
  import {
1403
+ IFileManager,
1404
+ IFolder,
1405
+ IStorageConfig,
1406
+ IStorageModuleConfig,
1263
1407
  IStorageProvider,
1264
1408
  IStorageProviderConfig,
1265
1409
  IUploadedFileInfo,
1266
1410
  StorageModuleOptions,
1411
+ StorageModuleAsyncOptions,
1267
1412
  } from '@flusys/nestjs-storage/interfaces';
1268
1413
 
1269
1414
  // Enums
@@ -1298,4 +1443,4 @@ The `@flusys/nestjs-storage` package provides:
1298
1443
 
1299
1444
  ---
1300
1445
 
1301
- **Last Updated:** 2026-02-16
1446
+ **Last Updated:** 2026-02-21
@@ -3,7 +3,6 @@ Object.defineProperty(exports, "__esModule", {
3
3
  value: true
4
4
  });
5
5
  _export_star(require("./storage.constants"), exports);
6
- _export_star(require("./storage-config.service"), exports);
7
6
  function _export_star(from, to) {
8
7
  Object.keys(from).forEach(function(k) {
9
8
  if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) {
@@ -17,29 +17,12 @@ _export(exports, {
17
17
  get DEFAULT_MAX_FILE_SIZE () {
18
18
  return DEFAULT_MAX_FILE_SIZE;
19
19
  },
20
- get FILE_VALIDATION_MESSAGES () {
21
- return FILE_VALIDATION_MESSAGES;
22
- },
23
- get STORAGE_CONFIG_SERVICE () {
24
- return STORAGE_CONFIG_SERVICE;
25
- },
26
- get STORAGE_DATA_SOURCE_PROVIDER () {
27
- return STORAGE_DATA_SOURCE_PROVIDER;
28
- },
29
20
  get STORAGE_MODULE_OPTIONS () {
30
21
  return STORAGE_MODULE_OPTIONS;
31
22
  }
32
23
  });
33
24
  const STORAGE_MODULE_OPTIONS = 'STORAGE_MODULE_OPTIONS';
34
- const STORAGE_CONFIG_SERVICE = 'STORAGE_CONFIG_SERVICE';
35
- const STORAGE_DATA_SOURCE_PROVIDER = 'STORAGE_DATA_SOURCE_PROVIDER';
36
25
  const DEFAULT_MAX_FILE_SIZE = 100 * 1024 * 1024; // 100MB
37
26
  const DEFAULT_ALLOWED_FILE_TYPES = [
38
27
  '*/*'
39
28
  ]; // All file types
40
- const FILE_VALIDATION_MESSAGES = {
41
- FILE_TOO_LARGE: 'File size exceeds the maximum allowed size',
42
- INVALID_FILE_TYPE: 'File type is not allowed',
43
- NO_FILE_PROVIDED: 'No file was provided',
44
- UPLOAD_FAILED: 'File upload failed'
45
- };
@@ -46,7 +46,50 @@ function _ts_param(paramIndex, decorator) {
46
46
  };
47
47
  }
48
48
  let FileManagerController = class FileManagerController extends (0, _classes.createApiController)(_dtos1.CreateFileManagerDto, _dtos1.UpdateFileManagerDto, _dtos1.FileManagerResponseDto, {
49
- security: 'jwt'
49
+ security: {
50
+ insert: {
51
+ level: 'permission',
52
+ permissions: [
53
+ _classes.FILE_PERMISSIONS.CREATE
54
+ ]
55
+ },
56
+ insertMany: {
57
+ level: 'permission',
58
+ permissions: [
59
+ _classes.FILE_PERMISSIONS.CREATE
60
+ ]
61
+ },
62
+ getById: {
63
+ level: 'permission',
64
+ permissions: [
65
+ _classes.FILE_PERMISSIONS.READ
66
+ ]
67
+ },
68
+ getAll: {
69
+ level: 'permission',
70
+ permissions: [
71
+ _classes.FILE_PERMISSIONS.READ
72
+ ]
73
+ },
74
+ update: {
75
+ level: 'permission',
76
+ permissions: [
77
+ _classes.FILE_PERMISSIONS.UPDATE
78
+ ]
79
+ },
80
+ updateMany: {
81
+ level: 'permission',
82
+ permissions: [
83
+ _classes.FILE_PERMISSIONS.UPDATE
84
+ ]
85
+ },
86
+ delete: {
87
+ level: 'permission',
88
+ permissions: [
89
+ _classes.FILE_PERMISSIONS.DELETE
90
+ ]
91
+ }
92
+ }
50
93
  }) {
51
94
  async getFiles(dto, req, user) {
52
95
  if (!dto || !dto.length) {
@@ -41,7 +41,50 @@ function _ts_param(paramIndex, decorator) {
41
41
  };
42
42
  }
43
43
  let FolderController = class FolderController extends (0, _classes.createApiController)(_dtos.CreateFolderDto, _dtos.UpdateFolderDto, _dtos.FolderResponseDto, {
44
- security: 'jwt'
44
+ security: {
45
+ insert: {
46
+ level: 'permission',
47
+ permissions: [
48
+ _classes.FOLDER_PERMISSIONS.CREATE
49
+ ]
50
+ },
51
+ insertMany: {
52
+ level: 'permission',
53
+ permissions: [
54
+ _classes.FOLDER_PERMISSIONS.CREATE
55
+ ]
56
+ },
57
+ getById: {
58
+ level: 'permission',
59
+ permissions: [
60
+ _classes.FOLDER_PERMISSIONS.READ
61
+ ]
62
+ },
63
+ getAll: {
64
+ level: 'permission',
65
+ permissions: [
66
+ _classes.FOLDER_PERMISSIONS.READ
67
+ ]
68
+ },
69
+ update: {
70
+ level: 'permission',
71
+ permissions: [
72
+ _classes.FOLDER_PERMISSIONS.UPDATE
73
+ ]
74
+ },
75
+ updateMany: {
76
+ level: 'permission',
77
+ permissions: [
78
+ _classes.FOLDER_PERMISSIONS.UPDATE
79
+ ]
80
+ },
81
+ delete: {
82
+ level: 'permission',
83
+ permissions: [
84
+ _classes.FOLDER_PERMISSIONS.DELETE
85
+ ]
86
+ }
87
+ }
45
88
  }) {
46
89
  constructor(folderService){
47
90
  super(folderService), _define_property(this, "folderService", void 0), this.folderService = folderService;
@@ -41,7 +41,50 @@ function _ts_param(paramIndex, decorator) {
41
41
  };
42
42
  }
43
43
  let StorageConfigController = class StorageConfigController extends (0, _classes.createApiController)(_dtos.CreateStorageConfigDto, _dtos.UpdateStorageConfigDto, _dtos.StorageConfigResponseDto, {
44
- security: 'jwt'
44
+ security: {
45
+ insert: {
46
+ level: 'permission',
47
+ permissions: [
48
+ _classes.STORAGE_CONFIG_PERMISSIONS.CREATE
49
+ ]
50
+ },
51
+ insertMany: {
52
+ level: 'permission',
53
+ permissions: [
54
+ _classes.STORAGE_CONFIG_PERMISSIONS.CREATE
55
+ ]
56
+ },
57
+ getById: {
58
+ level: 'permission',
59
+ permissions: [
60
+ _classes.STORAGE_CONFIG_PERMISSIONS.READ
61
+ ]
62
+ },
63
+ getAll: {
64
+ level: 'permission',
65
+ permissions: [
66
+ _classes.STORAGE_CONFIG_PERMISSIONS.READ
67
+ ]
68
+ },
69
+ update: {
70
+ level: 'permission',
71
+ permissions: [
72
+ _classes.STORAGE_CONFIG_PERMISSIONS.UPDATE
73
+ ]
74
+ },
75
+ updateMany: {
76
+ level: 'permission',
77
+ permissions: [
78
+ _classes.STORAGE_CONFIG_PERMISSIONS.UPDATE
79
+ ]
80
+ },
81
+ delete: {
82
+ level: 'permission',
83
+ permissions: [
84
+ _classes.STORAGE_CONFIG_PERMISSIONS.DELETE
85
+ ]
86
+ }
87
+ }
45
88
  }) {
46
89
  constructor(storageConfigService){
47
90
  super(storageConfigService), _define_property(this, "storageConfigService", void 0), this.storageConfigService = storageConfigService;
@@ -16,8 +16,6 @@ const _common = require("@nestjs/common");
16
16
  const _platformexpress = require("@nestjs/platform-express");
17
17
  const _swagger = require("@nestjs/swagger");
18
18
  const _uploadservice = require("../services/upload.service");
19
- const _config = require("../config");
20
- const _storagefactoryservice = require("../providers/storage-factory.service");
21
19
  function _define_property(obj, key, value) {
22
20
  if (key in obj) {
23
21
  Object.defineProperty(obj, key, {
@@ -46,35 +44,30 @@ function _ts_param(paramIndex, decorator) {
46
44
  };
47
45
  }
48
46
  let UploadController = class UploadController {
47
+ toFileUploadResponse(file) {
48
+ return {
49
+ size: this.uploadService.bytesToKb(file.size),
50
+ name: file.name,
51
+ key: file.key,
52
+ contentType: file.contentType,
53
+ location: file.location || 'local',
54
+ storageConfigId: file.storageConfigId || ''
55
+ };
56
+ }
49
57
  async uploadSingleFile(file, options, user) {
50
58
  const result = await this.uploadService.uploadSingleFile(file, options, user);
51
59
  return {
52
60
  success: true,
53
61
  message: 'File uploaded successfully',
54
- data: {
55
- size: this.uploadService.bytesToKb(result.size),
56
- name: result.name,
57
- key: result.key,
58
- contentType: result.contentType,
59
- location: result.location || 'local',
60
- storageConfigId: result.storageConfigId || ''
61
- }
62
+ data: this.toFileUploadResponse(result)
62
63
  };
63
64
  }
64
65
  async uploadMultipleFiles(files, options, user) {
65
66
  const uploadResponses = await this.uploadService.uploadMultipleFiles(files, options, user);
66
- const responseData = uploadResponses.map((file)=>({
67
- size: this.uploadService.bytesToKb(file.size),
68
- name: file.name,
69
- key: file.key,
70
- contentType: file.contentType,
71
- location: file.location || 'local',
72
- storageConfigId: file.storageConfigId || ''
73
- }));
74
67
  return {
75
68
  success: true,
76
69
  message: 'Files uploaded successfully',
77
- data: responseData
70
+ data: uploadResponses.map((file)=>this.toFileUploadResponse(file))
78
71
  };
79
72
  }
80
73
  async deleteSingleFile(dto, user) {
@@ -93,17 +86,14 @@ let UploadController = class UploadController {
93
86
  data
94
87
  };
95
88
  }
96
- constructor(uploadService, storageConfigService, storageFactoryService){
89
+ constructor(uploadService){
97
90
  _define_property(this, "uploadService", void 0);
98
- _define_property(this, "storageConfigService", void 0);
99
- _define_property(this, "storageFactoryService", void 0);
100
91
  this.uploadService = uploadService;
101
- this.storageConfigService = storageConfigService;
102
- this.storageFactoryService = storageFactoryService;
103
92
  }
104
93
  };
105
94
  _ts_decorate([
106
95
  (0, _common.Post)('single-file'),
96
+ (0, _decorators.RequirePermission)('file.upload'),
107
97
  (0, _decorators.ApiResponseDto)(_dtos.FileUploadResponsePayloadDto, false),
108
98
  (0, _swagger.ApiOperation)({
109
99
  summary: 'Upload a single file'
@@ -145,6 +135,7 @@ _ts_decorate([
145
135
  ], UploadController.prototype, "uploadSingleFile", null);
146
136
  _ts_decorate([
147
137
  (0, _common.Post)('multiple-file'),
138
+ (0, _decorators.RequirePermission)('file.upload'),
148
139
  (0, _swagger.ApiOperation)({
149
140
  summary: 'Upload multiple files (up to 50)'
150
141
  }),
@@ -189,6 +180,7 @@ _ts_decorate([
189
180
  ], UploadController.prototype, "uploadMultipleFiles", null);
190
181
  _ts_decorate([
191
182
  (0, _common.Post)('delete-single-file'),
183
+ (0, _decorators.RequirePermission)('file.delete'),
192
184
  (0, _swagger.ApiOperation)({
193
185
  summary: 'Delete a single file'
194
186
  }),
@@ -206,6 +198,7 @@ _ts_decorate([
206
198
  ], UploadController.prototype, "deleteSingleFile", null);
207
199
  _ts_decorate([
208
200
  (0, _common.Post)('delete-multiple-file'),
201
+ (0, _decorators.RequirePermission)('file.delete'),
209
202
  (0, _swagger.ApiOperation)({
210
203
  summary: 'Delete multiple files'
211
204
  }),
@@ -227,12 +220,8 @@ UploadController = _ts_decorate([
227
220
  (0, _common.Controller)('storage/upload'),
228
221
  (0, _common.UseGuards)(_guards.JwtAuthGuard),
229
222
  _ts_param(0, (0, _common.Inject)(_uploadservice.UploadService)),
230
- _ts_param(1, (0, _common.Inject)(_config.StorageConfigService)),
231
- _ts_param(2, (0, _common.Inject)(_storagefactoryservice.StorageFactoryService)),
232
223
  _ts_metadata("design:type", Function),
233
224
  _ts_metadata("design:paramtypes", [
234
- typeof _uploadservice.UploadService === "undefined" ? Object : _uploadservice.UploadService,
235
- typeof _config.StorageConfigService === "undefined" ? Object : _config.StorageConfigService,
236
- typeof _storagefactoryservice.StorageFactoryService === "undefined" ? Object : _storagefactoryservice.StorageFactoryService
225
+ typeof _uploadservice.UploadService === "undefined" ? Object : _uploadservice.UploadService
237
226
  ])
238
227
  ], UploadController);