diff --git a/lib/upload-manager.js b/lib/upload-manager.js index eb376a6..68eac54 100644 --- a/lib/upload-manager.js +++ b/lib/upload-manager.js @@ -72,14 +72,20 @@ class UploadManager extends EventEmitter { /limit (reached|exceeded|überschritten)/i, /rate[- ]?limit/i, /too many requests/i, - /\b(401|403)\b/, + /\b(401|403|429)\b/, /Falscher (User|Username|Passwort)/i, /Incorrect (Login|Password)/i, /invalid (credentials|api[- ]?key|token|session)/i, /(account|user) (banned|suspended|disabled|gesperrt)/i, /not authorized/i, /forbidden/i, - /session (expired|abgelaufen)/i + /session (expired|abgelaufen)/i, + // Session/CSRF hints — the account's server session went stale, which + // no amount of retrying will fix. Re-login happens on the next account. + /CSRF[- ]?Token nicht gefunden/i, + /CSRF[- ]?token not found/i, + /Bist du eingeloggt/i, + /not logged in/i ]; return PATTERNS.some(p => p.test(m)); } @@ -524,23 +530,34 @@ class UploadManager extends EventEmitter { return; } - // Account rotation: mark the current account failed, wait for main to - // resolve the next fallback, then retry. Loop so A → B → C → ... works - // for hosters with 3+ accounts (the old code only did one level: A → B - // and stopped, even if C would have worked). + // Account rotation: mark the current account failed (if not already), + // wait for main to resolve the next fallback, then retry. Loops so + // A → B → C → ... works for hosters with 3+ accounts. + // + // CRITICAL: we must ALWAYS check for an existing override, even if this + // account is already in _failedAccounts (e.g. another concurrent job + // already marked it failed). Otherwise the second job falls straight + // through to final-error instead of using the already-resolved fallback. this._rotLog('retries-exhausted', { hoster: task.hoster, fileName, accountId: task.accountId, lastError: lastError ? lastError.message : null }); - while (task.accountId && !this._failedAccounts.has(task.hoster + ':' + task.accountId)) { + while (task.accountId) { if (signal.aborted || this.stopAfterActive) break; - this._failedAccounts.set(task.hoster + ':' + task.accountId, true); - this._rotLog('mark-failed', { - hoster: task.hoster, fileName, accountId: task.accountId, - lastError: lastError ? lastError.message : null - }); - this.emit('account-failed', { hoster: task.hoster, accountId: task.accountId }); - await this._sleep(800, signal); + const alreadyMarked = this._failedAccounts.has(task.hoster + ':' + task.accountId); + if (!alreadyMarked) { + this._failedAccounts.set(task.hoster + ':' + task.accountId, true); + this._rotLog('mark-failed', { + hoster: task.hoster, fileName, accountId: task.accountId, + lastError: lastError ? lastError.message : null + }); + this.emit('account-failed', { hoster: task.hoster, accountId: task.accountId }); + await this._sleep(800, signal); + } else { + this._rotLog('already-marked', { + hoster: task.hoster, fileName, accountId: task.accountId + }); + } const override = this._accountOverrides.get(task.hoster); if (!override) { this._rotLog('rotation-end', { @@ -556,6 +573,13 @@ class UploadManager extends EventEmitter { }); break; } + if (override.id === task.accountId) { + this._rotLog('rotation-end', { + hoster: task.hoster, fileName, reason: 'override-same-as-current', + lastFailedAccountId: task.accountId + }); + break; + } // Switch to fallback account and retry this file this._rotLog('rotate', { hoster: task.hoster, fileName,