Skip to content

Commit f8c8907

Browse files
committed
feat: add service method
add StorageService registerDriver method
1 parent 7be4473 commit f8c8907

File tree

7 files changed

+44
-5
lines changed

7 files changed

+44
-5
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@ npm-debug.log
1111
.DS_Store
1212

1313
# tests
14+
tests/data/*
1415
!tests/data/.gitkeep
1516

17+
1618
/coverage
1719
/.nyc_output
1820

lib/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
export * from './storage.module';
22
export * from './storage.service';
33
export * from './interfaces';
4+
export * from './types';
Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1-
import {
2-
StorageManagerConfig,
3-
StorageManagerDiskConfig,
4-
} from '@slynova/flydrive';
1+
import { StorageManagerConfig } from '@slynova/flydrive';
2+
import { DiskConfigType, DriverType } from '../types';
53

64
export interface StorageModuleOptions extends StorageManagerConfig {
75
isGlobal?: boolean;
86
default: string;
9-
disks: StorageManagerDiskConfig;
7+
disks: Record<string, StorageDiskConfig>;
8+
}
9+
10+
export interface StorageDiskConfig {
11+
driver: DriverType | string;
12+
config: DiskConfigType;
1013
}

lib/storage.service.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,8 @@ export class StorageService {
1515
getDisk<T extends Storage>(name?: string): T {
1616
return this.storageManager.disk<T>(name);
1717
}
18+
19+
registerDriver(name: string, driver: new (...args: any[]) => Storage): void {
20+
this.storageManager.registerDriver(name, driver);
21+
}
1822
}

lib/types/disk-config.type.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
export type DiskConfigType =
2+
| DiskLocalConfigType
3+
| DiskS3ConfigType
4+
| DiskGCSConfigType
5+
| Record<string, any>;
6+
7+
export type DiskLocalConfigType = {
8+
root: string;
9+
};
10+
11+
export type DiskS3ConfigType = {
12+
key: string;
13+
endpoint: string;
14+
secret: string;
15+
bucket: string;
16+
region: string;
17+
};
18+
19+
export type DiskGCSConfigType = {
20+
keyFilename: string;
21+
bucket: string;
22+
};

lib/types/driver.type.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export enum DriverType {
2+
LOCAL = 'local',
3+
S3 = 's3',
4+
GCS = 'gcs',
5+
}

lib/types/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export * from './driver.type';
2+
export * from './disk-config.type';

0 commit comments

Comments
 (0)