fix: automate migration of session-whatsapp-bridge to session-slot-1 on startup
This commit is contained in:
@@ -728,20 +728,29 @@ server.listen(PORT, async () => {
|
|||||||
await initDatabase();
|
await initDatabase();
|
||||||
|
|
||||||
// Session Migration Logic: Move old session to slot-1 if slot-1 is empty
|
// Session Migration Logic: Move old session to slot-1 if slot-1 is empty
|
||||||
const oldSessionPath = path.join(__dirname, '.wwebjs_auth', 'session');
|
const oldSessionPaths = [
|
||||||
|
path.join(__dirname, '.wwebjs_auth', 'session-whatsapp-bridge'),
|
||||||
|
path.join(__dirname, '.wwebjs_auth', 'session')
|
||||||
|
];
|
||||||
const slot1SessionPath = path.join(__dirname, '.wwebjs_auth', 'session-slot-1');
|
const slot1SessionPath = path.join(__dirname, '.wwebjs_auth', 'session-slot-1');
|
||||||
if (fs.existsSync(oldSessionPath) && !fs.existsSync(slot1SessionPath)) {
|
|
||||||
console.log('[MIGRATION] Migrating active WhatsApp session from old version to Slot 1...');
|
if (!fs.existsSync(slot1SessionPath)) {
|
||||||
try {
|
for (const oldPath of oldSessionPaths) {
|
||||||
if (fs.cpSync) {
|
if (fs.existsSync(oldPath)) {
|
||||||
fs.cpSync(oldSessionPath, slot1SessionPath, { recursive: true });
|
console.log(`[MIGRATION] Migrating active WhatsApp session from ${oldPath} to Slot 1...`);
|
||||||
} else {
|
try {
|
||||||
const { execSync } = require('child_process');
|
if (fs.cpSync) {
|
||||||
execSync(`cp -R "${oldSessionPath}" "${slot1SessionPath}"`);
|
fs.cpSync(oldPath, slot1SessionPath, { recursive: true });
|
||||||
|
} else {
|
||||||
|
const { execSync } = require('child_process');
|
||||||
|
execSync(`cp -R "${oldPath}" "${slot1SessionPath}"`);
|
||||||
|
}
|
||||||
|
console.log('[MIGRATION] Session migrated successfully! Slot 1 will load connected.');
|
||||||
|
break;
|
||||||
|
} catch (migrationErr) {
|
||||||
|
console.error('[MIGRATION ERROR] Failed to migrate session:', migrationErr.message);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
console.log('[MIGRATION] Session migrated successfully! Slot 1 will load connected.');
|
|
||||||
} catch (migrationErr) {
|
|
||||||
console.error('[MIGRATION ERROR] Failed to migrate session:', migrationErr.message);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user