whatsapp_bridge/server.js aktualisiert
1.3.1 FIX Lade Client error
This commit is contained in:
@@ -12,10 +12,8 @@ let lastQr = "";
|
||||
let isReady = false;
|
||||
let isInitializing = true;
|
||||
|
||||
// Fester Speicherort für die Session außerhalb flüchtiger Docker-Verzeichnisse
|
||||
const SESSION_DATA = '/data/auth';
|
||||
|
||||
// Sauberes Herunterfahren bei Abstürzen, um Dateikorruption der Session zu verhindern
|
||||
async function handleCrash(errorContext) {
|
||||
console.error(`💥 CRITICAL ERROR CAUGHT: ${errorContext}`);
|
||||
isReady = false;
|
||||
@@ -33,7 +31,6 @@ async function handleCrash(errorContext) {
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
// Sicherheitsnetz für ungefangene Puppeteer/Browser-Fehler
|
||||
process.on('uncaughtException', async (err) => {
|
||||
if (err.message.includes('ProtocolError') || err.message.includes('Runtime.callFunctionOn') || err.message.includes('Target closed')) {
|
||||
await handleCrash('Puppeteer Protocol Timeout / Crash');
|
||||
@@ -50,7 +47,6 @@ process.on('unhandledRejection', async (reason, promise) => {
|
||||
}
|
||||
});
|
||||
|
||||
// Client-Definition mit fixierter Client-ID gegen Session-Verlust
|
||||
const client = new Client({
|
||||
authStrategy: new LocalAuth({
|
||||
dataPath: SESSION_DATA,
|
||||
@@ -66,18 +62,13 @@ const client = new Client({
|
||||
'--disable-setuid-sandbox',
|
||||
'--disable-dev-shm-usage',
|
||||
'--disable-gpu',
|
||||
'--no-first-run',
|
||||
'--no-zygote',
|
||||
'--single-process',
|
||||
'--disable-extensions',
|
||||
'--disable-background-timer-throttling',
|
||||
'--disable-backgrounding-occluded-windows',
|
||||
'--disable-renderer-backgrounding'
|
||||
'--single-process',
|
||||
'--disable-extensions'
|
||||
]
|
||||
}
|
||||
});
|
||||
|
||||
// QR Code Handling
|
||||
client.on('qr', (qr) => {
|
||||
lastQr = qr;
|
||||
isReady = false;
|
||||
@@ -89,7 +80,7 @@ client.on('ready', () => {
|
||||
isReady = true;
|
||||
lastQr = "";
|
||||
isInitializing = false;
|
||||
console.log('WhatsApp ist bereit! Session wurde erfolgreich geladen/gespeichert.');
|
||||
console.log('WhatsApp ist bereit!');
|
||||
});
|
||||
|
||||
client.on('disconnected', async (reason) => {
|
||||
@@ -127,7 +118,6 @@ app.get('/api/status', async (req, res) => {
|
||||
}
|
||||
});
|
||||
|
||||
// Logout & Session-Löschung (Nur bei explizitem Klick auf "Account wechseln")
|
||||
app.post('/auth/logout', async (req, res) => {
|
||||
try {
|
||||
console.log("Manueller Logout über Web-UI...");
|
||||
@@ -140,7 +130,6 @@ app.post('/auth/logout', async (req, res) => {
|
||||
}
|
||||
});
|
||||
|
||||
// Factory Reset
|
||||
app.delete('/system/reset', async (req, res) => {
|
||||
try {
|
||||
await client.destroy().catch(() => {});
|
||||
@@ -152,7 +141,6 @@ app.delete('/system/reset', async (req, res) => {
|
||||
}
|
||||
});
|
||||
|
||||
// Sende-Schnittstelle
|
||||
app.post('/send', async (req, res) => {
|
||||
const { number, message } = req.body;
|
||||
if (!isReady) return res.status(503).json({ error: 'Client nicht bereit' });
|
||||
|
||||
Reference in New Issue
Block a user