From b4cc59d25fe425624d96027c9105345a598e8e89 Mon Sep 17 00:00:00 2001 From: Kieran Date: Mon, 27 Nov 2023 17:19:27 +0000 Subject: [PATCH] refactor: remove size tag --- README.md | 1 - src/element/torrent-list.tsx | 2 +- src/page/new.tsx | 1 - src/page/torrent.tsx | 2 +- 4 files changed, 2 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 3d83bdb..53ada35 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,6 @@ "content": "", "tags": [ ["title", ""], - ["size", ""], ["btih", ""], ["t", ""], ["t", "(optional)"], diff --git a/src/element/torrent-list.tsx b/src/element/torrent-list.tsx index 88e2f21..5682e4a 100644 --- a/src/element/torrent-list.tsx +++ b/src/element/torrent-list.tsx @@ -31,7 +31,7 @@ export function TorrentList({ items }: { items: Array }) { function TorrentTableEntry({ item }: { item: TaggedNostrEvent }) { const profile = useUserProfile(item.pubkey); const name = item.tags.find((a) => a[0] === "title")?.at(1); - const size = Number(item.tags.find((a) => a[0] === "size")?.at(1)); + const size = item.tags.filter(a => a[0] === "file").map(a => Number(a[2])).reduce((acc, v) => acc += v, 0); const npub = hexToBech32("npub", item.pubkey); return ( diff --git a/src/page/new.tsx b/src/page/new.tsx index a4ebb43..e51f51f 100644 --- a/src/page/new.tsx +++ b/src/page/new.tsx @@ -90,7 +90,6 @@ export function NewPage() { .kind(TorrentKind) .content(obj.desc) .tag(["title", obj.name]) - .tag(["size", String(obj.files.reduce((acc, v) => (acc += v.size), 0))]) .tag(["btih", obj.btih]); obj.tags.forEach((t) => v.tag(["t", t])); diff --git a/src/page/torrent.tsx b/src/page/torrent.tsx index 72c4a6f..7a615a8 100644 --- a/src/page/torrent.tsx +++ b/src/page/torrent.tsx @@ -29,7 +29,7 @@ export function TorrentDetail({ item }: { item: TaggedNostrEvent }) { const login = useLogin(); const navigate = useNavigate(); const name = item.tags.find((a) => a[0] === "title")?.at(1); - const size = Number(item.tags.find((a) => a[0] === "size")?.at(1)); + const size = item.tags.filter(a => a[0] === "file").map(a => Number(a[2])).reduce((acc, v) => acc += v, 0); const files = item.tags.filter((a) => a[0] === "file"); const tags = item.tags.filter((a) => a[0] === "t").map((a) => a[1]);