Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Staubsaugarr

rqbit cleanup

Remove torrents which are at 0%. Only run this, when the checking phase is done. Use the dryRun prop to run this in dryRun.

(async (dryRun = false) => {
  const { torrents } = await (await fetch("/rqbit/torrents")).json();
  const zero = [];
  for (const t of torrents) {
    const s = await (await fetch(`/rqbit/torrents/${t.id}/stats/v1`)).json();
    if ((s.progress_bytes ?? 0) === 0) zero.push({ id: t.id, name: t.name });
  }
  console.table(zero);
  if (dryRun) return `${zero.length} matched — re-run with dryRun=false`;
  for (const t of zero) {
    const r = await fetch(`/rqbit/torrents/${t.id}/forget`, { method: "POST" });
    console.log(t.id, t.name, r.ok ? "ok" : `failed ${r.status}`);
  }
  return "done";
})();