import { Router } from "express";
import { getQbitClient } from "./qbit.context"

const router = Router();

router.get("/torrents", async (_req, res) => {
  const qbit = getQbitClient();
  const torrents = await qbit.getTorrentsInfo();
  res.json(torrents);
});

router.get("/transfer", async (_req, res) => {
  const qbit = getQbitClient();
  const transfer = await qbit.getTransferInfo();
  res.json(transfer);
});

router.get("/torrent/:hash", async (req, res) => {
  const qbit = getQbitClient();
  const props = await qbit.getTorrentProperties(req.params.hash);
  res.json(props);
});

router.delete("/torrent/:hash", async (req, res) => {
  const qbit = getQbitClient();
  await qbit.deleteTorrent(req.params.hash, true);
  res.json({ ok: true });
});

export default router;
