Correção na api de gerenciamento de whatsapp para nao deletar sessão de outra aplicação caso tenha o mesmo id
parent
5073ccadf7
commit
57b32a99e7
|
@ -25,7 +25,11 @@ app.get('/', function (req, res) { return res.send('Express + TypeScript Server'
|
||||||
|
|
||||||
app.post('/api/session', async function (req, res) {
|
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))
|
console.log('__dirname: ', path.join(__dirname, '..', app_name))
|
||||||
|
|
||||||
|
@ -39,7 +43,7 @@ app.post('/api/session', async function (req, res) {
|
||||||
|
|
||||||
console.log('directoriesInDIrectory: ', directoriesInDIrectory)
|
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)
|
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]
|
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])
|
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])
|
appPort.push(+subDir[x].split('_')[3])
|
||||||
|
|
||||||
|
console.log('---------> appPort: '+appPort)
|
||||||
|
|
||||||
existSubDir = true
|
existSubDir = true
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -154,11 +160,11 @@ app.post('/api/session', async function (req, res) {
|
||||||
|
|
||||||
let numberSession = 1
|
let numberSession = 1
|
||||||
|
|
||||||
const dirSessionsNumberAppDirectories = fs.readdirSync(dirSessionsApp, { withFileTypes: true })
|
// const dirSessionsNumberAppDirectories = fs.readdirSync(dirSessionsApp, { withFileTypes: true })
|
||||||
.filter((item) => item.isDirectory() && item.name.includes(`${number}`))
|
// .filter((item) => item.isDirectory() && item.name.includes(`${number}`))
|
||||||
.map((item) => item.name);
|
// .map((item) => item.name);
|
||||||
|
|
||||||
console.log('dirSessionsNumberAppDirectories', dirSessionsNumberAppDirectories, ' | dirSessionsApp: ', dirSessionsApp)
|
// console.log('dirSessionsNumberAppDirectories', dirSessionsNumberAppDirectories, ' | dirSessionsApp: ', dirSessionsApp)
|
||||||
|
|
||||||
console.log('client_url: ', client_url)
|
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) {
|
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')
|
const sessionsPath = path.join(__dirname, '..', 'sessions')
|
||||||
|
|
||||||
|
@ -378,7 +388,7 @@ app.post('/api/session/del', async function (req, res) {
|
||||||
|
|
||||||
console.log('directoriesInDIrectory: ', directoriesInDIrectory)
|
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)
|
console.log('dirExist: ', dirExist)
|
||||||
|
|
||||||
|
@ -400,7 +410,7 @@ app.post('/api/session/del', async function (req, res) {
|
||||||
|
|
||||||
let whatsId = subDir[x].split('_')[0]
|
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])
|
let currPath = path.join(sessionsPath, directoriesInDIrectory[i], subDir[x])
|
||||||
|
|
||||||
|
@ -410,7 +420,7 @@ app.post('/api/session/del', async function (req, res) {
|
||||||
|
|
||||||
removeDir(currPath)
|
removeDir(currPath)
|
||||||
|
|
||||||
break
|
return res.send('ok')
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -43,7 +43,7 @@ export const wbotMonitorQrcodeRemote = async (req: Request, res: Response): Prom
|
||||||
|
|
||||||
const { whatsappId } = req.body
|
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 })
|
const whatsapp: any = await Whatsapp.findByPk(whatsappId, { raw: true })
|
||||||
// let whatsapp = await ShowWhatsAppService(whatsappId)
|
// let whatsapp = await ShowWhatsAppService(whatsappId)
|
||||||
|
|
Loading…
Reference in New Issue