From 224bed32b51131d54a6948ceb08a90211de8448a Mon Sep 17 00:00:00 2001 From: Hamza-Ayed Date: Mon, 18 May 2026 20:26:06 +0300 Subject: [PATCH] fix: automate migration of session-whatsapp-bridge to session-slot-1 on startup --- whatsapp_bridge/server.js | 33 +++++++++++++++++++++------------ 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/whatsapp_bridge/server.js b/whatsapp_bridge/server.js index 72b8a39..22d9697 100644 --- a/whatsapp_bridge/server.js +++ b/whatsapp_bridge/server.js @@ -728,20 +728,29 @@ server.listen(PORT, async () => { await initDatabase(); // 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'); - if (fs.existsSync(oldSessionPath) && !fs.existsSync(slot1SessionPath)) { - console.log('[MIGRATION] Migrating active WhatsApp session from old version to Slot 1...'); - try { - if (fs.cpSync) { - fs.cpSync(oldSessionPath, slot1SessionPath, { recursive: true }); - } else { - const { execSync } = require('child_process'); - execSync(`cp -R "${oldSessionPath}" "${slot1SessionPath}"`); + + if (!fs.existsSync(slot1SessionPath)) { + for (const oldPath of oldSessionPaths) { + if (fs.existsSync(oldPath)) { + console.log(`[MIGRATION] Migrating active WhatsApp session from ${oldPath} to Slot 1...`); + try { + if (fs.cpSync) { + 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); } }