"use client"; import { Download } from "lucide-react"; import { postAttachmentDownloadURL, type PostAttachment } from "@/lib/api"; import { toast } from "@/lib/toast"; function formatSize(n: number) { if (n < 1024) return `${n} B`; if (n < 1024 * 1024) return `${(n / 1024).toFixed(1)} KB`; return `${(n / 1024 / 1024).toFixed(1)} MB`; } export default function PostAttachments({ postId, items, }: { postId: number; items: PostAttachment[]; }) { if (!items.length) return null; const onClick = (a: PostAttachment) => { if (a.price_points > 0 && !a.unlocked) { // 仍走下载 URL:后端会扣积分或 402 toast(`将消耗 ${a.price_points} 积分下载`, "ok"); } window.location.href = postAttachmentDownloadURL(postId, a.id); }; return (

附件

); }