← back to Trademarks Copyright
src/app/drops/view/[token]/[dropId]/page.tsx
41 lines
import { notFound } from "next/navigation";
import Link from "next/link";
import { query } from "@/lib/db";
import { renderDropHTML } from "@/lib/drops";
type Params = { token: string; dropId: string };
export default async function DropView({ params }: { params: Promise<Params> }) {
const { token, dropId: dropIdStr } = await params;
const dropId = Number(dropIdStr);
if (!Number.isFinite(dropId)) notFound();
const { rows: subs } = await query<{ id: number; tier: string; token: string }>(
`SELECT id, tier, token FROM subscribers WHERE token = $1`, [token]
);
if (!subs.length) notFound();
const sub = subs[0];
// Gate: subscriber must have actually received this drop OR be pro/comp preview.
const { rows: delivered } = await query<{ n: string }>(
`SELECT COUNT(*)::text AS n FROM deliveries WHERE drop_id = $1 AND subscriber_id = $2`,
[dropId, sub.id]
);
const hasDelivery = Number(delivered[0]?.n ?? 0) > 0;
if (!hasDelivery && sub.tier !== "pro" && sub.tier !== "comp") notFound();
const { html } = await renderDropHTML({
dropId,
tier: sub.tier as "trial" | "standard" | "pro" | "comp",
subscriberToken: sub.token,
appBaseUrl: "",
});
return (
<div>
<div className="mb-3 text-sm"><Link href={`/drops/view/${token}`} className="text-ink/60 hover:text-brass">← Archive</Link></div>
<div className="card bg-white p-0 overflow-hidden" dangerouslySetInnerHTML={{ __html: html }} />
</div>
);
}