fix: ne retire pas les fichiers quand on en ajoute sur le torrent
This commit is contained in:
1 parent
7e53bab0fc
commit
79b6a8bbb4
2 files changed
+28
-11
No files matched your search
@@ -70,17 +70,24 @@ async function qbApplyFilePriority(
|
||||
const files: any[] = await res.json()
|
||||
if (!Array.isArray(files) || files.length === 0) continue
|
||||
|
||||
// Désactiver tous les autres fichiers
|
||||
const unwanted = files.map((_, i) => i).filter(i => i !== fileIndex)
|
||||
if (unwanted.length > 0) {
|
||||
const form = new FormData()
|
||||
form.append('hash', hash)
|
||||
form.append('id', unwanted.join('|'))
|
||||
form.append('priority', '0')
|
||||
await fetch(`${config.url}/api/v2/torrents/filePrio`, { method: 'POST', body: form, headers: { Cookie: `SID=${sid}` } })
|
||||
// Si tous les fichiers sont à priorité normale (état initial du torrent),
|
||||
// on applique le filtrage complet : on désactive tout sauf la cible.
|
||||
// Si certains sont déjà à 0 (filtrage déjà effectué pour un épisode précédent),
|
||||
// on se contente d'activer la nouvelle cible sans toucher aux autres.
|
||||
const isInitialState = files.every((f: any) => (f.priority ?? 1) > 0)
|
||||
|
||||
if (isInitialState) {
|
||||
const unwanted = files.map((_, i) => i).filter(i => i !== fileIndex)
|
||||
if (unwanted.length > 0) {
|
||||
const form = new FormData()
|
||||
form.append('hash', hash)
|
||||
form.append('id', unwanted.join('|'))
|
||||
form.append('priority', '0')
|
||||
await fetch(`${config.url}/api/v2/torrents/filePrio`, { method: 'POST', body: form, headers: { Cookie: `SID=${sid}` } })
|
||||
}
|
||||
}
|
||||
|
||||
// Activer le fichier cible
|
||||
// Activer le fichier cible (dans tous les cas)
|
||||
const form2 = new FormData()
|
||||
form2.append('hash', hash)
|
||||
form2.append('id', String(fileIndex))
|
||||
|
||||
@@ -142,12 +142,22 @@ async function rtApplyFilePriority(
|
||||
for (let attempt = 0; attempt < 100; attempt++) {
|
||||
await new Promise(r => setTimeout(r, 300))
|
||||
try {
|
||||
const files: any[] = await rpcCall(config, 'f.multicall', [hash, '', 'f.size_bytes='])
|
||||
// Récupérer taille ET priorité courante de chaque fichier
|
||||
const files: any[] = await rpcCall(config, 'f.multicall', [hash, '', 'f.size_bytes=', 'f.priority='])
|
||||
const fileCount = Array.isArray(files) ? files.length : 0
|
||||
if (fileCount === 0) continue
|
||||
|
||||
// Si tous les fichiers sont à priorité normale (état initial),
|
||||
// on filtre tout sauf la cible. Sinon on active juste la cible.
|
||||
const isInitialState = files.every((f: any) => Number(f[1]) > 0)
|
||||
|
||||
for (let i = 0; i < fileCount; i++) {
|
||||
await rpcCall(config, 'f.priority.set', [hash, i, i === fileIndex ? 1 : 0])
|
||||
if (i === fileIndex) {
|
||||
await rpcCall(config, 'f.priority.set', [hash, i, 1])
|
||||
} else if (isInitialState) {
|
||||
await rpcCall(config, 'f.priority.set', [hash, i, 0])
|
||||
}
|
||||
// Si pas initial state : on ne touche pas aux autres fichiers
|
||||
}
|
||||
|
||||
logger.info('rtorrent', `Fichier ${fileIndex} sélectionné pour ${hash.slice(0, 8)}…`)
|
||||
|
||||
Reference in new issue
Block a user