fix: qbitorrent header

This commit is contained in:
MasutaYunikon committed 2026-04-29 18:34:51 +02:00
1 parent 9834023522
commit f5094c68c6
1 file changed
+17 -19
+17 -19
View File
@@ -79,24 +79,23 @@ async function qbApplyFilePriority(
// on se contente d'activer la nouvelle cible sans toucher aux autres. // on se contente d'activer la nouvelle cible sans toucher aux autres.
const isInitialState = files.every((f: any) => (f.priority ?? 1) > 0) const isInitialState = files.every((f: any) => (f.priority ?? 1) > 0)
const headers = { Cookie: `SID=${sid}`, 'Content-Type': 'application/x-www-form-urlencoded' }
if (isInitialState) { if (isInitialState) {
const unwanted = files.map((_, i) => i).filter(i => i !== fileIndex) const unwanted = files.map((_, i) => i).filter(i => i !== fileIndex)
if (unwanted.length > 0) { if (unwanted.length > 0) {
const form = new FormData() const body = new URLSearchParams({ hash, id: unwanted.join('|'), priority: '0' })
form.append('hash', hash) const r = await fetch(`${config.url}/api/v2/torrents/filePrio`, { method: 'POST', body, headers })
form.append('id', unwanted.join('|'))
form.append('priority', '0')
const r = await fetch(`${config.url}/api/v2/torrents/filePrio`, { method: 'POST', body: form, headers: { Cookie: `SID=${sid}` } })
if (!r.ok) { logger.warn('qbittorrent', `filePrio désactivation échouée (${r.status}) — retry`); continue } if (!r.ok) { logger.warn('qbittorrent', `filePrio désactivation échouée (${r.status}) — retry`); continue }
} }
} }
// Activer le fichier cible (dans tous les cas) // Activer le fichier cible (dans tous les cas)
const form2 = new FormData() const r2 = await fetch(`${config.url}/api/v2/torrents/filePrio`, {
form2.append('hash', hash) method: 'POST',
form2.append('id', String(fileIndex)) body : new URLSearchParams({ hash, id: String(fileIndex), priority: '1' }),
form2.append('priority', '1') headers,
const r2 = await fetch(`${config.url}/api/v2/torrents/filePrio`, { method: 'POST', body: form2, headers: { Cookie: `SID=${sid}` } }) })
if (!r2.ok) { logger.warn('qbittorrent', `filePrio activation échouée (${r2.status}) — retry`); continue } if (!r2.ok) { logger.warn('qbittorrent', `filePrio activation échouée (${r2.status}) — retry`); continue }
// Vérification : le fichier cible est bien à priorité > 0 // Vérification : le fichier cible est bien à priorité > 0
@@ -113,11 +112,10 @@ async function qbApplyFilePriority(
// Reprendre (torrent mis en pause via paused/stopped à l'ajout) // Reprendre (torrent mis en pause via paused/stopped à l'ajout)
// On appelle les deux endpoints : resume (qBit ≤ 4.x) et start (qBit ≥ 5.0) // On appelle les deux endpoints : resume (qBit ≤ 4.x) et start (qBit ≥ 5.0)
if (resume) { if (resume) {
const resumeForm = new FormData() const resumeBody = new URLSearchParams({ hashes: hash })
resumeForm.append('hashes', hash)
await Promise.allSettled([ await Promise.allSettled([
fetch(`${config.url}/api/v2/torrents/resume`, { method: 'POST', body: resumeForm, headers: { Cookie: `SID=${sid}` } }), fetch(`${config.url}/api/v2/torrents/resume`, { method: 'POST', body: resumeBody, headers }),
fetch(`${config.url}/api/v2/torrents/start`, { method: 'POST', body: resumeForm, headers: { Cookie: `SID=${sid}` } }), fetch(`${config.url}/api/v2/torrents/start`, { method: 'POST', body: resumeBody, headers }),
]) ])
} }
@@ -131,12 +129,12 @@ async function qbApplyFilePriority(
// Timeout : reprendre quand même pour ne pas laisser le torrent bloqué // Timeout : reprendre quand même pour ne pas laisser le torrent bloqué
if (resume) { if (resume) {
try { try {
const sid = await qbLogin(config) const sid = await qbLogin(config)
const resumeForm = new FormData() const headers = { Cookie: `SID=${sid}`, 'Content-Type': 'application/x-www-form-urlencoded' }
resumeForm.append('hashes', hash) const body = new URLSearchParams({ hashes: hash })
await Promise.allSettled([ await Promise.allSettled([
fetch(`${config.url}/api/v2/torrents/resume`, { method: 'POST', body: resumeForm, headers: { Cookie: `SID=${sid}` } }), fetch(`${config.url}/api/v2/torrents/resume`, { method: 'POST', body, headers }),
fetch(`${config.url}/api/v2/torrents/start`, { method: 'POST', body: resumeForm, headers: { Cookie: `SID=${sid}` } }), fetch(`${config.url}/api/v2/torrents/start`, { method: 'POST', body, headers }),
]) ])
} catch {} } catch {}
} }