@flusys/nestjs-storage 0.1.0-beta.3 → 1.0.0-rc
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 +131 -19
- package/cjs/config/storage-config.service.js +5 -0
- package/cjs/config/storage.constants.js +0 -8
- package/cjs/controllers/file-manager.controller.js +50 -5
- package/cjs/controllers/folder.controller.js +46 -4
- package/cjs/controllers/storage-config.controller.js +46 -4
- package/cjs/controllers/upload.controller.js +6 -12
- package/cjs/dtos/file-manager.dto.js +8 -5
- package/cjs/dtos/storage-config.dto.js +41 -1
- package/cjs/dtos/upload.dto.js +7 -0
- package/cjs/entities/storage-config-base.entity.js +31 -2
- package/cjs/interfaces/index.js +0 -1
- package/cjs/middlewares/file-serve.middleware.js +6 -0
- package/cjs/modules/storage.module.js +2 -4
- package/cjs/providers/local-provider.js +52 -2
- package/cjs/providers/storage-factory.service.js +2 -2
- package/cjs/services/file-manager.service.js +37 -24
- package/cjs/services/folder.service.js +18 -52
- package/cjs/services/storage-datasource.provider.js +10 -16
- package/cjs/services/storage-provider-config.service.js +28 -63
- package/cjs/services/upload.service.js +39 -27
- package/cjs/utils/file-validator.util.js +470 -0
- package/cjs/utils/image-compressor.util.js +1 -3
- package/config/storage-config.service.d.ts +5 -2
- package/config/storage.constants.d.ts +0 -2
- package/controllers/file-manager.controller.d.ts +1 -1
- package/controllers/upload.controller.d.ts +2 -6
- package/dtos/file-manager.dto.d.ts +2 -4
- package/dtos/folder.dto.d.ts +2 -4
- package/dtos/storage-config.dto.d.ts +9 -6
- package/entities/storage-config-base.entity.d.ts +2 -0
- package/fesm/config/storage-config.service.js +5 -0
- package/fesm/config/storage.constants.js +0 -2
- package/fesm/controllers/file-manager.controller.js +51 -6
- package/fesm/controllers/folder.controller.js +49 -7
- package/fesm/controllers/storage-config.controller.js +49 -7
- package/fesm/controllers/upload.controller.js +7 -13
- package/fesm/dtos/file-manager.dto.js +8 -5
- package/fesm/dtos/storage-config.dto.js +45 -11
- package/fesm/dtos/upload.dto.js +8 -1
- package/fesm/entities/index.js +1 -5
- package/fesm/entities/storage-config-base.entity.js +33 -7
- package/fesm/interfaces/index.js +0 -1
- package/fesm/interfaces/storage-config.interface.js +1 -3
- package/fesm/middlewares/file-serve.middleware.js +7 -1
- package/fesm/modules/storage.module.js +2 -4
- package/fesm/providers/local-provider.js +52 -2
- package/fesm/providers/storage-factory.service.js +2 -2
- package/fesm/services/file-manager.service.js +38 -25
- package/fesm/services/folder.service.js +19 -53
- package/fesm/services/storage-datasource.provider.js +10 -16
- package/fesm/services/storage-provider-config.service.js +28 -63
- package/fesm/services/upload.service.js +40 -28
- package/fesm/utils/file-validator.util.js +463 -0
- package/fesm/utils/image-compressor.util.js +1 -3
- package/interfaces/file-manager.interface.d.ts +7 -4
- package/interfaces/index.d.ts +0 -1
- package/interfaces/storage-config.interface.d.ts +2 -20
- package/package.json +6 -6
- package/providers/local-provider.d.ts +2 -0
- package/services/file-manager.service.d.ts +2 -2
- package/services/folder.service.d.ts +1 -2
- package/services/storage-provider-config.service.d.ts +1 -2
- package/utils/file-validator.util.d.ts +16 -0
- package/cjs/interfaces/file-upload-response.interface.js +0 -4
- package/fesm/interfaces/file-upload-response.interface.js +0 -1
- package/interfaces/file-upload-response.interface.d.ts +0 -6
package/README.md
CHANGED
|
@@ -89,6 +89,7 @@ nestjs-storage/
|
|
|
89
89
|
│ │ ├── file-manager.service.ts # File metadata CRUD
|
|
90
90
|
│ │ ├── folder.service.ts # Folder CRUD
|
|
91
91
|
│ │ ├── storage-provider-config.service.ts
|
|
92
|
+
│ │ ├── storage-datasource.provider.ts # Dynamic entity loading
|
|
92
93
|
│ │ └── index.ts
|
|
93
94
|
│ │
|
|
94
95
|
│ ├── controllers/
|
|
@@ -99,13 +100,15 @@ nestjs-storage/
|
|
|
99
100
|
│ │ └── index.ts
|
|
100
101
|
│ │
|
|
101
102
|
│ ├── entities/
|
|
102
|
-
│ │ ├── file-manager.entity.ts # File metadata
|
|
103
103
|
│ │ ├── file-manager-base.entity.ts
|
|
104
|
+
│ │ ├── file-manager.entity.ts
|
|
104
105
|
│ │ ├── file-manager-with-company.entity.ts
|
|
105
|
-
│ │ ├── folder.entity.ts # Folder structure
|
|
106
106
|
│ │ ├── folder-base.entity.ts
|
|
107
|
+
│ │ ├── folder.entity.ts
|
|
107
108
|
│ │ ├── folder-with-company.entity.ts
|
|
108
|
-
│ │ ├── storage-config.entity.ts
|
|
109
|
+
│ │ ├── storage-config-base.entity.ts
|
|
110
|
+
│ │ ├── storage-config.entity.ts
|
|
111
|
+
│ │ ├── storage-config-with-company.entity.ts
|
|
109
112
|
│ │ └── index.ts
|
|
110
113
|
│ │
|
|
111
114
|
│ ├── dtos/
|
|
@@ -116,8 +119,11 @@ nestjs-storage/
|
|
|
116
119
|
│ │ └── index.ts
|
|
117
120
|
│ │
|
|
118
121
|
│ ├── interfaces/
|
|
119
|
-
│ │ ├──
|
|
122
|
+
│ │ ├── file-manager.interface.ts
|
|
123
|
+
│ │ ├── folder.interface.ts
|
|
124
|
+
│ │ ├── storage-config.interface.ts
|
|
120
125
|
│ │ ├── storage-module-options.interface.ts
|
|
126
|
+
│ │ ├── storage-provider.interface.ts
|
|
121
127
|
│ │ └── index.ts
|
|
122
128
|
│ │
|
|
123
129
|
│ ├── enums/
|
|
@@ -412,6 +418,12 @@ export class StorageConfig extends Identity {
|
|
|
412
418
|
@Column({ type: 'json' })
|
|
413
419
|
config: Record<string, any>; // Provider-specific config
|
|
414
420
|
|
|
421
|
+
@Column({ default: true })
|
|
422
|
+
isActive: boolean; // Whether config is active and usable
|
|
423
|
+
|
|
424
|
+
@Column({ default: false })
|
|
425
|
+
isDefault: boolean; // Set as default configuration
|
|
426
|
+
|
|
415
427
|
@Column({ nullable: true })
|
|
416
428
|
companyId: string; // Company scope (when enabled)
|
|
417
429
|
}
|
|
@@ -438,6 +450,8 @@ export class SetupService {
|
|
|
438
450
|
accessKeyId: process.env.AWS_ACCESS_KEY,
|
|
439
451
|
secretAccessKey: process.env.AWS_SECRET_KEY,
|
|
440
452
|
},
|
|
453
|
+
isActive: true,
|
|
454
|
+
isDefault: true, // Set as default configuration
|
|
441
455
|
},
|
|
442
456
|
user,
|
|
443
457
|
);
|
|
@@ -453,6 +467,8 @@ export class SetupService {
|
|
|
453
467
|
privateKey: process.env.SFTP_PRIVATE_KEY,
|
|
454
468
|
basePath: '/backups',
|
|
455
469
|
},
|
|
470
|
+
isActive: true,
|
|
471
|
+
isDefault: false, // Not the default
|
|
456
472
|
},
|
|
457
473
|
user,
|
|
458
474
|
);
|
|
@@ -460,27 +476,123 @@ export class SetupService {
|
|
|
460
476
|
}
|
|
461
477
|
```
|
|
462
478
|
|
|
479
|
+
### Storage Provider Resolution Flow
|
|
480
|
+
|
|
481
|
+
When performing upload operations, the `UploadService` resolves the storage provider using a multi-level fallback strategy:
|
|
482
|
+
|
|
483
|
+
**Resolution Flow Diagram:**
|
|
484
|
+
|
|
485
|
+
```
|
|
486
|
+
Upload Request (with optional storageConfigId)
|
|
487
|
+
│
|
|
488
|
+
▼
|
|
489
|
+
┌─────────────────────────────────────────────────────────┐
|
|
490
|
+
│ 1. Check if storageConfigId provided │
|
|
491
|
+
└─────────────────────────────────────────────────────────┘
|
|
492
|
+
│
|
|
493
|
+
provided? ─┴── no ──┐
|
|
494
|
+
│ │
|
|
495
|
+
▼ ▼
|
|
496
|
+
┌──────────────────┐ ┌─────────────────────────────────────┐
|
|
497
|
+
│ 2. Lookup config │ │ 3. Get default config for company │
|
|
498
|
+
│ by ID │ │ - Priority 1: isDefault=true │
|
|
499
|
+
└────────┬─────────┘ │ - Priority 2: oldest active │
|
|
500
|
+
│ └─────────────────────────────────────┘
|
|
501
|
+
│ │
|
|
502
|
+
▼ ▼
|
|
503
|
+
┌─────────────────────────────────────────────────────────┐
|
|
504
|
+
│ 4. Validate company ownership (if company feature) │
|
|
505
|
+
│ - Throws BadRequestException if wrong company │
|
|
506
|
+
└─────────────────────────────────────────────────────────┘
|
|
507
|
+
│
|
|
508
|
+
▼
|
|
509
|
+
┌─────────────────────────────────────────────────────────┐
|
|
510
|
+
│ 5. Create/reuse storage provider instance │
|
|
511
|
+
│ - Check provider cache by config hash │
|
|
512
|
+
│ - Create new if not cached │
|
|
513
|
+
└─────────────────────────────────────────────────────────┘
|
|
514
|
+
│
|
|
515
|
+
▼
|
|
516
|
+
[Perform Upload]
|
|
517
|
+
```
|
|
518
|
+
|
|
519
|
+
**Code Implementation:**
|
|
520
|
+
|
|
521
|
+
```typescript
|
|
522
|
+
// UploadService
|
|
523
|
+
private async getStorageProvider(
|
|
524
|
+
storageConfigId?: string,
|
|
525
|
+
user?: ILoggedUserInfo,
|
|
526
|
+
): Promise<{ provider: IStorageProvider; config: StorageConfigBase }> {
|
|
527
|
+
let config: StorageConfigBase | null = null;
|
|
528
|
+
|
|
529
|
+
// Step 1: Try to get by ID or fallback to default
|
|
530
|
+
if (storageConfigId) {
|
|
531
|
+
config = await this.storageProviderConfigService.findByIdDirect(storageConfigId);
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
if (!config) {
|
|
535
|
+
config = await this.storageProviderConfigService.getDefaultConfig(user);
|
|
536
|
+
}
|
|
537
|
+
|
|
538
|
+
if (!config) {
|
|
539
|
+
throw new BadRequestException('No storage configuration available');
|
|
540
|
+
}
|
|
541
|
+
|
|
542
|
+
// Step 2: Validate company ownership
|
|
543
|
+
if (this.storageConfigService.isCompanyFeatureEnabled() && user?.companyId) {
|
|
544
|
+
const configWithCompany = config as StorageConfigWithCompany;
|
|
545
|
+
if (configWithCompany.companyId && configWithCompany.companyId !== user.companyId) {
|
|
546
|
+
throw new BadRequestException('Storage configuration belongs to another company');
|
|
547
|
+
}
|
|
548
|
+
}
|
|
549
|
+
|
|
550
|
+
// Step 3: Get or create provider instance
|
|
551
|
+
const provider = await this.storageFactory.createProvider({
|
|
552
|
+
provider: config.storage,
|
|
553
|
+
config: config.config,
|
|
554
|
+
});
|
|
555
|
+
|
|
556
|
+
return { provider, config };
|
|
557
|
+
}
|
|
558
|
+
```
|
|
559
|
+
|
|
560
|
+
**Key Points:**
|
|
561
|
+
- Always specify `storageConfigId` for deterministic behavior
|
|
562
|
+
- Without `storageConfigId`, system uses company's default config
|
|
563
|
+
- Company ownership is always validated when company feature is enabled
|
|
564
|
+
- Provider instances are cached for connection reuse
|
|
565
|
+
|
|
463
566
|
### Default Configuration Resolution
|
|
464
567
|
|
|
568
|
+
When `storageConfigId` is not provided for uploads, the system automatically resolves the default config:
|
|
569
|
+
|
|
570
|
+
1. **Priority 1:** Find config with `isDefault: true` and `isActive: true`
|
|
571
|
+
2. **Priority 2:** Fall back to oldest active config
|
|
572
|
+
|
|
465
573
|
```typescript
|
|
466
574
|
// StorageProviderConfigService
|
|
467
575
|
async getDefaultConfig(user?: ILoggedUserInfo): Promise<StorageConfigBase | null> {
|
|
576
|
+
await this.ensureRepositoryInitialized();
|
|
577
|
+
|
|
578
|
+
const baseWhere: any = { isActive: true };
|
|
579
|
+
|
|
468
580
|
// Filter by company if enabled
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
where.companyId = user.companyId;
|
|
581
|
+
if (this.storageConfig.isCompanyFeatureEnabled() && user?.companyId) {
|
|
582
|
+
baseWhere.companyId = user.companyId;
|
|
472
583
|
}
|
|
473
584
|
|
|
474
|
-
// First try
|
|
585
|
+
// First try to find config marked as default
|
|
475
586
|
const defaultConfig = await this.repository.findOne({
|
|
476
|
-
where: { ...
|
|
587
|
+
where: { ...baseWhere, isDefault: true },
|
|
588
|
+
order: { createdAt: 'ASC' },
|
|
477
589
|
});
|
|
478
590
|
|
|
479
591
|
if (defaultConfig) return defaultConfig;
|
|
480
592
|
|
|
481
|
-
// Fall back to
|
|
593
|
+
// Fall back to oldest active config
|
|
482
594
|
return await this.repository.findOne({
|
|
483
|
-
where,
|
|
595
|
+
where: baseWhere,
|
|
484
596
|
order: { createdAt: 'ASC' },
|
|
485
597
|
});
|
|
486
598
|
}
|
|
@@ -860,7 +972,7 @@ curl -X POST http://localhost:3000/upload/single-file \
|
|
|
860
972
|
|
|
861
973
|
---
|
|
862
974
|
|
|
863
|
-
## DataSource Provider Pattern
|
|
975
|
+
## DataSource Provider Pattern
|
|
864
976
|
|
|
865
977
|
### Overview
|
|
866
978
|
|
|
@@ -1211,6 +1323,7 @@ import {
|
|
|
1211
1323
|
FileManagerService,
|
|
1212
1324
|
FolderService,
|
|
1213
1325
|
StorageProviderConfigService,
|
|
1326
|
+
StorageDataSourceProvider,
|
|
1214
1327
|
} from '@flusys/nestjs-storage/services';
|
|
1215
1328
|
|
|
1216
1329
|
// Entities
|
|
@@ -1241,10 +1354,15 @@ import {
|
|
|
1241
1354
|
|
|
1242
1355
|
// Interfaces
|
|
1243
1356
|
import {
|
|
1357
|
+
IFileManager,
|
|
1358
|
+
IFolder,
|
|
1359
|
+
IStorageConfig,
|
|
1360
|
+
IStorageModuleConfig,
|
|
1244
1361
|
IStorageProvider,
|
|
1245
1362
|
IStorageProviderConfig,
|
|
1246
1363
|
IUploadedFileInfo,
|
|
1247
1364
|
StorageModuleOptions,
|
|
1365
|
+
StorageModuleAsyncOptions,
|
|
1248
1366
|
} from '@flusys/nestjs-storage/interfaces';
|
|
1249
1367
|
|
|
1250
1368
|
// Enums
|
|
@@ -1279,10 +1397,4 @@ The `@flusys/nestjs-storage` package provides:
|
|
|
1279
1397
|
|
|
1280
1398
|
---
|
|
1281
1399
|
|
|
1282
|
-
**Last Updated:** 2026-02-
|
|
1283
|
-
|
|
1284
|
-
**Recent Changes:**
|
|
1285
|
-
- 2026-02-09: Added explicit `@Inject()` decorators to all services for esbuild bundling compatibility
|
|
1286
|
-
- 2026-02-09: Fixed `instanceof` checks in FolderService and FileManagerService - replaced with `'id' in dto` pattern
|
|
1287
|
-
- 2026-02-07: Condensed DataSource Provider pattern documentation
|
|
1288
|
-
- 2026-02-07: Simplified provider registration section
|
|
1400
|
+
**Last Updated:** 2026-02-18
|
|
@@ -50,6 +50,11 @@ let StorageConfigService = class StorageConfigService {
|
|
|
50
50
|
return this.options.bootstrapAppConfig?.databaseMode ?? 'single';
|
|
51
51
|
}
|
|
52
52
|
/**
|
|
53
|
+
* Check if running in multi-tenant mode
|
|
54
|
+
*/ isMultiTenant() {
|
|
55
|
+
return this.getDatabaseMode() === 'multi-tenant';
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
53
58
|
* Get maximum file size in bytes
|
|
54
59
|
*/ getMaxFileSize() {
|
|
55
60
|
return this.options.config?.maxFileSize ?? _storageconstants.DEFAULT_MAX_FILE_SIZE;
|
|
@@ -20,19 +20,11 @@ _export(exports, {
|
|
|
20
20
|
get FILE_VALIDATION_MESSAGES () {
|
|
21
21
|
return FILE_VALIDATION_MESSAGES;
|
|
22
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
23
|
get STORAGE_MODULE_OPTIONS () {
|
|
30
24
|
return STORAGE_MODULE_OPTIONS;
|
|
31
25
|
}
|
|
32
26
|
});
|
|
33
27
|
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
28
|
const DEFAULT_MAX_FILE_SIZE = 100 * 1024 * 1024; // 100MB
|
|
37
29
|
const DEFAULT_ALLOWED_FILE_TYPES = [
|
|
38
30
|
'*/*'
|
|
@@ -9,11 +9,11 @@ Object.defineProperty(exports, "FileManagerController", {
|
|
|
9
9
|
}
|
|
10
10
|
});
|
|
11
11
|
const _common = require("@nestjs/common");
|
|
12
|
-
const _guards = require("@flusys/nestjs-shared/guards");
|
|
13
12
|
const _classes = require("@flusys/nestjs-shared/classes");
|
|
14
13
|
const _decorators = require("@flusys/nestjs-shared/decorators");
|
|
15
|
-
const _interfaces = require("@flusys/nestjs-shared/interfaces");
|
|
16
14
|
const _dtos = require("@flusys/nestjs-shared/dtos");
|
|
15
|
+
const _guards = require("@flusys/nestjs-shared/guards");
|
|
16
|
+
const _interfaces = require("@flusys/nestjs-shared/interfaces");
|
|
17
17
|
const _dtos1 = require("../dtos");
|
|
18
18
|
const _swagger = require("@nestjs/swagger");
|
|
19
19
|
const _express = require("express");
|
|
@@ -45,7 +45,52 @@ function _ts_param(paramIndex, decorator) {
|
|
|
45
45
|
decorator(target, key, paramIndex);
|
|
46
46
|
};
|
|
47
47
|
}
|
|
48
|
-
let FileManagerController = class FileManagerController extends (0, _classes.createApiController)(_dtos1.CreateFileManagerDto, _dtos1.UpdateFileManagerDto, _dtos1.FileManagerResponseDto
|
|
48
|
+
let FileManagerController = class FileManagerController extends (0, _classes.createApiController)(_dtos1.CreateFileManagerDto, _dtos1.UpdateFileManagerDto, _dtos1.FileManagerResponseDto, {
|
|
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
|
+
}
|
|
93
|
+
}) {
|
|
49
94
|
async getFiles(dto, req, user) {
|
|
50
95
|
if (!dto || !dto.length) {
|
|
51
96
|
throw new _common.BadRequestException('No files provided');
|
|
@@ -64,6 +109,8 @@ let FileManagerController = class FileManagerController extends (0, _classes.cre
|
|
|
64
109
|
};
|
|
65
110
|
_ts_decorate([
|
|
66
111
|
(0, _common.Post)('get-files'),
|
|
112
|
+
(0, _common.UseGuards)(_guards.JwtAuthGuard),
|
|
113
|
+
(0, _swagger.ApiBearerAuth)(),
|
|
67
114
|
(0, _common.HttpCode)(200),
|
|
68
115
|
(0, _swagger.ApiBody)({
|
|
69
116
|
type: _dtos1.GetFilesRequestDto,
|
|
@@ -90,9 +137,7 @@ _ts_decorate([
|
|
|
90
137
|
], FileManagerController.prototype, "getFiles", null);
|
|
91
138
|
FileManagerController = _ts_decorate([
|
|
92
139
|
(0, _swagger.ApiTags)('Files'),
|
|
93
|
-
(0, _swagger.ApiBearerAuth)(),
|
|
94
140
|
(0, _common.Controller)('storage/file-manager'),
|
|
95
|
-
(0, _common.UseGuards)(_guards.JwtAuthGuard),
|
|
96
141
|
_ts_param(0, (0, _common.Inject)(_filemanagerservice.FileManagerService)),
|
|
97
142
|
_ts_metadata("design:type", Function),
|
|
98
143
|
_ts_metadata("design:paramtypes", [
|
|
@@ -8,7 +8,6 @@ Object.defineProperty(exports, "FolderController", {
|
|
|
8
8
|
return FolderController;
|
|
9
9
|
}
|
|
10
10
|
});
|
|
11
|
-
const _guards = require("@flusys/nestjs-shared/guards");
|
|
12
11
|
const _classes = require("@flusys/nestjs-shared/classes");
|
|
13
12
|
const _dtos = require("../dtos");
|
|
14
13
|
const _common = require("@nestjs/common");
|
|
@@ -41,16 +40,59 @@ function _ts_param(paramIndex, decorator) {
|
|
|
41
40
|
decorator(target, key, paramIndex);
|
|
42
41
|
};
|
|
43
42
|
}
|
|
44
|
-
let FolderController = class FolderController extends (0, _classes.createApiController)(_dtos.CreateFolderDto, _dtos.UpdateFolderDto, _dtos.FolderResponseDto
|
|
43
|
+
let FolderController = class FolderController extends (0, _classes.createApiController)(_dtos.CreateFolderDto, _dtos.UpdateFolderDto, _dtos.FolderResponseDto, {
|
|
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
|
+
}
|
|
88
|
+
}) {
|
|
45
89
|
constructor(folderService){
|
|
46
90
|
super(folderService), _define_property(this, "folderService", void 0), this.folderService = folderService;
|
|
47
91
|
}
|
|
48
92
|
};
|
|
49
93
|
FolderController = _ts_decorate([
|
|
50
94
|
(0, _swagger.ApiTags)('Folders'),
|
|
51
|
-
(0, _swagger.ApiBearerAuth)(),
|
|
52
95
|
(0, _common.Controller)('storage/folder'),
|
|
53
|
-
(0, _common.UseGuards)(_guards.JwtAuthGuard),
|
|
54
96
|
_ts_param(0, (0, _common.Inject)(_folderservice.FolderService)),
|
|
55
97
|
_ts_metadata("design:type", Function),
|
|
56
98
|
_ts_metadata("design:paramtypes", [
|
|
@@ -8,7 +8,6 @@ Object.defineProperty(exports, "StorageConfigController", {
|
|
|
8
8
|
return StorageConfigController;
|
|
9
9
|
}
|
|
10
10
|
});
|
|
11
|
-
const _guards = require("@flusys/nestjs-shared/guards");
|
|
12
11
|
const _classes = require("@flusys/nestjs-shared/classes");
|
|
13
12
|
const _dtos = require("../dtos");
|
|
14
13
|
const _common = require("@nestjs/common");
|
|
@@ -41,16 +40,59 @@ function _ts_param(paramIndex, decorator) {
|
|
|
41
40
|
decorator(target, key, paramIndex);
|
|
42
41
|
};
|
|
43
42
|
}
|
|
44
|
-
let StorageConfigController = class StorageConfigController extends (0, _classes.createApiController)(_dtos.CreateStorageConfigDto, _dtos.UpdateStorageConfigDto, _dtos.StorageConfigResponseDto
|
|
43
|
+
let StorageConfigController = class StorageConfigController extends (0, _classes.createApiController)(_dtos.CreateStorageConfigDto, _dtos.UpdateStorageConfigDto, _dtos.StorageConfigResponseDto, {
|
|
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
|
+
}
|
|
88
|
+
}) {
|
|
45
89
|
constructor(storageConfigService){
|
|
46
90
|
super(storageConfigService), _define_property(this, "storageConfigService", void 0), this.storageConfigService = storageConfigService;
|
|
47
91
|
}
|
|
48
92
|
};
|
|
49
93
|
StorageConfigController = _ts_decorate([
|
|
50
94
|
(0, _swagger.ApiTags)('Storage Config'),
|
|
51
|
-
(0, _swagger.ApiBearerAuth)(),
|
|
52
95
|
(0, _common.Controller)('storage/storage-config'),
|
|
53
|
-
(0, _common.UseGuards)(_guards.JwtAuthGuard),
|
|
54
96
|
_ts_param(0, (0, _common.Inject)(_storageproviderconfigservice.StorageProviderConfigService)),
|
|
55
97
|
_ts_metadata("design:type", Function),
|
|
56
98
|
_ts_metadata("design:paramtypes", [
|
|
@@ -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, {
|
|
@@ -93,17 +91,14 @@ let UploadController = class UploadController {
|
|
|
93
91
|
data
|
|
94
92
|
};
|
|
95
93
|
}
|
|
96
|
-
constructor(uploadService
|
|
94
|
+
constructor(uploadService){
|
|
97
95
|
_define_property(this, "uploadService", void 0);
|
|
98
|
-
_define_property(this, "storageConfigService", void 0);
|
|
99
|
-
_define_property(this, "storageFactoryService", void 0);
|
|
100
96
|
this.uploadService = uploadService;
|
|
101
|
-
this.storageConfigService = storageConfigService;
|
|
102
|
-
this.storageFactoryService = storageFactoryService;
|
|
103
97
|
}
|
|
104
98
|
};
|
|
105
99
|
_ts_decorate([
|
|
106
100
|
(0, _common.Post)('single-file'),
|
|
101
|
+
(0, _decorators.RequirePermission)('file.upload'),
|
|
107
102
|
(0, _decorators.ApiResponseDto)(_dtos.FileUploadResponsePayloadDto, false),
|
|
108
103
|
(0, _swagger.ApiOperation)({
|
|
109
104
|
summary: 'Upload a single file'
|
|
@@ -145,6 +140,7 @@ _ts_decorate([
|
|
|
145
140
|
], UploadController.prototype, "uploadSingleFile", null);
|
|
146
141
|
_ts_decorate([
|
|
147
142
|
(0, _common.Post)('multiple-file'),
|
|
143
|
+
(0, _decorators.RequirePermission)('file.upload'),
|
|
148
144
|
(0, _swagger.ApiOperation)({
|
|
149
145
|
summary: 'Upload multiple files (up to 50)'
|
|
150
146
|
}),
|
|
@@ -189,6 +185,7 @@ _ts_decorate([
|
|
|
189
185
|
], UploadController.prototype, "uploadMultipleFiles", null);
|
|
190
186
|
_ts_decorate([
|
|
191
187
|
(0, _common.Post)('delete-single-file'),
|
|
188
|
+
(0, _decorators.RequirePermission)('file.delete'),
|
|
192
189
|
(0, _swagger.ApiOperation)({
|
|
193
190
|
summary: 'Delete a single file'
|
|
194
191
|
}),
|
|
@@ -206,6 +203,7 @@ _ts_decorate([
|
|
|
206
203
|
], UploadController.prototype, "deleteSingleFile", null);
|
|
207
204
|
_ts_decorate([
|
|
208
205
|
(0, _common.Post)('delete-multiple-file'),
|
|
206
|
+
(0, _decorators.RequirePermission)('file.delete'),
|
|
209
207
|
(0, _swagger.ApiOperation)({
|
|
210
208
|
summary: 'Delete multiple files'
|
|
211
209
|
}),
|
|
@@ -227,12 +225,8 @@ UploadController = _ts_decorate([
|
|
|
227
225
|
(0, _common.Controller)('storage/upload'),
|
|
228
226
|
(0, _common.UseGuards)(_guards.JwtAuthGuard),
|
|
229
227
|
_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
228
|
_ts_metadata("design:type", Function),
|
|
233
229
|
_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
|
|
230
|
+
typeof _uploadservice.UploadService === "undefined" ? Object : _uploadservice.UploadService
|
|
237
231
|
])
|
|
238
232
|
], UploadController);
|
|
@@ -64,8 +64,8 @@ let CreateFileManagerDto = class CreateFileManagerDto {
|
|
|
64
64
|
};
|
|
65
65
|
_ts_decorate([
|
|
66
66
|
(0, _swagger.ApiProperty)({
|
|
67
|
-
description: '
|
|
68
|
-
example: '
|
|
67
|
+
description: 'Original file name',
|
|
68
|
+
example: 'vacation-photo.jpg'
|
|
69
69
|
}),
|
|
70
70
|
(0, _classvalidator.IsNotEmpty)(),
|
|
71
71
|
(0, _classvalidator.IsString)(),
|
|
@@ -73,8 +73,8 @@ _ts_decorate([
|
|
|
73
73
|
], CreateFileManagerDto.prototype, "name", void 0);
|
|
74
74
|
_ts_decorate([
|
|
75
75
|
(0, _swagger.ApiProperty)({
|
|
76
|
-
description: '
|
|
77
|
-
example: '
|
|
76
|
+
description: 'Storage key or path of the file',
|
|
77
|
+
example: 'uploads/abc123-vacation-photo.jpg'
|
|
78
78
|
}),
|
|
79
79
|
(0, _classvalidator.IsNotEmpty)(),
|
|
80
80
|
(0, _classvalidator.IsString)(),
|
|
@@ -142,10 +142,11 @@ let UpdateFileManagerDto = class UpdateFileManagerDto extends (0, _swagger.Parti
|
|
|
142
142
|
};
|
|
143
143
|
_ts_decorate([
|
|
144
144
|
(0, _swagger.ApiProperty)({
|
|
145
|
-
description: 'Unique identifier of the
|
|
145
|
+
description: 'Unique identifier of the file',
|
|
146
146
|
example: 'f2e9c8d0-7a2a-11eb-9439-0242ac130002'
|
|
147
147
|
}),
|
|
148
148
|
(0, _classvalidator.IsNotEmpty)(),
|
|
149
|
+
(0, _classvalidator.IsString)(),
|
|
149
150
|
_ts_metadata("design:type", String)
|
|
150
151
|
], UpdateFileManagerDto.prototype, "id", void 0);
|
|
151
152
|
let FileManagerResponseDto = class FileManagerResponseDto extends UpdateFileManagerDto {
|
|
@@ -169,6 +170,8 @@ _ts_decorate([
|
|
|
169
170
|
(0, _swagger.ApiProperty)({
|
|
170
171
|
example: 'f2e9c8d0-7a2a-11eb-9439-0242ac130002'
|
|
171
172
|
}),
|
|
173
|
+
(0, _classvalidator.IsNotEmpty)(),
|
|
174
|
+
(0, _classvalidator.IsString)(),
|
|
172
175
|
_ts_metadata("design:type", String)
|
|
173
176
|
], GetFilesRequestDto.prototype, "id", void 0);
|
|
174
177
|
let FilesResponseDto = class FilesResponseDto {
|
|
@@ -50,6 +50,8 @@ let CreateStorageConfigDto = class CreateStorageConfigDto {
|
|
|
50
50
|
_define_property(this, "name", void 0);
|
|
51
51
|
_define_property(this, "storage", void 0);
|
|
52
52
|
_define_property(this, "config", void 0);
|
|
53
|
+
_define_property(this, "isActive", void 0);
|
|
54
|
+
_define_property(this, "isDefault", void 0);
|
|
53
55
|
}
|
|
54
56
|
};
|
|
55
57
|
_ts_decorate([
|
|
@@ -97,12 +99,32 @@ _ts_decorate([
|
|
|
97
99
|
(0, _classvalidator.IsNotEmpty)(),
|
|
98
100
|
_ts_metadata("design:type", typeof Record === "undefined" ? Object : Record)
|
|
99
101
|
], CreateStorageConfigDto.prototype, "config", void 0);
|
|
102
|
+
_ts_decorate([
|
|
103
|
+
(0, _swagger.ApiPropertyOptional)({
|
|
104
|
+
example: true,
|
|
105
|
+
description: 'Whether storage configuration is active'
|
|
106
|
+
}),
|
|
107
|
+
(0, _classvalidator.IsBoolean)(),
|
|
108
|
+
(0, _classvalidator.IsOptional)(),
|
|
109
|
+
_ts_metadata("design:type", Boolean)
|
|
110
|
+
], CreateStorageConfigDto.prototype, "isActive", void 0);
|
|
111
|
+
_ts_decorate([
|
|
112
|
+
(0, _swagger.ApiPropertyOptional)({
|
|
113
|
+
example: false,
|
|
114
|
+
description: 'Set as default storage configuration'
|
|
115
|
+
}),
|
|
116
|
+
(0, _classvalidator.IsBoolean)(),
|
|
117
|
+
(0, _classvalidator.IsOptional)(),
|
|
118
|
+
_ts_metadata("design:type", Boolean)
|
|
119
|
+
], CreateStorageConfigDto.prototype, "isDefault", void 0);
|
|
100
120
|
let UpdateStorageConfigDto = class UpdateStorageConfigDto {
|
|
101
121
|
constructor(){
|
|
102
122
|
_define_property(this, "id", void 0);
|
|
103
123
|
_define_property(this, "name", void 0);
|
|
104
124
|
_define_property(this, "storage", void 0);
|
|
105
125
|
_define_property(this, "config", void 0);
|
|
126
|
+
_define_property(this, "isActive", void 0);
|
|
127
|
+
_define_property(this, "isDefault", void 0);
|
|
106
128
|
}
|
|
107
129
|
};
|
|
108
130
|
_ts_decorate([
|
|
@@ -157,8 +179,26 @@ _ts_decorate([
|
|
|
157
179
|
(0, _classvalidator.IsOptional)(),
|
|
158
180
|
_ts_metadata("design:type", typeof Record === "undefined" ? Object : Record)
|
|
159
181
|
], UpdateStorageConfigDto.prototype, "config", void 0);
|
|
182
|
+
_ts_decorate([
|
|
183
|
+
(0, _swagger.ApiPropertyOptional)({
|
|
184
|
+
example: true,
|
|
185
|
+
description: 'Whether storage configuration is active'
|
|
186
|
+
}),
|
|
187
|
+
(0, _classvalidator.IsBoolean)(),
|
|
188
|
+
(0, _classvalidator.IsOptional)(),
|
|
189
|
+
_ts_metadata("design:type", Boolean)
|
|
190
|
+
], UpdateStorageConfigDto.prototype, "isActive", void 0);
|
|
191
|
+
_ts_decorate([
|
|
192
|
+
(0, _swagger.ApiPropertyOptional)({
|
|
193
|
+
example: false,
|
|
194
|
+
description: 'Set as default storage configuration'
|
|
195
|
+
}),
|
|
196
|
+
(0, _classvalidator.IsBoolean)(),
|
|
197
|
+
(0, _classvalidator.IsOptional)(),
|
|
198
|
+
_ts_metadata("design:type", Boolean)
|
|
199
|
+
], UpdateStorageConfigDto.prototype, "isDefault", void 0);
|
|
160
200
|
let StorageConfigResponseDto = class StorageConfigResponseDto extends _dtos.IdentityResponseDto {
|
|
161
201
|
constructor(...args){
|
|
162
|
-
super(...args), _define_property(this, "name", void 0), _define_property(this, "storage", void 0), _define_property(this, "config", void 0);
|
|
202
|
+
super(...args), _define_property(this, "name", void 0), _define_property(this, "storage", void 0), _define_property(this, "config", void 0), _define_property(this, "isActive", void 0), _define_property(this, "isDefault", void 0);
|
|
163
203
|
}
|
|
164
204
|
};
|