chore: Add homepage link to theme card

This commit is contained in:
Mauro Balades
2024-08-15 11:22:19 +02:00
parent f36a630f81
commit 4c9b85e357
3 changed files with 38 additions and 1 deletions

View File

@@ -0,0 +1,25 @@
import { getThemeFromId } from "@/lib/themes";
import { NextApiRequest, NextApiResponse } from "next";
function getQSParamFromURL(
key: string,
url: string | undefined
): string | null {
if (!url) return "";
const search = new URL(url).search;
const urlParams = new URLSearchParams(search);
return urlParams.get(key);
}
export async function GET(request: NextApiRequest, response: NextApiResponse) {
const id = getQSParamFromURL("id", request.url);
if (!id) {
return Response.json({ error: "id is required" });
}
const theme = getThemeFromId(id);
if (!theme) {
return Response.json({ error: "theme not found" });
}
return Response.json( theme );
}