File size: 1,978 Bytes
6727a3d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import path from 'path';
import { fileURLToPath } from 'url';
import fs from 'fs';
import dotenv from 'dotenv';

const __dirname = path.dirname(fileURLToPath(import.meta.url));
const envCandidates = [
    path.resolve(__dirname, '..', '.env'),
    path.resolve(__dirname, '..', '..', '.env'),
    path.resolve(process.cwd(), '.env'),
];
for (const candidate of envCandidates) {
    if (fs.existsSync(candidate)) {
        dotenv.config({ path: candidate, override: false });
        break;
    }
}

class ConfigManager {
    static instance: ConfigManager | null = null;

    public PORT: number;
    public LOG_LEVEL: string;
    public TEMP_FOLDER: string;
    public AUTH_FOLDER: string;
    public API_URL: string;
    public API_TIMEOUT: number;
    public API_AUTH_TOKEN: string;
    public COMPANY_NAME: string;
    public FALLBACK_MESSAGE: string;
    public BOT_NUMERO_REAL: string;

    constructor() {
        this.PORT = Number(process.env.PORT || 3000);
        this.LOG_LEVEL = process.env.LOG_LEVEL || 'info';
        this.TEMP_FOLDER = process.env.TEMP_FOLDER || './temp';
        this.AUTH_FOLDER = process.env.AUTH_FOLDER || './auth_info_baileys';

        this.API_URL = (process.env.API_URL || 'https://akra35567-akiragpu.hf.space/api').replace(/\/$/, '');
        this.API_TIMEOUT = Number(process.env.API_TIMEOUT || 120000);
        this.API_AUTH_TOKEN = process.env.API_AUTH_TOKEN || '';

        this.COMPANY_NAME = process.env.COMPANY_NAME || 'Akira';
        this.BOT_NUMERO_REAL = (process.env.BOT_NUMERO_REAL || '').replace(/\D/g, '');

        this.FALLBACK_MESSAGE =
            process.env.FALLBACK_MESSAGE ||
            'Sei la, o servidor caiu. Tenta de novo já já.';

        ConfigManager.instance = this;
    }

    static getInstance(): ConfigManager {
        if (!ConfigManager.instance) {
            ConfigManager.instance = new ConfigManager();
        }
        return ConfigManager.instance;
    }
}

export default ConfigManager;