diff --git a/src/app/(isr)/photos/[photoId]/image/route.tsx b/src/app/(isr)/photos/[photoId]/image/route.tsx index 45a8539a..986e67db 100644 --- a/src/app/(isr)/photos/[photoId]/image/route.tsx +++ b/src/app/(isr)/photos/[photoId]/image/route.tsx @@ -1,20 +1,19 @@ +import { getImageCacheHeadersForAuth } from '@/cache'; import PhotoOGImageResponse from '@/photo/image-response/PhotoOGImageResponse'; import { getPhoto } from '@/services/postgres'; import { IMAGE_OG_WIDTH, IMAGE_OG_HEIGHT } from '@/site'; import { FONT_FAMILY_IBM_PLEX_MONO, getIBMPlexMonoMedium } from '@/site/font'; import { ImageResponse } from '@vercel/og'; -const DEBUG_CACHING: boolean = false; - export const runtime = 'edge'; export async function GET(request: Request, context: any) { const photo = await getPhoto(context.params.photoId); + const fontData = await getIBMPlexMonoMedium(); + const headers = await getImageCacheHeadersForAuth(); if (!photo) { return null; } - const fontData = await getIBMPlexMonoMedium(); - return new ImageResponse( ( tags: [TAG_PHOTOS, tagForPhoto(...args)], } )(); + +export const getImageCacheHeadersForAuth = async () => { + const session = await auth(); + const shouldCacheRequest = !session?.user; + return { + 'Cache-Control': shouldCacheRequest + ? 's-maxage=3600, stale-while-revalidate' + : 's-maxage=1, stale-while-revalidate', + }; +};