diff --git a/src/config.service.ts b/src/config.service.ts index 22cef64f..36af6abb 100644 --- a/src/config.service.ts +++ b/src/config.service.ts @@ -7,15 +7,8 @@ import { WebhookConfig } from './structures/webhooks.config.dto'; @Injectable() export class WhatsappConfigService { - public filesUri = '/api/files'; - public schema = 'http'; - constructor(private configService: ConfigService) {} - get filesURL(): string { - return `${this.schema}://${this.hostname}:${this.port}${this.filesUri}/`; - } - get hostname(): string { return this.configService.get('WHATSAPP_API_HOSTNAME', 'localhost'); } @@ -24,17 +17,6 @@ export class WhatsappConfigService { return this.configService.get('WHATSAPP_API_PORT', '3000'); } - get filesFolder(): string { - return this.configService.get( - 'WHATSAPP_FILES_FOLDER', - '/tmp/whatsapp-files', - ); - } - - get filesLifetime(): number { - return this.configService.get('WHATSAPP_FILES_LIFETIME', 180); - } - get mimetypes(): string[] { if (!this.shouldDownloadMedia) { return ['mimetype/ignore-all-media']; diff --git a/src/core/app.module.core.ts b/src/core/app.module.core.ts index c274e119..5089d7d0 100644 --- a/src/core/app.module.core.ts +++ b/src/core/app.module.core.ts @@ -7,6 +7,7 @@ import { TerminusModule } from '@nestjs/terminus'; import { ChannelsController } from '@waha/api/channels.controller'; import { ServerController } from '@waha/api/server.controller'; import { WebsocketGatewayCore } from '@waha/core/api/websocket.gateway.core'; +import { MediaLocalStorageConfig } from '@waha/core/media/local/MediaLocalStorageConfig'; import { BufferJsonReplacerInterceptor } from '@waha/nestjs/BufferJsonReplacerInterceptor'; import { getPinoHttpUseLevel, @@ -71,26 +72,18 @@ export const IMPORTS = [ }), ServeStaticModule.forRootAsync({ imports: [], - extraProviders: [WhatsappConfigService, DashboardConfigServiceCore], - inject: [WhatsappConfigService, DashboardConfigServiceCore], - useFactory: ( - config: WhatsappConfigService, - dashboardConfig: DashboardConfigServiceCore, - ) => { - const options = [ - // Serve files (media) + extraProviders: [DashboardConfigServiceCore], + inject: [DashboardConfigServiceCore], + useFactory: (dashboardConfig: DashboardConfigServiceCore) => { + if (!dashboardConfig.enabled) { + return []; + } + return [ { - rootPath: config.filesFolder, - serveRoot: config.filesUri, - }, - ]; - if (dashboardConfig.enabled) { - options.push({ rootPath: join(__dirname, '..', 'dashboard'), serveRoot: dashboardConfig.dashboardUri, - }); - } - return options; + }, + ]; }, }), PassportModule, @@ -131,6 +124,7 @@ const PROVIDERS = [ WhatsappConfigService, EngineConfigService, WebsocketGatewayCore, + MediaLocalStorageConfig, ]; @Module({ diff --git a/src/core/media/local/MediaLocalStorageConfig.ts b/src/core/media/local/MediaLocalStorageConfig.ts new file mode 100644 index 00000000..d54e9fb9 --- /dev/null +++ b/src/core/media/local/MediaLocalStorageConfig.ts @@ -0,0 +1,22 @@ +import { Injectable } from '@nestjs/common'; +import { WhatsappConfigService } from '@waha/config.service'; + +@Injectable() +export class MediaLocalStorageConfig { + public filesUri = '/api/files'; + public schema = 'http'; + + constructor(private config: WhatsappConfigService) {} + + get filesURL(): string { + return `${this.schema}://${this.config.hostname}:${this.config.port}${this.filesUri}/`; + } + + get filesFolder(): string { + return this.config.get('WHATSAPP_FILES_FOLDER', '/tmp/whatsapp-files'); + } + + get filesLifetime(): number { + return parseInt(this.config.get('WHATSAPP_FILES_LIFETIME', '180')); + } +}