Fix Debrid-Link notDebrid handling

This commit is contained in:
Sucukdeluxe 2026-03-08 20:39:00 +01:00
parent e19cdf247c
commit df8cbcf1c9
3 changed files with 89 additions and 2 deletions

View File

@ -24,9 +24,9 @@ const DEBRID_LINK_QUOTA_ERRORS = new Set(["maxLink", "maxLinkHost", "maxData", "
const DEBRID_LINK_INVALID_TOKEN_ERRORS = new Set(["badToken", "hidedToken", "expired_token"]);
const DEBRID_LINK_RATE_LIMIT_ERRORS = new Set(["floodDetected"]);
const DEBRID_LINK_RETRYABLE_ERRORS = new Set(["internalError", "server_error"]);
const DEBRID_LINK_PROVIDER_WIDE_ERRORS = new Set(["notDebrid"]);
/** 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",
"notFreeHost",
"serverNotAllowed",
@ -1986,10 +1986,18 @@ class DebridLinkClient {
category: "quota"
};
}
if (DEBRID_LINK_PROVIDER_WIDE_ERRORS.has(code)) {
return {
fatal: true,
cooldownMs: 0,
message: `Link kann aktuell nicht generiert werden (${code}: ${description})`,
category: "skip"
};
}
if (DEBRID_LINK_SKIP_KEY_ERRORS.has(code)) {
return {
fatal: false,
cooldownMs: DEBRID_LINK_KEY_COOLDOWN_MS,
cooldownMs: 0,
message: `Key kann Link aktuell nicht verarbeiten (${code}: ${description})`,
category: "skip"
};

View File

@ -470,6 +470,9 @@ function isTemporaryUnrestrictError(errorText: string): boolean {
const text = String(errorText || "").toLowerCase();
return text.includes("server error")
|| text.includes("internal server error")
|| text.includes("notdebrid")
|| text.includes("unable to generate link")
|| text.includes("kann aktuell nicht generiert werden")
|| text.includes("temporarily unavailable")
|| text.includes("temporary unavailable")
|| text.includes("temporarily disabled")

View File

@ -459,6 +459,82 @@ describe("debrid service", () => {
expect(addCalls).toBe(2);
});
it("fails fast on provider-wide Debrid-Link notDebrid errors without rotating through all keys", async () => {
const settings = {
...defaultSettings(),
debridLinkApiKeys: "dl-key-one\ndl-key-two",
providerOrder: ["debridlink"] as const,
providerPrimary: "debridlink" as const,
providerSecondary: "none" as const,
providerTertiary: "none" as const,
autoProviderFallback: true
};
const authHeaders: string[] = [];
globalThis.fetch = (async (_input: RequestInfo | URL, init?: RequestInit): Promise<Response> => {
authHeaders.push(String((init?.headers as Record<string, string> | undefined)?.Authorization || ""));
return new Response(JSON.stringify({
success: false,
error: "notDebrid",
error_description: "notDebrid"
}), {
status: 403,
headers: { "Content-Type": "application/json" }
});
}) as typeof fetch;
const service = new DebridService(settings);
await expect(service.unrestrictLink("https://hoster.example/not-debrid.bin")).rejects.toThrow("Link kann aktuell nicht generiert werden (notDebrid: notDebrid)");
expect(authHeaders).toEqual(["Bearer dl-key-one"]);
});
it("continues to the next Debrid-Link key for non-provider-wide skip errors without caching a cooldown", async () => {
const settings = {
...defaultSettings(),
debridLinkApiKeys: "dl-key-one\ndl-key-two",
providerOrder: ["debridlink"] as const,
providerPrimary: "debridlink" as const,
providerSecondary: "none" as const,
providerTertiary: "none" as const,
autoProviderFallback: true
};
const authHeaders: string[] = [];
globalThis.fetch = (async (_input: RequestInfo | URL, init?: RequestInit): Promise<Response> => {
const authHeader = String((init?.headers as Record<string, string> | undefined)?.Authorization || "");
authHeaders.push(authHeader);
if (authHeader === "Bearer dl-key-one") {
return new Response(JSON.stringify({
success: false,
error: "noServerHost",
error_description: "host temporarily unavailable"
}), {
status: 403,
headers: { "Content-Type": "application/json" }
});
}
return new Response(JSON.stringify({
success: true,
value: {
downloadUrl: "https://debrid-link.example/second-key.bin",
name: "second-key.bin",
size: 4096
}
}), {
status: 200,
headers: { "Content-Type": "application/json" }
});
}) as typeof fetch;
const service = new DebridService(settings);
const result = await service.unrestrictLink("https://hoster.example/skip-key.bin");
expect(result.directUrl).toBe("https://debrid-link.example/second-key.bin");
expect(result.sourceAccountLabel).toBe("Key 2");
expect(authHeaders).toEqual(["Bearer dl-key-one", "Bearer dl-key-two"]);
});
it("uses BestDebrid auth header without token query fallback", async () => {
const settings = {
...defaultSettings(),