chore: migrate OG image generation API to App Router (#19568)

* migrate

* improve apiRouteMiddleware wrapper type

* refactor

* fix type check

* fix build

* fix

* Do not import stripe lib in getServerErrorFromUnknown

* address comment

* remove comment

* add url

* keep the location

* remove space

* add unit test for getServerErrorFromUnknown

* improve

* fix
This commit is contained in:
Benny Joo
2025-02-28 11:03:20 +01:00
committed by GitHub
parent c1ef57e3c2
commit 87f161d944
2 changed files with 15 additions and 15 deletions
+1 -1
View File
@@ -6,7 +6,7 @@ import { NextResponse } from "next/server";
import { getServerErrorFromUnknown } from "@calcom/lib/server/getServerErrorFromUnknown";
export const apiRouteMiddleware =
(handler: (req: NextRequest, { params }: { params: Params }) => Promise<NextResponse>) =>
(handler: (req: NextRequest, { params }: { params: Params }) => Promise<NextResponse | Response>) =>
async (req: NextRequest, { params }: { params: Params }) => {
try {
return await handler(req, { params });
@@ -1,25 +1,21 @@
import type { NextApiRequest } from "next";
import { apiRouteMiddleware } from "app/api/apiRouteMiddleware";
import type { NextRequest } from "next/server";
import { ImageResponse } from "next/server";
import type { SatoriOptions } from "satori";
import { z } from "zod";
import { Meeting, App, Generic } from "@calcom/lib/OgImages";
import { WEBAPP_URL } from "@calcom/lib/constants";
const calFont = fetch(new URL("../../../../public/fonts/cal.ttf", import.meta.url)).then((res) =>
const calFont = fetch(new URL("/fonts/cal.ttf", WEBAPP_URL)).then((res) => res.arrayBuffer());
const interFont = fetch(new URL("/fonts/Inter-Regular.ttf", WEBAPP_URL)).then((res) => res.arrayBuffer());
const interFontMedium = fetch(new URL("/fonts/Inter-Medium.ttf", WEBAPP_URL)).then((res) =>
res.arrayBuffer()
);
const interFont = fetch(new URL("../../../../public/fonts/Inter-Regular.ttf", import.meta.url)).then((res) =>
res.arrayBuffer()
);
const interFontMedium = fetch(new URL("../../../../public/fonts/Inter-Medium.ttf", import.meta.url)).then(
(res) => res.arrayBuffer()
);
export const config = {
runtime: "edge",
};
export const runtime = "edge";
const meetingSchema = z.object({
imageType: z.literal("meeting"),
@@ -43,7 +39,7 @@ const genericSchema = z.object({
description: z.string(),
});
export default async function handler(req: NextApiRequest) {
async function handler(req: NextRequest) {
const { searchParams } = new URL(`${req.url}`);
const imageType = searchParams.get("type");
@@ -118,3 +114,7 @@ export default async function handler(req: NextApiRequest) {
return new Response("What you're looking for is not here..", { status: 404 });
}
}
const getHandler = apiRouteMiddleware(handler);
export { getHandler as GET };