File size: 1,110 Bytes
4327358
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import { Injectable, Logger } from '@nestjs/common';
import { ConfigService } from '@nestjs/config';
import { InjectPinoLogger, PinoLogger } from 'nestjs-pino';

import { parseBool } from '../../helpers';

@Injectable()
export class DashboardConfigServiceCore {
  public dashboardUri = '/dashboard';

  constructor(
    protected configService: ConfigService,
    @InjectPinoLogger('DashboardConfigService')
    protected logger: PinoLogger,
  ) {}

  get enabled(): boolean {
    const value = this.configService.get('WAHA_DASHBOARD_ENABLED', 'true');
    return parseBool(value);
  }

  get credentials(): [string, string] | null {
    const user = this.configService.get('WAHA_DASHBOARD_USERNAME', '');
    const password = this.configService.get('WAHA_DASHBOARD_PASSWORD', '');
    if (!user && !password) {
      return null;
    }
    if ((user && !password) || (!user && password)) {
      this.logger.warn(
        'Set up both WAHA_DASHBOARD_USERNAME and WAHA_DASHBOARD_PASSWORD ' +
          'to enable dashboard authentication.',
      );
      return null;
    }
    return [user, password];
  }
}