@@ -3,7 +3,7 @@ import type { NextRequest } from "next/server";
33import type { SatoriOptions } from "satori" ;
44import { z , ZodError } from "zod" ;
55
6- import { Meeting , App , Generic } from "@calcom/lib/OgImages" ;
6+ import { Meeting , App , Generic , getOGImageVersion } from "@calcom/lib/OgImages" ;
77import { WEBAPP_URL } from "@calcom/lib/constants" ;
88
99export const runtime = "edge" ;
@@ -22,6 +22,7 @@ const appSchema = z.object({
2222 name : z . string ( ) ,
2323 description : z . string ( ) ,
2424 slug : z . string ( ) ,
25+ logoUrl : z . string ( ) ,
2526} ) ;
2627
2728const genericSchema = z . object ( {
@@ -74,6 +75,7 @@ async function handler(req: NextRequest) {
7475 imageType,
7576 } ) ;
7677
78+ const etag = await getOGImageVersion ( "meeting" ) ;
7779 const img = new ImageResponse (
7880 (
7981 < Meeting
@@ -89,7 +91,9 @@ async function handler(req: NextRequest) {
8991 status : 200 ,
9092 headers : {
9193 "Content-Type" : "image/png" ,
92- "Cache-Control" : "public, max-age=3600, stale-while-revalidate=86400" ,
94+ "Cache-Control" :
95+ "public, max-age=31536000, immutable, s-maxage=31536000, stale-while-revalidate=31536000" ,
96+ ETag : `"${ etag } "` ,
9397 } ,
9498 } ) ;
9599 } catch ( error ) {
@@ -111,19 +115,32 @@ async function handler(req: NextRequest) {
111115 }
112116 case "app" : {
113117 try {
114- const { name, description, slug } = appSchema . parse ( {
118+ const { name, description, slug, logoUrl } = appSchema . parse ( {
115119 name : searchParams . get ( "name" ) ,
116120 description : searchParams . get ( "description" ) ,
117121 slug : searchParams . get ( "slug" ) ,
122+ logoUrl : searchParams . get ( "logoUrl" ) ,
118123 imageType,
119124 } ) ;
120- const img = new ImageResponse ( < App name = { name } description = { description } slug = { slug } /> , ogConfig ) ;
125+
126+ // Get SVG hash for the app
127+ const svgHashesModule = await import ( "@calcom/web/public/app-store/svg-hashes.json" ) ;
128+ const SVG_HASHES = svgHashesModule . default ?? { } ;
129+ const svgHash = SVG_HASHES [ slug ] ?? undefined ;
130+
131+ const etag = await getOGImageVersion ( "app" , { svgHash } ) ;
132+ const img = new ImageResponse (
133+ < App name = { name } description = { description } slug = { slug } logoUrl = { logoUrl } /> ,
134+ ogConfig
135+ ) ;
121136
122137 return new Response ( img . body , {
123138 status : 200 ,
124139 headers : {
125140 "Content-Type" : "image/png" ,
126- "Cache-Control" : "public, max-age=3600, stale-while-revalidate=86400" ,
141+ "Cache-Control" :
142+ "public, max-age=31536000, immutable, s-maxage=31536000, stale-while-revalidate=31536000" ,
143+ ETag : `"${ etag } "` ,
127144 } ,
128145 } ) ;
129146 } catch ( error ) {
@@ -151,13 +168,16 @@ async function handler(req: NextRequest) {
151168 imageType,
152169 } ) ;
153170
171+ const etag = await getOGImageVersion ( "generic" ) ;
154172 const img = new ImageResponse ( < Generic title = { title } description = { description } /> , ogConfig ) ;
155173
156174 return new Response ( img . body , {
157175 status : 200 ,
158176 headers : {
159177 "Content-Type" : "image/png" ,
160- "Cache-Control" : "public, max-age=3600, stale-while-revalidate=86400" ,
178+ "Cache-Control" :
179+ "public, max-age=31536000, immutable, s-maxage=31536000, stale-while-revalidate=31536000" ,
180+ ETag : `"${ etag } "` ,
161181 } ,
162182 } ) ;
163183 } catch ( error ) {
@@ -178,9 +198,9 @@ async function handler(req: NextRequest) {
178198 }
179199
180200 default :
181- return new Response ( "What you're looking for is not here.. " , { status : 404 } ) ;
201+ return new Response ( "Wrong image type " , { status : 404 } ) ;
182202 }
183- } catch ( error ) {
203+ } catch {
184204 return new Response ( "Internal server error" , { status : 500 } ) ;
185205 }
186206}
0 commit comments