From 434da54ede8ece06c1fbcf4d66fe6ecdf87557a5 Mon Sep 17 00:00:00 2001 From: MasutaYunikon Date: Wed, 6 May 2026 23:00:12 +0200 Subject: [PATCH] =?UTF-8?q?fix(qbittorrent):=20FanKarr=20t=C3=A9l=C3=A9cha?= =?UTF-8?q?rge=20le=20.torrent=20et=20l'uploade=20directement=20=C3=A0=20q?= =?UTF-8?q?Bit?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit qBittorrent (Docker/runtipi) n'a pas forcément accès à nyaa.si depuis son réseau. FanKarr télécharge lui-même le fichier .torrent et l'envoie en upload direct à qBit, qui n'a donc plus besoin d'accès internet pour les métadonnées. --- server/torrent-clients/qbittorrent.ts | 35 ++++++++++++--------------- 1 file changed, 15 insertions(+), 20 deletions(-) diff --git a/server/torrent-clients/qbittorrent.ts b/server/torrent-clients/qbittorrent.ts index 0eea370..c853bb2 100644 --- a/server/torrent-clients/qbittorrent.ts +++ b/server/torrent-clients/qbittorrent.ts @@ -278,40 +278,35 @@ const QB: TorrentClientDriver = { } // Stratégie d'ajout selon le type de lien : - // .torrent URL → ajout en pause (métadonnées dans le fichier, disponibles immédiatement) - // magnet link → ajout normal (métadonnées viennent des pairs, la pause bloque leur récupération) + // .torrent URL → FanKarr télécharge le fichier et l'uploade directement à qBit + // (qBit n'a pas forcément accès à internet / nyaa.si depuis son réseau Docker) + // magnet link → passage de l'URL brute, ajout normal sans pause + // (les métadonnées arrivent via les pairs, la pause bloquerait tout) const isMagnet = url.startsWith('magnet:') const form = new FormData() - form.append('urls', url) if (config.category) form.append('category', String(config.category)) if (config.savePath) form.append('savepath', String(config.savePath)) - if (!isMagnet) { + + if (isMagnet) { + form.append('urls', url) + } else { + // FanKarr télécharge le .torrent et l'envoie directement à qBit + logger.debug('qbittorrent', `Téléchargement .torrent via FanKarr : ${url.slice(0, 120)}`) + const torrentRes = await fetch(url, { headers: { 'User-Agent': 'FanKarr/1.0' } }) + if (!torrentRes.ok) throw new Error(`Impossible de télécharger le .torrent (${torrentRes.status}) : ${url}`) + const torrentBytes = await torrentRes.arrayBuffer() + form.append('torrents', new Blob([torrentBytes], { type: 'application/x-bittorrent' }), 'torrent.torrent') + // Pause : métadonnées déjà dans le fichier → liste de fichiers disponible immédiatement form.append('paused', 'true') // qBit < 5.0 form.append('stopped', 'true') // qBit ≥ 5.0 } - logger.debug('qbittorrent', `Ajout torrent — URL : ${url.slice(0, 120)}${url.length > 120 ? '…' : ''}`) const res = await fetch(`${config.url}/api/v2/torrents/add`, { method: 'POST', body: form, headers: { Cookie: `SID=${sid}` }, }) const text = await res.text() if (text !== 'Ok.') throw new Error(`Ajout échoué : ${text}`) - // Vérifier que le torrent apparaît bien dans qBit après l'add - if (hash) { - let appeared = false - for (let i = 0; i < 10; i++) { - await new Promise(r => setTimeout(r, 300)) - const s2 = await qbLogin(config) - appeared = await qbTorrentExists(config, s2, hash) - if (appeared) break - } - if (!appeared) { - logger.warn('qbittorrent', `Torrent ${hash.slice(0, 8)}… non visible dans qBit après l'add — URL inaccessible depuis qBit ? URL : ${url.slice(0, 200)}`) - return - } - } - if (hash) { logger.info('qbittorrent', `Torrent ajouté (${isMagnet ? 'magnet, actif' : 'en pause'}) — sélection fichier ${options.file_index} en attente des métadonnées`) qbApplyFilePriority(config, hash, options.file_index, true).catch(err =>