From aa8b500f57efb97aae10eb0bd8e254388a8aff42 Mon Sep 17 00:00:00 2001 From: MasutaYunikon Date: Thu, 7 May 2026 14:51:55 +0200 Subject: [PATCH] =?UTF-8?q?feat(qbittorrent):=20support=20cookie=20name=20?= =?UTF-8?q?(=E2=89=A55.2.0)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/torrent-clients/qbittorrent.ts | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/server/torrent-clients/qbittorrent.ts b/server/torrent-clients/qbittorrent.ts index f844962..4e287b5 100644 --- a/server/torrent-clients/qbittorrent.ts +++ b/server/torrent-clients/qbittorrent.ts @@ -15,15 +15,17 @@ function mapState(state: string): TorrentInfo['state'] { return 'unknown' } -// Retourne les headers d'authentification : Bearer (≥5.2.0) ou cookie SID (<5.2.0) +// Retourne les headers d'authentification : Bearer (≥5.2.0) ou cookie SID async function qbAuth(config: Record): Promise> { if (config.apiKey) { return { Authorization: `Bearer ${config.apiKey}` } } - const sid = await qbLogin(config) - return { Cookie: `SID=${sid}` } + const cookie = await qbLogin(config) + return { Cookie: cookie } } +// Retourne le cookie complet "name=value" à utiliser dans les requêtes suivantes. +// En ≥5.2.0, le nom est QBT_SID_ ; en <5.2.0, c'est SID. async function qbLogin(config: Record): Promise { const form = new URLSearchParams() form.append('username', String(config.username ?? '')) @@ -38,10 +40,12 @@ async function qbLogin(config: Record): Promise const text = await res.text() if (text !== 'Ok.') throw new Error(`Login échoué : ${text}`) - const cookie = res.headers.get('set-cookie') ?? '' - const sid = cookie.match(/SID=([^;]+)/)?.[1] - if (!sid) throw new Error('Cookie SID introuvable') - return sid + const setCookie = res.headers.get('set-cookie') ?? '' + // ≥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') + // match[0] = "QBT_SID_8080=abc123" ou "SID=abc123" — on renvoie le pair complet + return match[0] } async function qbTorrentExists(config: Record, authHeaders: Record, hash: string): Promise {