From e22784cef8f3591170e98aaafcbefe52d609689f Mon Sep 17 00:00:00 2001 From: Administrator Date: Sat, 21 Mar 2026 15:24:41 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix(hosters):=20API=20JSON=20par?= =?UTF-8?q?se=20safety=20+=20URL-encode=20API=20key?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - apiGet(): wrap res.json() in try-catch with descriptive error message when server returns HTML instead of JSON - URL-encode apiKey in upload server lookup URL template (prevents broken URLs if key contains +, &, = chars) Co-Authored-By: Claude Opus 4.6 (1M context) --- lib/hosters.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/hosters.js b/lib/hosters.js index 80e2b49..367e857 100644 --- a/lib/hosters.js +++ b/lib/hosters.js @@ -281,7 +281,13 @@ async function apiGet(url, signal) { signal: controller.signal, redirect: 'follow' }); - const data = await res.json(); + let data; + try { + data = await res.json(); + } catch { + const text = await res.text().catch(() => ''); + throw new Error(`API-Antwort war kein JSON (HTTP ${res.status}): ${(text || '').slice(0, 200)}`); + } if (data.status && [401, 403, 429, 500].includes(data.status)) { throw new Error(data.msg || data.message || JSON.stringify(data)); @@ -300,7 +306,7 @@ async function getUploadServer(hosterName, hosterConfig, apiKey, signal) { for (let attempt = 1; attempt <= SERVER_RETRY_ATTEMPTS; attempt++) { for (const endpoint of hosterConfig.serverEndpoints) { - const url = `${hosterConfig.apiBase}${endpoint}?key=${apiKey}`; + const url = `${hosterConfig.apiBase}${endpoint}?key=${encodeURIComponent(apiKey)}`; try { const data = await apiGet(url, signal); const uploadUrl = extractUploadServerUrl(data, hosterConfig.apiBase);