| Server IP : 127.0.0.1 / Your IP : 192.168.99.1 Web Server : Apache/2.4.35 (Win64) OpenSSL/1.1.1b mod_fcgid/2.3.9 System : Windows NT WIN-JEJMB9EN0L0 10.0 build 14393 (Windows Server 2016) AMD64 User : Administrator ( 0) PHP Version : 7.4.33 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : OFF | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : /laragon4/www/wa-gateway/server/controllers/ |
Upload File : |
'use strict'
const fs = require('fs')
const chats = (req, res) => {
const { token, type, jid } = req.body
if (token && type) {
try {
const file = fs.readFileSync(`credentials/${token}/multistore.js`, { encoding: 'utf8' })
// parsing data to json
let json = JSON.parse(file)
if (type === "chats") {
json = json.chats
} else if (type === "contacts") {
json = json.contacts
} else if (type === "messages") {
if (jid) {
// json = Object.values(json.messages[jid])
json = json.messages[jid]
} else {
json = json.messages
}
} else {
return res.send({ status: false, message: "Unknown type" })
}
if (typeof json === 'undefined') return res.send({ status: false, message: 'Data Not Found' })
return res.send(json.length > 0 ? json.reverse() : json)
} catch (error) {
process.env.NODE_ENV !== 'production' ? console.log(error) : null
return res.send({ status: false, error: error })
}
}
res.send({ status: false, error: 'wrong parameters' })
}
module.exports = {
chats
}