feat(qbittorrent): show share ratio for active torrents
This commit is contained in:
@@ -17,6 +17,7 @@ interface ActiveTorrent {
|
||||
direction?: "downloading" | "uploading";
|
||||
size: number | null;
|
||||
progress: number | null;
|
||||
ratio: number | null;
|
||||
dl_speed: number | null;
|
||||
up_speed: number | null;
|
||||
}
|
||||
@@ -40,6 +41,12 @@ function formatProgress(progress: number | null): string {
|
||||
return `${Math.round(progress * 100)}% complete`;
|
||||
}
|
||||
|
||||
function formatRatio(ratio: number | null): string {
|
||||
if (ratio === null || !Number.isFinite(ratio) || ratio < 0)
|
||||
return "Ratio unknown";
|
||||
return `Ratio ${ratio.toFixed(2)}`;
|
||||
}
|
||||
|
||||
function formatState(
|
||||
state: string | null,
|
||||
direction?: ActiveTorrent["direction"],
|
||||
@@ -103,7 +110,8 @@ export function QbittorrentActiveTorrentsWidget({
|
||||
</p>
|
||||
<p className="text-xs text-muted-foreground">
|
||||
{formatSize(torrent.size)} ·{" "}
|
||||
{formatProgress(torrent.progress)}
|
||||
{formatProgress(torrent.progress)} ·{" "}
|
||||
{formatRatio(torrent.ratio)}
|
||||
</p>
|
||||
</div>
|
||||
<Badge
|
||||
|
||||
@@ -54,6 +54,7 @@ describe("QbittorrentActiveTorrentsWidget", () => {
|
||||
state: "downloading",
|
||||
size: 1000,
|
||||
progress: 0.5,
|
||||
ratio: 1.25,
|
||||
dl_speed: 500000,
|
||||
up_speed: 1000,
|
||||
},
|
||||
@@ -77,6 +78,7 @@ describe("QbittorrentActiveTorrentsWidget", () => {
|
||||
expect(screen.getByText("Show.mkv")).toBeInTheDocument();
|
||||
expect(screen.getByText("Downloading")).toBeInTheDocument();
|
||||
expect(screen.getByText("Uploading")).toBeInTheDocument();
|
||||
expect(screen.getByText(/Ratio 1\.25/)).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("shows empty state when no active torrents", () => {
|
||||
|
||||
Reference in New Issue
Block a user