Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions app/d/[slug]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,20 @@ type Props = {
searchParams: Promise<{ [k: string]: string | string[] | undefined }>;
};

export async function generateMetadata({ params }: Props): Promise<Metadata> {
export async function generateMetadata({ params, searchParams }: Props): Promise<Metadata> {
const { slug } = await params;
const doc = await findBySlug(slug);
const title = doc ? (doc.title || doc.slug) : "private";
return { title: `${title} — justhtml.sh` };
if (doc) {
const sp = await searchParams;
const rawToken = sp.viewtoken;
const viewtoken = Array.isArray(rawToken) ? (rawToken[0] ?? null) : (rawToken ?? null);
const req = await reconstructRequest();
const session = await getSession(req);
if (await canViewSession(doc, session, viewtoken)) {
return { title: `${doc.title || doc.slug} — justhtml.sh` };
}
}
return { title: "justhtml.sh" };
}

async function reconstructRequest(): Promise<Request> {
Expand Down
Loading