projeto-hit/TEST_SERVER1/whats/helpers/backup_session.js

39 lines
1.0 KiB
JavaScript
Raw Normal View History

const removeDir = require('./remove_dir');
const copyFolder = require('./copyFolder');
const path = require('path');
const fs = require('fs');
async function backup_session(destroy, save_session_after, save_first_read_only=false) {
console.log('process.cwd(): ', process.cwd())
const sessionBackupPath = path.join(process.cwd(), `session_backup`, `session-omnihit_sesssion`)
if (fs.existsSync(sessionBackupPath) && save_first_read_only) return
destroy = setTimeout(async () => {
const sessionPath = path.join(process.cwd(), '.wwebjs_auth', 'session-omnihit_sesssion')
if (fs.existsSync(path.join(process.cwd(), '.wwebjs_auth'))) {
await removeDir(sessionBackupPath)
// copy the good session for backup dir
copyFolder(sessionPath, sessionBackupPath)
}
else {
console.log('Directory not found to copy backup_session: ', sessionPath)
}
}, save_session_after);
return destroy
}
module.exports = backup_session;