diff --git a/src/app/(twibbon)/twbn/[slug]/page.tsx b/src/app/(twibbon)/twbn/[slug]/page.tsx new file mode 100644 index 00000000..761fae8f --- /dev/null +++ b/src/app/(twibbon)/twbn/[slug]/page.tsx @@ -0,0 +1,27 @@ +import { notFound, redirect } from "next/navigation"; +import { findTwibbon } from "@/utils/database/twibbon.query"; + +export default async function TwibbonRedirectPage({ + params, +}: { + params: { slug: string }; +}) { + const { slug } = params; + const twibbon = await findTwibbon({ slug }); + + if (!twibbon) { + return notFound(); + } + + redirect( + `https://twibbon.moklet.org/go?` + + new URLSearchParams({ + title: twibbon.title, + slug, + frameUrl: twibbon.frame_url, + ...(twibbon.caption + ? { caption: encodeURIComponent(twibbon.caption) } + : {}), + }).toString(), + ); +} diff --git a/src/app/(twibbon)/twbn/[slug]/route.ts b/src/app/(twibbon)/twbn/[slug]/route.ts deleted file mode 100644 index 860c3782..00000000 --- a/src/app/(twibbon)/twbn/[slug]/route.ts +++ /dev/null @@ -1,23 +0,0 @@ -import { internalServerError } from "@/utils/apiResponse"; -import { findTwibbon } from "@/utils/database/twibbon.query"; -import { notFound } from "next/navigation"; -import { NextRequest, NextResponse } from "next/server"; - -export async function GET( - req: NextRequest, - { params }: { params: { slug: string } }, -) { - try { - const { slug } = params; - const twibbon = await findTwibbon({ slug }); - - if (!twibbon) return notFound(); - - return NextResponse.redirect( - `https://twibbon.moklet.org/go?title=${twibbon.title}&slug=${slug}&frameUrl=${twibbon.frame_url}${twibbon?.caption ? "&caption=" + encodeURIComponent(twibbon.caption as string) : ""}`, - { status: 302 }, - ); - } catch (error) { - return internalServerError([]); - } -}