From a0800045ec8bf077f63d3ee7b3ef998c2411ccb2 Mon Sep 17 00:00:00 2001 From: Sucukdeluxe Date: Sat, 7 Mar 2026 18:02:34 +0100 Subject: [PATCH] Fix Debrid-Link key rotation: skip broken keys immediately, add cooldown cache - Add "notDebrid", "disabledServerHost", "notFree" as immediate-skip errors (no 3x retry per key, break to next key instantly like quota errors) - Add per-key cooldown cache (2 min) so parallel items skip recently-failed keys instead of all starting at the same broken key - Set cooldown on quota errors too, preventing repeated checks on exhausted keys Co-Authored-By: Claude Opus 4.6 --- src/main/debrid.ts | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/main/debrid.ts b/src/main/debrid.ts index cb2d678..26ec81d 100644 --- a/src/main/debrid.ts +++ b/src/main/debrid.ts @@ -21,6 +21,11 @@ const ONEFICHIER_URL_RE = /^https?:\/\/(?:www\.)?(?:1fichier\.com|alterupload\.c const DEBRID_LINK_API_BASE = "https://debrid-link.com/api/v2"; const DEBRID_LINK_QUOTA_ERRORS = new Set(["maxLink", "maxLinkHost", "maxData", "maxDataHost", "maxAttempts", "maxTransfer"]); +/** Errors where the key can't handle this link — skip to next key immediately, no retries */ +const DEBRID_LINK_SKIP_KEY_ERRORS = new Set(["notDebrid", "disabledServerHost", "notFree"]); +/** Per-key cooldown cache: keyId → expiry timestamp. Parallel items skip keys that recently failed. */ +const debridLinkKeyCooldowns = new Map(); +const DEBRID_LINK_KEY_COOLDOWN_MS = 120_000; // 2 min cooldown per failed key const LINKSNAPPY_API_BASE = "https://linksnappy.com/api"; @@ -1486,6 +1491,12 @@ class DebridLinkClient { this.currentKeyIndex = (this.currentKeyIndex + 1) % this.apiKeys.length; continue; } + const keyCooldownExpiry = debridLinkKeyCooldowns.get(apiKey.id); + if (keyCooldownExpiry && Date.now() < keyCooldownExpiry) { + logger.info(`Debrid-Link${keyLabel}: uebersprungen (Cooldown bis ${new Date(keyCooldownExpiry).toLocaleTimeString()}), pruefe naechsten Key`); + this.currentKeyIndex = (this.currentKeyIndex + 1) % this.apiKeys.length; + continue; + } let lastError = ""; for (let attempt = 1; attempt <= REQUEST_RETRIES; attempt += 1) { @@ -1509,7 +1520,12 @@ class DebridLinkClient { if (DEBRID_LINK_QUOTA_ERRORS.has(errorCode)) { logger.warn(`Debrid-Link${keyLabel}: API-Quota erreicht (${errorCode}: ${errorDesc}), wechsle zum naechsten Key`); - logger.warn(`Debrid-Link Quota erreicht${keyLabel}: ${errorCode} – ${errorDesc}`); + debridLinkKeyCooldowns.set(apiKey.id, Date.now() + DEBRID_LINK_KEY_COOLDOWN_MS); + break; + } + if (DEBRID_LINK_SKIP_KEY_ERRORS.has(errorCode)) { + logger.warn(`Debrid-Link${keyLabel}: Key kann Link nicht verarbeiten (${errorCode}: ${errorDesc}), wechsle zum naechsten Key`); + debridLinkKeyCooldowns.set(apiKey.id, Date.now() + DEBRID_LINK_KEY_COOLDOWN_MS); break; }