fix: cookie

This commit is contained in:
MasutaYunikon committed 2026-05-07 14:57:30 +02:00
1 parent 2b3fd79a92
commit 7da5a8d4e8
1 file changed
+2 -5
+2 -5
View File
@@ -31,8 +31,6 @@ async function qbLogin(config: Record<string, string | number>): Promise<string>
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<string, string | number>): Promise<string>
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_<PORT>=<value> | <5.2.0 : SID=<value>
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]
}