Correção na api de gerenciamento de whatsapp para nao deletar sessão de outra aplicação caso tenha o mesmo id

pull/21/head
adriano 2023-04-11 17:17:17 -03:00
parent 5073ccadf7
commit 57b32a99e7
2 changed files with 22 additions and 12 deletions

View File

@ -25,7 +25,11 @@ app.get('/', function (req, res) { return res.send('Express + TypeScript Server'
app.post('/api/session', async function (req, res) {
const { app_name, whatsappId, client_url, number } = req.body
let { app_name, whatsappId, client_url, number } = req.body
if(app_name){
app_name = app_name.trim()
}
console.log('__dirname: ', path.join(__dirname, '..', app_name))
@ -39,7 +43,7 @@ app.post('/api/session', async function (req, res) {
console.log('directoriesInDIrectory: ', directoriesInDIrectory)
const dirExist = directoriesInDIrectory.filter((e) => e == app_name)
const dirExist = directoriesInDIrectory.filter((e) => e.trim() == app_name)
let dirSessionsApp = path.join(sessionsPath, app_name)
@ -75,7 +79,7 @@ app.post('/api/session', async function (req, res) {
let whatsId = subDir[x].split('_')[0]
if (whatsId == whatsappId) {
if (whatsId == whatsappId && app_name == directoriesInDIrectory[i]) {
let currPath = path.join(sessionsPath, directoriesInDIrectory[i], subDir[x])
@ -138,6 +142,8 @@ app.post('/api/session', async function (req, res) {
appPort.push(+subDir[x].split('_')[3])
console.log('---------> appPort: '+appPort)
existSubDir = true
}
@ -154,11 +160,11 @@ app.post('/api/session', async function (req, res) {
let numberSession = 1
const dirSessionsNumberAppDirectories = fs.readdirSync(dirSessionsApp, { withFileTypes: true })
.filter((item) => item.isDirectory() && item.name.includes(`${number}`))
.map((item) => item.name);
// const dirSessionsNumberAppDirectories = fs.readdirSync(dirSessionsApp, { withFileTypes: true })
// .filter((item) => item.isDirectory() && item.name.includes(`${number}`))
// .map((item) => item.name);
console.log('dirSessionsNumberAppDirectories', dirSessionsNumberAppDirectories, ' | dirSessionsApp: ', dirSessionsApp)
// console.log('dirSessionsNumberAppDirectories', dirSessionsNumberAppDirectories, ' | dirSessionsApp: ', dirSessionsApp)
console.log('client_url: ', client_url)
@ -368,7 +374,11 @@ app.post('/api/session/edit', async function (req, res) {
app.post('/api/session/del', async function (req, res) {
const { whatsappId, app_name } = req.body
let { whatsappId, app_name } = req.body
if(app_name){
app_name = app_name.trim()
}
const sessionsPath = path.join(__dirname, '..', 'sessions')
@ -378,7 +388,7 @@ app.post('/api/session/del', async function (req, res) {
console.log('directoriesInDIrectory: ', directoriesInDIrectory)
const dirExist = directoriesInDIrectory.filter((e) => e == app_name)
const dirExist = directoriesInDIrectory.filter((e) => e.trim() == app_name)
console.log('dirExist: ', dirExist)
@ -400,7 +410,7 @@ app.post('/api/session/del', async function (req, res) {
let whatsId = subDir[x].split('_')[0]
if (whatsId == whatsappId) {
if (whatsId == whatsappId && app_name == directoriesInDIrectory[i]) {
let currPath = path.join(sessionsPath, directoriesInDIrectory[i], subDir[x])
@ -410,7 +420,7 @@ app.post('/api/session/del', async function (req, res) {
removeDir(currPath)
break
return res.send('ok')
}

View File

@ -43,7 +43,7 @@ export const wbotMonitorQrcodeRemote = async (req: Request, res: Response): Prom
const { whatsappId } = req.body
console.log('-----------> whatsappId: ', req.body['whatsappId'])
console.log('-----------> QRCODE MONITOR whatsappId: ', req.body['whatsappId'])
const whatsapp: any = await Whatsapp.findByPk(whatsappId, { raw: true })
// let whatsapp = await ShowWhatsAppService(whatsappId)