@flusys/nestjs-storage 1.0.0-beta → 1.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/README.md +174 -13
- 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 +71 -35
- package/cjs/dtos/folder.dto.js +15 -9
- package/cjs/dtos/storage-config.dto.js +25 -66
- 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 +73 -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 +21 -38
- 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 +13 -7
- package/dtos/folder.dto.d.ts +5 -5
- package/dtos/storage-config.dto.d.ts +13 -14
- package/entities/file-manager-with-company.entity.d.ts +2 -2
- package/entities/file-manager.entity.d.ts +11 -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 +7 -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 +72 -36
- package/fesm/dtos/folder.dto.js +16 -10
- package/fesm/dtos/storage-config.dto.js +29 -76
- 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 +74 -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 +19 -36
- 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 +3 -22
- 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 +5 -6
- package/services/upload.service.d.ts +5 -5
- 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 -64
- 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 -7
- 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 -57
- package/fesm/interfaces/file-upload-response.interface.js +0 -1
- package/interfaces/file-upload-response.interface.d.ts +0 -6
package/README.md
CHANGED
|
@@ -9,8 +9,10 @@ This comprehensive guide covers the storage package - flexible file storage with
|
|
|
9
9
|
|
|
10
10
|
- [Overview](#overview)
|
|
11
11
|
- [Installation](#installation)
|
|
12
|
+
- [Constants](#constants)
|
|
12
13
|
- [Package Architecture](#package-architecture)
|
|
13
14
|
- [Module Setup](#module-setup)
|
|
15
|
+
- [Entities](#entities)
|
|
14
16
|
- [Storage Providers](#storage-providers)
|
|
15
17
|
- [Storage Configuration](#storage-configuration)
|
|
16
18
|
- [File Manager](#file-manager)
|
|
@@ -62,6 +64,19 @@ npm install ssh2-sftp-client # For SFTP
|
|
|
62
64
|
|
|
63
65
|
---
|
|
64
66
|
|
|
67
|
+
## Constants
|
|
68
|
+
|
|
69
|
+
```typescript
|
|
70
|
+
// Injection Token
|
|
71
|
+
export const STORAGE_MODULE_OPTIONS = 'STORAGE_MODULE_OPTIONS';
|
|
72
|
+
|
|
73
|
+
// Default Configuration
|
|
74
|
+
export const DEFAULT_MAX_FILE_SIZE = 100 * 1024 * 1024; // 100MB
|
|
75
|
+
export const DEFAULT_ALLOWED_FILE_TYPES = ['*/*']; // All file types
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
---
|
|
79
|
+
|
|
65
80
|
## Package Architecture
|
|
66
81
|
|
|
67
82
|
```
|
|
@@ -89,6 +104,7 @@ nestjs-storage/
|
|
|
89
104
|
│ │ ├── file-manager.service.ts # File metadata CRUD
|
|
90
105
|
│ │ ├── folder.service.ts # Folder CRUD
|
|
91
106
|
│ │ ├── storage-provider-config.service.ts
|
|
107
|
+
│ │ ├── storage-datasource.provider.ts # Dynamic entity loading
|
|
92
108
|
│ │ └── index.ts
|
|
93
109
|
│ │
|
|
94
110
|
│ ├── controllers/
|
|
@@ -99,13 +115,15 @@ nestjs-storage/
|
|
|
99
115
|
│ │ └── index.ts
|
|
100
116
|
│ │
|
|
101
117
|
│ ├── entities/
|
|
102
|
-
│ │ ├── file-manager.entity.ts # File metadata
|
|
103
118
|
│ │ ├── file-manager-base.entity.ts
|
|
119
|
+
│ │ ├── file-manager.entity.ts
|
|
104
120
|
│ │ ├── file-manager-with-company.entity.ts
|
|
105
|
-
│ │ ├── folder.entity.ts # Folder structure
|
|
106
121
|
│ │ ├── folder-base.entity.ts
|
|
122
|
+
│ │ ├── folder.entity.ts
|
|
107
123
|
│ │ ├── folder-with-company.entity.ts
|
|
108
|
-
│ │ ├── storage-config.entity.ts
|
|
124
|
+
│ │ ├── storage-config-base.entity.ts
|
|
125
|
+
│ │ ├── storage-config.entity.ts
|
|
126
|
+
│ │ ├── storage-config-with-company.entity.ts
|
|
109
127
|
│ │ └── index.ts
|
|
110
128
|
│ │
|
|
111
129
|
│ ├── dtos/
|
|
@@ -116,8 +134,11 @@ nestjs-storage/
|
|
|
116
134
|
│ │ └── index.ts
|
|
117
135
|
│ │
|
|
118
136
|
│ ├── interfaces/
|
|
119
|
-
│ │ ├──
|
|
137
|
+
│ │ ├── file-manager.interface.ts
|
|
138
|
+
│ │ ├── folder.interface.ts
|
|
139
|
+
│ │ ├── storage-config.interface.ts
|
|
120
140
|
│ │ ├── storage-module-options.interface.ts
|
|
141
|
+
│ │ ├── storage-provider.interface.ts
|
|
121
142
|
│ │ └── index.ts
|
|
122
143
|
│ │
|
|
123
144
|
│ ├── enums/
|
|
@@ -253,6 +274,34 @@ This ensures the API documentation accurately reflects the available fields base
|
|
|
253
274
|
|
|
254
275
|
---
|
|
255
276
|
|
|
277
|
+
## Entities
|
|
278
|
+
|
|
279
|
+
### Entity Groups
|
|
280
|
+
|
|
281
|
+
```typescript
|
|
282
|
+
// Core entities (no company feature)
|
|
283
|
+
export const StorageCoreEntities = [FileManager, Folder, StorageConfig];
|
|
284
|
+
|
|
285
|
+
// Company-specific entities
|
|
286
|
+
export const StorageCompanyEntities = [
|
|
287
|
+
FileManagerWithCompany,
|
|
288
|
+
FolderWithCompany,
|
|
289
|
+
StorageConfigWithCompany,
|
|
290
|
+
];
|
|
291
|
+
|
|
292
|
+
// Helper function
|
|
293
|
+
export function getStorageEntitiesByConfig(enableCompanyFeature: boolean): any[] {
|
|
294
|
+
return enableCompanyFeature ? StorageCompanyEntities : StorageCoreEntities;
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
// Base type aliases for backwards compatibility
|
|
298
|
+
export { FileManager as FileManagerBase } from './file-manager.entity';
|
|
299
|
+
export { Folder as FolderBase } from './folder.entity';
|
|
300
|
+
export { StorageConfig as StorageConfigBase } from './storage-config.entity';
|
|
301
|
+
```
|
|
302
|
+
|
|
303
|
+
---
|
|
304
|
+
|
|
256
305
|
## Storage Providers
|
|
257
306
|
|
|
258
307
|
### Provider Types
|
|
@@ -412,6 +461,12 @@ export class StorageConfig extends Identity {
|
|
|
412
461
|
@Column({ type: 'json' })
|
|
413
462
|
config: Record<string, any>; // Provider-specific config
|
|
414
463
|
|
|
464
|
+
@Column({ default: true })
|
|
465
|
+
isActive: boolean; // Whether config is active and usable
|
|
466
|
+
|
|
467
|
+
@Column({ default: false })
|
|
468
|
+
isDefault: boolean; // Set as default configuration
|
|
469
|
+
|
|
415
470
|
@Column({ nullable: true })
|
|
416
471
|
companyId: string; // Company scope (when enabled)
|
|
417
472
|
}
|
|
@@ -438,6 +493,8 @@ export class SetupService {
|
|
|
438
493
|
accessKeyId: process.env.AWS_ACCESS_KEY,
|
|
439
494
|
secretAccessKey: process.env.AWS_SECRET_KEY,
|
|
440
495
|
},
|
|
496
|
+
isActive: true,
|
|
497
|
+
isDefault: true, // Set as default configuration
|
|
441
498
|
},
|
|
442
499
|
user,
|
|
443
500
|
);
|
|
@@ -453,6 +510,8 @@ export class SetupService {
|
|
|
453
510
|
privateKey: process.env.SFTP_PRIVATE_KEY,
|
|
454
511
|
basePath: '/backups',
|
|
455
512
|
},
|
|
513
|
+
isActive: true,
|
|
514
|
+
isDefault: false, // Not the default
|
|
456
515
|
},
|
|
457
516
|
user,
|
|
458
517
|
);
|
|
@@ -460,27 +519,123 @@ export class SetupService {
|
|
|
460
519
|
}
|
|
461
520
|
```
|
|
462
521
|
|
|
522
|
+
### Storage Provider Resolution Flow
|
|
523
|
+
|
|
524
|
+
When performing upload operations, the `UploadService` resolves the storage provider using a multi-level fallback strategy:
|
|
525
|
+
|
|
526
|
+
**Resolution Flow Diagram:**
|
|
527
|
+
|
|
528
|
+
```
|
|
529
|
+
Upload Request (with optional storageConfigId)
|
|
530
|
+
│
|
|
531
|
+
▼
|
|
532
|
+
┌─────────────────────────────────────────────────────────┐
|
|
533
|
+
│ 1. Check if storageConfigId provided │
|
|
534
|
+
└─────────────────────────────────────────────────────────┘
|
|
535
|
+
│
|
|
536
|
+
provided? ─┴── no ──┐
|
|
537
|
+
│ │
|
|
538
|
+
▼ ▼
|
|
539
|
+
┌──────────────────┐ ┌─────────────────────────────────────┐
|
|
540
|
+
│ 2. Lookup config │ │ 3. Get default config for company │
|
|
541
|
+
│ by ID │ │ - Priority 1: isDefault=true │
|
|
542
|
+
└────────┬─────────┘ │ - Priority 2: oldest active │
|
|
543
|
+
│ └─────────────────────────────────────┘
|
|
544
|
+
│ │
|
|
545
|
+
▼ ▼
|
|
546
|
+
┌─────────────────────────────────────────────────────────┐
|
|
547
|
+
│ 4. Validate company ownership (if company feature) │
|
|
548
|
+
│ - Throws BadRequestException if wrong company │
|
|
549
|
+
└─────────────────────────────────────────────────────────┘
|
|
550
|
+
│
|
|
551
|
+
▼
|
|
552
|
+
┌─────────────────────────────────────────────────────────┐
|
|
553
|
+
│ 5. Create/reuse storage provider instance │
|
|
554
|
+
│ - Check provider cache by config hash │
|
|
555
|
+
│ - Create new if not cached │
|
|
556
|
+
└─────────────────────────────────────────────────────────┘
|
|
557
|
+
│
|
|
558
|
+
▼
|
|
559
|
+
[Perform Upload]
|
|
560
|
+
```
|
|
561
|
+
|
|
562
|
+
**Code Implementation:**
|
|
563
|
+
|
|
564
|
+
```typescript
|
|
565
|
+
// UploadService
|
|
566
|
+
private async getStorageProvider(
|
|
567
|
+
storageConfigId?: string,
|
|
568
|
+
user?: ILoggedUserInfo,
|
|
569
|
+
): Promise<{ provider: IStorageProvider; config: StorageConfigBase }> {
|
|
570
|
+
let config: StorageConfigBase | null = null;
|
|
571
|
+
|
|
572
|
+
// Step 1: Try to get by ID or fallback to default
|
|
573
|
+
if (storageConfigId) {
|
|
574
|
+
config = await this.storageProviderConfigService.findByIdDirect(storageConfigId);
|
|
575
|
+
}
|
|
576
|
+
|
|
577
|
+
if (!config) {
|
|
578
|
+
config = await this.storageProviderConfigService.getDefaultConfig(user);
|
|
579
|
+
}
|
|
580
|
+
|
|
581
|
+
if (!config) {
|
|
582
|
+
throw new BadRequestException('No storage configuration available');
|
|
583
|
+
}
|
|
584
|
+
|
|
585
|
+
// Step 2: Validate company ownership
|
|
586
|
+
if (this.storageConfigService.isCompanyFeatureEnabled() && user?.companyId) {
|
|
587
|
+
const configWithCompany = config as StorageConfigWithCompany;
|
|
588
|
+
if (configWithCompany.companyId && configWithCompany.companyId !== user.companyId) {
|
|
589
|
+
throw new BadRequestException('Storage configuration belongs to another company');
|
|
590
|
+
}
|
|
591
|
+
}
|
|
592
|
+
|
|
593
|
+
// Step 3: Get or create provider instance
|
|
594
|
+
const provider = await this.storageFactory.createProvider({
|
|
595
|
+
provider: config.storage,
|
|
596
|
+
config: config.config,
|
|
597
|
+
});
|
|
598
|
+
|
|
599
|
+
return { provider, config };
|
|
600
|
+
}
|
|
601
|
+
```
|
|
602
|
+
|
|
603
|
+
**Key Points:**
|
|
604
|
+
- Always specify `storageConfigId` for deterministic behavior
|
|
605
|
+
- Without `storageConfigId`, system uses company's default config
|
|
606
|
+
- Company ownership is always validated when company feature is enabled
|
|
607
|
+
- Provider instances are cached for connection reuse
|
|
608
|
+
|
|
463
609
|
### Default Configuration Resolution
|
|
464
610
|
|
|
611
|
+
When `storageConfigId` is not provided for uploads, the system automatically resolves the default config:
|
|
612
|
+
|
|
613
|
+
1. **Priority 1:** Find config with `isDefault: true` and `isActive: true`
|
|
614
|
+
2. **Priority 2:** Fall back to oldest active config
|
|
615
|
+
|
|
465
616
|
```typescript
|
|
466
617
|
// StorageProviderConfigService
|
|
467
618
|
async getDefaultConfig(user?: ILoggedUserInfo): Promise<StorageConfigBase | null> {
|
|
619
|
+
await this.ensureRepositoryInitialized();
|
|
620
|
+
|
|
621
|
+
const baseWhere: any = { isActive: true };
|
|
622
|
+
|
|
468
623
|
// Filter by company if enabled
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
where.companyId = user.companyId;
|
|
624
|
+
if (this.storageConfig.isCompanyFeatureEnabled() && user?.companyId) {
|
|
625
|
+
baseWhere.companyId = user.companyId;
|
|
472
626
|
}
|
|
473
627
|
|
|
474
|
-
// First try
|
|
628
|
+
// First try to find config marked as default
|
|
475
629
|
const defaultConfig = await this.repository.findOne({
|
|
476
|
-
where: { ...
|
|
630
|
+
where: { ...baseWhere, isDefault: true },
|
|
631
|
+
order: { createdAt: 'ASC' },
|
|
477
632
|
});
|
|
478
633
|
|
|
479
634
|
if (defaultConfig) return defaultConfig;
|
|
480
635
|
|
|
481
|
-
// Fall back to
|
|
636
|
+
// Fall back to oldest active config
|
|
482
637
|
return await this.repository.findOne({
|
|
483
|
-
where,
|
|
638
|
+
where: baseWhere,
|
|
484
639
|
order: { createdAt: 'ASC' },
|
|
485
640
|
});
|
|
486
641
|
}
|
|
@@ -860,7 +1015,7 @@ curl -X POST http://localhost:3000/upload/single-file \
|
|
|
860
1015
|
|
|
861
1016
|
---
|
|
862
1017
|
|
|
863
|
-
## DataSource Provider Pattern
|
|
1018
|
+
## DataSource Provider Pattern
|
|
864
1019
|
|
|
865
1020
|
### Overview
|
|
866
1021
|
|
|
@@ -1211,6 +1366,7 @@ import {
|
|
|
1211
1366
|
FileManagerService,
|
|
1212
1367
|
FolderService,
|
|
1213
1368
|
StorageProviderConfigService,
|
|
1369
|
+
StorageDataSourceProvider,
|
|
1214
1370
|
} from '@flusys/nestjs-storage/services';
|
|
1215
1371
|
|
|
1216
1372
|
// Entities
|
|
@@ -1241,10 +1397,15 @@ import {
|
|
|
1241
1397
|
|
|
1242
1398
|
// Interfaces
|
|
1243
1399
|
import {
|
|
1400
|
+
IFileManager,
|
|
1401
|
+
IFolder,
|
|
1402
|
+
IStorageConfig,
|
|
1403
|
+
IStorageModuleConfig,
|
|
1244
1404
|
IStorageProvider,
|
|
1245
1405
|
IStorageProviderConfig,
|
|
1246
1406
|
IUploadedFileInfo,
|
|
1247
1407
|
StorageModuleOptions,
|
|
1408
|
+
StorageModuleAsyncOptions,
|
|
1248
1409
|
} from '@flusys/nestjs-storage/interfaces';
|
|
1249
1410
|
|
|
1250
1411
|
// Enums
|
|
@@ -1279,4 +1440,4 @@ The `@flusys/nestjs-storage` package provides:
|
|
|
1279
1440
|
|
|
1280
1441
|
---
|
|
1281
1442
|
|
|
1282
|
-
**Last Updated:** 2026-02-
|
|
1443
|
+
**Last Updated:** 2026-02-21
|
package/cjs/config/index.js
CHANGED
|
@@ -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:
|
|
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:
|
|
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:
|
|
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:
|
|
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
|
|
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);
|