mirror of
https://github.com/EvolutionAPI/evolution-api.git
synced 2025-12-25 22:57:44 -06:00
fix: fix problems in create instance and delete instance files
This commit is contained in:
@@ -72,6 +72,18 @@ export class AuthService {
|
||||
return { apikey };
|
||||
}
|
||||
|
||||
public async checkDuplicateToken(token: string) {
|
||||
const instances = await this.waMonitor.instanceInfo();
|
||||
|
||||
const instance = instances.find((instance) => instance.instance.apikey === token);
|
||||
|
||||
if (instance) {
|
||||
throw new BadRequestException('Token already exists');
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public async generateHash(instance: InstanceDto, token?: string) {
|
||||
const options = this.configService.get<Auth>('AUTHENTICATION');
|
||||
return (await this[options.TYPE](instance, token)) as
|
||||
|
||||
@@ -16,7 +16,6 @@ import { NotFoundException } from '../../exceptions';
|
||||
import { Db } from 'mongodb';
|
||||
import { RedisCache } from '../../db/redis.client';
|
||||
import { initInstance } from '../whatsapp.module';
|
||||
import { ValidationError } from 'class-validator';
|
||||
|
||||
export class WAMonitoringService {
|
||||
constructor(
|
||||
@@ -50,9 +49,19 @@ export class WAMonitoringService {
|
||||
public delInstanceTime(instance: string) {
|
||||
const time = this.configService.get<DelInstance>('DEL_INSTANCE');
|
||||
if (typeof time === 'number' && time > 0) {
|
||||
setTimeout(() => {
|
||||
setTimeout(async () => {
|
||||
if (this.waInstances[instance]?.connectionStatus?.state !== 'open') {
|
||||
delete this.waInstances[instance];
|
||||
if (this.waInstances[instance]?.connectionStatus?.state === 'connecting') {
|
||||
await this.waInstances[instance]?.client?.logout(
|
||||
'Log out instance: ' + instance,
|
||||
);
|
||||
this.waInstances[instance]?.client?.ws?.close();
|
||||
this.waInstances[instance]?.client?.end(undefined);
|
||||
delete this.waInstances[instance];
|
||||
} else {
|
||||
delete this.waInstances[instance];
|
||||
this.eventEmitter.emit('remove.instance', instance, 'inner');
|
||||
}
|
||||
}
|
||||
}, 1000 * 60 * time);
|
||||
}
|
||||
@@ -156,7 +165,7 @@ export class WAMonitoringService {
|
||||
}, 3600 * 1000 * 2);
|
||||
}
|
||||
|
||||
private async cleaningUp(instanceName: string) {
|
||||
public async cleaningUp(instanceName: string) {
|
||||
if (this.db.ENABLED && this.db.SAVE_DATA.INSTANCE) {
|
||||
await this.repository.dbServer.connect();
|
||||
const collections: any[] = await this.dbInstance.collections();
|
||||
|
||||
@@ -30,7 +30,7 @@ import makeWASocket, {
|
||||
WAMessageUpdate,
|
||||
WASocket,
|
||||
getAggregateVotesInPollMessage,
|
||||
} from '@evolution/base';
|
||||
} from '@whiskeysockets/baileys';
|
||||
import {
|
||||
Auth,
|
||||
CleanStoreConf,
|
||||
|
||||
Reference in New Issue
Block a user