From 7da5a8d4e853f7e92770f20352478a76ee91642d Mon Sep 17 00:00:00 2001 From: MasutaYunikon Date: Thu, 7 May 2026 14:57:30 +0200 Subject: [PATCH] fix: cookie --- server/torrent-clients/qbittorrent.ts | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/server/torrent-clients/qbittorrent.ts b/server/torrent-clients/qbittorrent.ts index 68b5d6c..b240fea 100644 --- a/server/torrent-clients/qbittorrent.ts +++ b/server/torrent-clients/qbittorrent.ts @@ -31,8 +31,6 @@ async function qbLogin(config: Record): Promise form.append('username', String(config.username ?? '')) form.append('password', String(config.password ?? '')) - logger.debug('qbittorrent', `Login → POST ${config.url}/api/v2/auth/login (user: ${config.username})`) - const res = await fetch(`${config.url}/api/v2/auth/login`, { method : 'POST', body : form, @@ -41,15 +39,14 @@ async function qbLogin(config: Record): Promise const text = await res.text() const setCookie = res.headers.get('set-cookie') ?? '' - logger.debug('qbittorrent', `Login ← HTTP ${res.status} | body: "${text.trim()}" | set-cookie: "${setCookie}"`) - if (text.trim() !== 'Ok.') throw new Error(`Login échoué : ${text.trim()}`) + // ≥5.2.0 : HTTP 204, body vide | <5.2.0 : HTTP 200, body "Ok." + if (!res.ok) throw new Error(`Login échoué : ${text.trim() || res.status}`) // ≥5.2.0 : QBT_SID_= | <5.2.0 : SID= const match = setCookie.match(/(?:QBT_SID_\d+|SID)=([^;]+)/) if (!match) throw new Error(`Cookie SID introuvable (set-cookie reçu : "${setCookie}")`) // match[0] = "QBT_SID_8080=abc123" ou "SID=abc123" — on renvoie le pair complet - logger.debug('qbittorrent', `Login OK — cookie: ${match[0].split('=')[0]}=***`) return match[0] }