@@ -20,6 +20,7 @@ const PUPPETEER_EXECUTABLE_PATH = process.env.PUPPETEER_EXECUTABLE_PATH;
2020const OG_IMAGE_VALIDITY_PERIOD = revalidate * 1000 ;
2121const PUPPETEER_ARGS = process . env . PUPPETEER_ARGS || "" ;
2222const API_SLUG_PATTERN = / ^ \/ a p i \/ o g - i m a g e ( (?: \/ [ . \w - ] + ) * ) / ;
23+ const IMAGE_GENERATION_ENABLED = false ;
2324
2425const imageGenerationPromises = new Map < string , Promise < NextResponse > > ( ) ;
2526
@@ -189,14 +190,19 @@ const routeHandler: CustomMiddleware<[{ params: Promise<{ slug: string[] }> }]>
189190 console . info ( "Returning existing promise for" , slug ) ;
190191 return await result . previousPromise ;
191192 case "not-found" :
192- return tryGenerateScreenshot ( slug , payload ) ;
193+ if ( IMAGE_GENERATION_ENABLED ) {
194+ return tryGenerateScreenshot ( slug , payload ) ;
195+ }
196+ // If image generation is disabled, return a 404
193197 case "image-invalid" :
194198 console . error ( "OG image record has no URL" , slug ) ;
195199 return NextResponse . json ( { message : "Image not found" } , { status : 404 } ) ;
196200 case "image-stale" :
197- // Update the image in the background but return the stale image
198- console . info ( "Updating stale OG image for" , slug , "from" , result . image . updatedAt ) ;
199- tryGenerateScreenshot ( slug , payload , result . image ) ;
201+ if ( IMAGE_GENERATION_ENABLED ) {
202+ // Update the image in the background but return the stale image
203+ console . info ( "Updating stale OG image for" , slug , "from" , result . image . updatedAt ) ;
204+ tryGenerateScreenshot ( slug , payload , result . image ) ;
205+ }
200206 // Fall through to redirect (deliberately omitted 'break')
201207 case "image-valid" :
202208 return NextResponse . redirect ( result . redirectUrl ) ;
0 commit comments