import { ImageResponse } from "next/og"; import { createClient } from "@vercel/kv"; import { shareString2Json } from "@/util/use-share"; const kv = process.env?.KV_REST_API_URL && process.env?.KV_REST_API_TOKEN ? createClient({ url: process.env.KV_REST_API_URL, token: process.env.KV_REST_API_TOKEN, }) : null; export const runtime = "edge"; const siteUrl = process.env.NODE_ENV === "production" ? "https://www.tryemoji.com/" : "http://localhost:3000/"; export async function GET(request: Request) { const { searchParams } = new URL(request.url); const image = await fetch(new URL("./image.png", import.meta.url)).then( (res) => res.arrayBuffer(), ); let base64URL = ""; let emoji = ""; const share = searchParams.get("share"); const option = share ? shareString2Json(share as string) : null; const apiURL = new URL("api/share", siteUrl); if (share) { apiURL.searchParams.set("share", share); const res = await fetch(apiURL.toString()); base64URL = await res.text(); emoji = option?.emoji || "👍"; } return new ImageResponse( (