| 1 | import type { DynamicModule, Provider } from '@nestjs/common' |
| 2 | import { Module } from '@nestjs/common' |
| 3 | import { AssetsModule } from '../assets.module' |
| 4 | import { AssetsHttpController } from './assets-http.controller' |
| 5 | import { ASSETS_HTTP_OPTIONS, AssetsHttpModuleOptions } from './assets-http.options' |
| 6 | import { AssetsHttpScheduler } from './assets-http.scheduler' |
| 7 | |
| 8 | @Module({}) |
| 9 | export class AssetsHttpModule { |
| 10 | static forRoot(options: AssetsHttpModuleOptions): DynamicModule { |
| 11 | const providers: Provider[] = [ |
| 12 | { |
| 13 | provide: ASSETS_HTTP_OPTIONS, |
| 14 | useValue: options, |
| 15 | }, |
| 16 | ] |
| 17 | |
| 18 | if (options.enableScheduler !== false) { |
| 19 | providers.push(AssetsHttpScheduler) |
| 20 | } |
| 21 | |
| 22 | return { |
| 23 | module: AssetsHttpModule, |
| 24 | imports: [AssetsModule.forRoot(options.assetsConfig)], |
| 25 | controllers: [AssetsHttpController], |
| 26 | providers, |
| 27 | } |
| 28 | } |
| 29 | } |
| 30 |