Alteração no cache
parent
7c7627873c
commit
2c6b6c7309
|
@ -18,7 +18,7 @@ const autoRestore = async (whatsappId: string | number, started_action_by: strin
|
|||
|
||||
// console.log('>>>>>>>>>>> Whatsapp.id: ', whatsappId)
|
||||
|
||||
restartWhatsSession(whatsapp, true)
|
||||
await restartWhatsSession(whatsapp, true)
|
||||
|
||||
|
||||
const sourcePath = path.join(__dirname, `../../.wwebjs_auth/sessions/log`)
|
||||
|
|
|
@ -0,0 +1,24 @@
|
|||
// require fs module
|
||||
const fs = require("fs");
|
||||
|
||||
|
||||
// Delete a directory and its children
|
||||
export const creationTime = (sourcePath: string) => {
|
||||
|
||||
if (fs.existsSync(sourcePath)) {
|
||||
|
||||
try {
|
||||
|
||||
const { birthtime } = fs.statSync(sourcePath)
|
||||
|
||||
return birthtime
|
||||
|
||||
} catch (error) {
|
||||
console.log(`There was an error on trying get de file/directory creation info from ${sourcePath}: `, error)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return
|
||||
|
||||
}
|
|
@ -142,7 +142,7 @@ export const getRestoreControll = () => {
|
|||
|
||||
export const _restore = async (whatsapp: Whatsapp, msg_file_title: string) => {
|
||||
|
||||
if (whatsapp.status != 'RESTORING') {
|
||||
if (whatsapp.status != 'RESTORING' && whatsapp.status != 'qrcode') {
|
||||
|
||||
console.log('THE WHATSAAP ID: ', whatsapp.id, ' WILL BE RESTORED SOON!')
|
||||
|
||||
|
|
|
@ -117,6 +117,7 @@ async function searchWhatsappCache(id: string, status: string) {
|
|||
const number_cache: any = await redis.hgetall(`whatsapp:${id}`)
|
||||
|
||||
if(Object.entries(number_cache).length == 0){
|
||||
redis.quit()
|
||||
return []
|
||||
}
|
||||
|
||||
|
|
|
@ -10,19 +10,24 @@ import { getRestoreControll, setRestoreControll, shifRestoreControll } from "../
|
|||
import ShowWhatsAppService from "../WhatsappService/ShowWhatsAppService";
|
||||
import { restartWhatsSession } from "../../helpers/RestartWhatsSession";
|
||||
|
||||
import dir from 'path';
|
||||
|
||||
import autoRestore from "../../helpers/AutoRestore";
|
||||
import { creationTime } from "../../helpers/CreationTime";
|
||||
import { splitDateTime } from "../../helpers/SplitDateTime";
|
||||
|
||||
import { format } from "date-fns";
|
||||
import ptBR from 'date-fns/locale/pt-BR';
|
||||
|
||||
let lstAutoRestore: any = []
|
||||
|
||||
export const StartWhatsAppSession = async (whatsapp: Whatsapp, backupSession: boolean = false): Promise<void> => {
|
||||
await whatsapp.update({ status: "OPENING" });
|
||||
await whatsapp.update({ status: "OPENING" });
|
||||
|
||||
await insertOrUpeateWhatsCache(`whatsapp:${whatsapp.id}`, {
|
||||
status: "OPENING",
|
||||
})
|
||||
|
||||
|
||||
|
||||
try {
|
||||
|
||||
let lstRestore: any = getRestoreControll()
|
||||
|
@ -34,7 +39,7 @@ export const StartWhatsAppSession = async (whatsapp: Whatsapp, backupSession: bo
|
|||
}
|
||||
else {
|
||||
|
||||
lstAutoRestore.push({ 'whatsappId': +whatsapp.id })
|
||||
lstAutoRestore.push({ 'whatsappId': +whatsapp.id })
|
||||
|
||||
setTimeout(async () => {
|
||||
|
||||
|
@ -46,22 +51,22 @@ export const StartWhatsAppSession = async (whatsapp: Whatsapp, backupSession: bo
|
|||
|
||||
let autoR = lstAutoRestore.shift()
|
||||
|
||||
console.log('----------------> autoR: ', autoR)
|
||||
console.log('----------------> autoR: ', autoR)
|
||||
|
||||
if (autoR && autoR.whatsappId) {
|
||||
if (autoR && autoR.whatsappId) {
|
||||
|
||||
if (Object.keys(lstRestore.filter((e: any) => +e.id == +autoR.whatsappId)).length) {
|
||||
|
||||
console.log(' EXECUTING RESTORING autoR: ', autoR)
|
||||
|
||||
|
||||
continue
|
||||
}
|
||||
|
||||
const _whatsapp = await Whatsapp.findOne({ where: { id: autoR.whatsappId } });
|
||||
|
||||
console.log('----------------> autoR exec after 120 seconds: ', autoR)
|
||||
console.log('----------------> autoR exec after 120 seconds: ', autoR)
|
||||
|
||||
let whatsappStatus = ["CONFLICT",
|
||||
let whatsappStatus = ["CONFLICT",
|
||||
"DEPRECATED_VERSION",
|
||||
"OPENING",
|
||||
"PROXYBLOCK",
|
||||
|
@ -74,13 +79,13 @@ export const StartWhatsAppSession = async (whatsapp: Whatsapp, backupSession: bo
|
|||
|
||||
if (_whatsapp?.status) {
|
||||
|
||||
if (whatsappStatus.includes(_whatsapp.status)) {
|
||||
if (whatsappStatus.includes(_whatsapp.status)) {
|
||||
|
||||
await autoRestore(autoR.whatsappId, 'auto_monit')
|
||||
await autoRestore(autoR.whatsappId, 'auto_monit')
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue