fix: automate migration of session-whatsapp-bridge to session-slot-1 on startup
This commit is contained in:
@@ -728,22 +728,31 @@ 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...');
|
||||
|
||||
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(oldSessionPath, slot1SessionPath, { recursive: true });
|
||||
fs.cpSync(oldPath, slot1SessionPath, { recursive: true });
|
||||
} else {
|
||||
const { execSync } = require('child_process');
|
||||
execSync(`cp -R "${oldSessionPath}" "${slot1SessionPath}"`);
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Auto-bootstrap Slot 1 at startup
|
||||
bootstrapSlot(1);
|
||||
|
||||
Reference in New Issue
Block a user