2023-02-13 12:43:00 +00:00
|
|
|
const removeDir = require('./remove_dir');
|
|
|
|
const copyFolder = require('./copyFolder');
|
|
|
|
const path = require('path');
|
|
|
|
const fs = require('fs');
|
|
|
|
|
|
|
|
|
|
|
|
async function restore(client) {
|
|
|
|
|
2023-04-10 12:08:09 +00:00
|
|
|
try {
|
|
|
|
await client.destroy()
|
|
|
|
} catch (error) {
|
|
|
|
console.error(`Error on try destroy client: ${error}`)
|
|
|
|
}
|
2023-02-13 12:43:00 +00:00
|
|
|
|
|
|
|
const sessionBackupPath = path.join(process.cwd(), `session_backup`, `session-omnihit_sesssion`)
|
|
|
|
|
|
|
|
const sessionPath = path.join(process.cwd(), '.wwebjs_auth', 'session-omnihit_sesssion')
|
|
|
|
|
|
|
|
if (fs.existsSync(path.join(process.cwd(), `session_backup`, `session-omnihit_sesssion`))) {
|
|
|
|
|
|
|
|
await removeDir(sessionPath)
|
|
|
|
|
|
|
|
// copy the good session for backup dir
|
|
|
|
copyFolder(sessionBackupPath, sessionPath)
|
|
|
|
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
console.log('Directory not found to copy: ', sessionPath)
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
console.log('process.exit: kkkkkkkkkkkkkkkkkkkkk')
|
|
|
|
process.exit()
|
|
|
|
}, 5000)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = restore;
|