import { unwrap } from "@snort/shared"; import { NoteCollection, RequestBuilder, TaggedNostrEvent, parseNostrLink } from "@snort/system"; import { useRequestBuilder } from "@snort/system-react"; import { useLocation, useNavigate, useParams } from "react-router-dom"; import { FormatBytes, TorrentKind } from "../const"; import { ProfileImage } from "../element/profile-image"; import { MagnetLink } from "../element/magnet"; import { useLogin } from "../login"; import { Button } from "../element/button"; export function TorrentPage() { const location = useLocation(); const { id } = useParams(); const evState = "kind" in location.state ? (location.state as TaggedNostrEvent) : undefined; const rb = new RequestBuilder("torrent:event"); rb.withFilter() .kinds([TorrentKind]) .link(parseNostrLink(unwrap(id))); const evNew = useRequestBuilder(NoteCollection, evState ? null : rb); const ev = evState ?? evNew.data?.at(0); if (!ev) return; return ; } 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 files = item.tags.filter(a => a[0] === "file"); const tags = item.tags.filter(a => a[0] === "t").map(a => a[1]); async function deleteTorrent() { const ev = await login?.builder?.delete(item.id); if (ev) { await login?.system.BroadcastEvent(ev); navigate(-1); } } return (
{name}
Size: {FormatBytes(size)}
Uploaded: {new Date(item.created_at * 1000).toLocaleDateString()}
Tags:
{tags.map(a =>
#{a}
)}
Get this torrent

Description

{item.content}

Files

{files.map(a =>
{a[1]} {FormatBytes(Number(a[2]))}
)}
{item.pubkey == login?.publicKey && }
); }