diff --git a/package.json b/package.json index 6f92aaf3b..e976de407 100644 --- a/package.json +++ b/package.json @@ -76,6 +76,7 @@ "redis": "^4.6.5", "sharp": "^0.30.7", "socket.io": "^4.7.1", + "socks-proxy-agent": "^8.0.1", "uuid": "^9.0.0" }, "devDependencies": { diff --git a/src/libs/redis.client.ts b/src/libs/redis.client.ts index dffeb949e..f03513ba6 100644 --- a/src/libs/redis.client.ts +++ b/src/libs/redis.client.ts @@ -5,6 +5,10 @@ import { Redis } from '../config/env.config'; import { Logger } from '../config/logger.config'; export class RedisCache { + async disconnect() { + await this.client.disconnect(); + this.statusConnection = false; + } constructor() { this.logger.verbose('instance created'); process.on('beforeExit', async () => { diff --git a/src/whatsapp/controllers/instance.controller.ts b/src/whatsapp/controllers/instance.controller.ts index 2a9047610..ab98a4811 100644 --- a/src/whatsapp/controllers/instance.controller.ts +++ b/src/whatsapp/controllers/instance.controller.ts @@ -482,12 +482,13 @@ export class InstanceController { } public async fetchInstances({ instanceName }: InstanceDto) { - this.logger.verbose('requested fetchInstances from ' + instanceName + ' instance'); if (instanceName) { + this.logger.verbose('requested fetchInstances from ' + instanceName + ' instance'); this.logger.verbose('instanceName: ' + instanceName); return this.waMonitor.instanceInfo(instanceName); } + this.logger.verbose('requested fetchInstances (all instances)'); return this.waMonitor.instanceInfo(); } diff --git a/src/whatsapp/guards/auth.guard.ts b/src/whatsapp/guards/auth.guard.ts index 72148885e..a72ebfffd 100644 --- a/src/whatsapp/guards/auth.guard.ts +++ b/src/whatsapp/guards/auth.guard.ts @@ -55,7 +55,7 @@ async function jwtGuard(req: Request, res: Response, next: NextFunction) { } } -async function apikey(req: Request, res: Response, next: NextFunction) { +async function apikey(req: Request, _: Response, next: NextFunction) { const env = configService.get('AUTHENTICATION').API_KEY; const key = req.get('apikey'); diff --git a/src/whatsapp/services/monitor.service.ts b/src/whatsapp/services/monitor.service.ts index 039a5f29f..8da82fd5a 100644 --- a/src/whatsapp/services/monitor.service.ts +++ b/src/whatsapp/services/monitor.service.ts @@ -115,7 +115,7 @@ export class WAMonitoringService { if (this.configService.get('AUTHENTICATION').EXPOSE_IN_FETCH_INSTANCES) { instanceData.instance['serverUrl'] = this.configService.get('SERVER').URL; - instanceData.instance['apikey'] = (await this.repository.auth.find(key)).apikey; + instanceData.instance['apikey'] = (await this.repository.auth.find(key))?.apikey; instanceData.instance['chatwoot'] = chatwoot; } @@ -134,7 +134,7 @@ export class WAMonitoringService { if (this.configService.get('AUTHENTICATION').EXPOSE_IN_FETCH_INSTANCES) { instanceData.instance['serverUrl'] = this.configService.get('SERVER').URL; - instanceData.instance['apikey'] = (await this.repository.auth.find(key)).apikey; + instanceData.instance['apikey'] = (await this.repository.auth.find(key))?.apikey; instanceData.instance['chatwoot'] = chatwoot; } @@ -161,8 +161,7 @@ export class WAMonitoringService { }); this.logger.verbose('instance files deleted: ' + name); }); - // } else if (this.redis.ENABLED) { - } else { + } else if (!this.redis.ENABLED) { const dir = opendirSync(INSTANCE_DIR, { encoding: 'utf-8' }); for await (const dirent of dir) { if (dirent.isDirectory()) { @@ -200,6 +199,7 @@ export class WAMonitoringService { this.logger.verbose('cleaning up instance in redis: ' + instanceName); this.cache.reference = instanceName; await this.cache.delAll(); + this.cache.disconnect(); return; } @@ -263,6 +263,7 @@ export class WAMonitoringService { } else { this.logger.verbose('no instance keys found'); } + this.cache.disconnect(); return; } diff --git a/src/whatsapp/services/whatsapp.service.ts b/src/whatsapp/services/whatsapp.service.ts index d11946ee0..ebc5e3779 100644 --- a/src/whatsapp/services/whatsapp.service.ts +++ b/src/whatsapp/services/whatsapp.service.ts @@ -127,6 +127,7 @@ import { RepositoryBroker } from '../repository/repository.manager'; import { Events, MessageSubtype, TypeMediaMessage, wa } from '../types/wa.types'; import { waMonitor } from '../whatsapp.module'; import { ChatwootService } from './chatwoot.service'; +//import { SocksProxyAgent } from './socks-proxy-agent'; import { TypebotService } from './typebot.service'; export class WAStartupService {