Skip to content

Commit 2233bee

Browse files
committed
feat: storage module / service
1 parent 838715f commit 2233bee

File tree

6 files changed

+36
-24
lines changed

6 files changed

+36
-24
lines changed

lib/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
export * from './storage.module';
22
export * from './storage.service';
3+
export * from './interfaces';

lib/interfaces/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './Storage-module-options';
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import {
2+
StorageManagerConfig,
3+
StorageManagerDiskConfig,
4+
} from '@slynova/flydrive';
5+
6+
export interface StorageModuleOptions extends StorageManagerConfig {
7+
isGlobal?: boolean;
8+
default: string;
9+
disks: StorageManagerDiskConfig;
10+
}

lib/storage.constants.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
/**
22
* Injection tokens
33
*/
4-
export const STORAGE_SERVICE_TOKEN = Symbol('STORAGE_SERVICE');
54
export const STORAGE_TOKEN = 'STORAGE_TOKEN';

lib/storage.module.ts

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,25 @@
1-
import { DynamicModule, Module } from '@nestjs/common';
1+
import { DynamicModule, FactoryProvider, Module } from '@nestjs/common';
22
import { StorageService } from './storage.service';
3-
import { StorageHostModule } from './storage-host.module';
43

5-
import { STORAGE_SERVICE_TOKEN } from './storage.constants';
4+
import { STORAGE_TOKEN } from './storage.constants';
5+
import { StorageModuleOptions } from './interfaces';
66

77
@Module({
8-
imports: [StorageHostModule],
9-
providers: [
10-
{
11-
provide: StorageService,
12-
useExisting: STORAGE_SERVICE_TOKEN,
13-
},
14-
],
15-
exports: [StorageHostModule, StorageService],
8+
providers: [StorageService],
9+
exports: [StorageService],
1610
})
1711
export class StorageModule {
18-
static forRoot(): DynamicModule {
12+
static forRoot(options: StorageModuleOptions): DynamicModule {
1913
return {
2014
module: StorageModule,
15+
global: options.isGlobal,
16+
providers: [
17+
{
18+
provide: STORAGE_TOKEN,
19+
useValue: options,
20+
},
21+
],
22+
exports: [StorageService],
2123
};
2224
}
2325
}

lib/storage.service.ts

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,18 @@
11
import { Inject, Injectable } from '@nestjs/common';
2-
import { StorageManager } from '@slynova/flydrive';
2+
import { Storage, StorageManager } from '@slynova/flydrive';
33

44
import { STORAGE_TOKEN } from './storage.constants';
5+
import { StorageModuleOptions } from './interfaces';
56

67
@Injectable()
78
export class StorageService {
8-
constructor(
9-
@Inject(STORAGE_TOKEN)
10-
private storageManager: StorageManager,
11-
) {
12-
const storage = new StorageManager({
13-
default: 'local',
14-
});
15-
console.log(this.storageManager);
16-
console.log(storage);
17-
// storage.disk().getSignedUrl('./');
9+
private storageManager: StorageManager;
10+
11+
constructor(@Inject(STORAGE_TOKEN) private options: StorageModuleOptions) {
12+
this.storageManager = new StorageManager(options);
13+
}
14+
15+
getDisk<T extends Storage>(name?: string) {
16+
return this.storageManager.disk<T>(name);
1817
}
1918
}

0 commit comments

Comments
 (0)