diff --git a/app/home-image/route.tsx b/app/home-image/route.tsx index b85df89a..fc74ad1b 100644 --- a/app/home-image/route.tsx +++ b/app/home-image/route.tsx @@ -7,7 +7,7 @@ import HomeImageResponse from '@/app/HomeImageResponse'; import { getIBMPlexMono } from '@/app/font'; import { getImageResponseCacheControlHeaders } from '@/image-response/cache'; import { APP_OG_IMAGE_QUERY_OPTIONS } from '@/feed'; -import { safePhotoImageResponse } from '@/platforms/safe-photo-image-response'; +import { ImageResponse } from 'next/og'; export const dynamic = 'force-static'; @@ -28,15 +28,13 @@ export async function GET() { const { width, height } = IMAGE_OG_DIMENSION_SMALL; - return safePhotoImageResponse( - photos, - isNextImageReady => ( - - ), { width, height, headers, fonts }, + return new ImageResponse( + , + { width, height, headers, fonts }, ); } diff --git a/app/p/[photoId]/image/route.tsx b/app/p/[photoId]/image/route.tsx index 516e9180..d1ff8575 100644 --- a/app/p/[photoId]/image/route.tsx +++ b/app/p/[photoId]/image/route.tsx @@ -4,7 +4,7 @@ import PhotoImageResponse from '@/photo/PhotoImageResponse'; import { getIBMPlexMono } from '@/app/font'; import { getImageResponseCacheControlHeaders } from '@/image-response/cache'; import { staticallyGeneratePhotosIfConfigured } from '@/app/static'; -import { safePhotoImageResponse } from '@/platforms/safe-photo-image-response'; +import { ImageResponse } from 'next/og'; export const generateStaticParams = staticallyGeneratePhotosIfConfigured( 'image', @@ -30,17 +30,13 @@ export async function GET( const { width, height } = IMAGE_OG_DIMENSION; - return safePhotoImageResponse( - [photo], - isNextImageReady => ( - - ), + return new ImageResponse( + , { width, height, fonts, headers }, ); } diff --git a/app/recents/image/route.tsx b/app/recents/image/route.tsx index e4fab8ef..9b4bb754 100644 --- a/app/recents/image/route.tsx +++ b/app/recents/image/route.tsx @@ -9,7 +9,7 @@ import { getIBMPlexMono } from '@/app/font'; import { getImageResponseCacheControlHeaders } from '@/image-response/cache'; import { getAppText } from '@/i18n/state/server'; import { SHOW_RECENTS } from '@/app/config'; -import { safePhotoImageResponse } from '@/platforms/safe-photo-image-response'; +import { ImageResponse } from 'next/og'; export const dynamic = 'force-static'; @@ -35,17 +35,14 @@ export async function GET() { const { width, height } = IMAGE_OG_DIMENSION_SMALL; - return safePhotoImageResponse( - photos, - isNextImageReady => ( - - ), + return new ImageResponse( + , { width, height, fonts, headers }, ); } diff --git a/app/template-image-tight/route.tsx b/app/template-image-tight/route.tsx index 007a8eeb..4a624cda 100644 --- a/app/template-image-tight/route.tsx +++ b/app/template-image-tight/route.tsx @@ -7,7 +7,7 @@ import TemplateImageResponse from '@/app/TemplateImageResponse'; import { getIBMPlexMono } from '@/app/font'; import { getImageResponseCacheControlHeaders } from '@/image-response/cache'; -import { safePhotoImageResponse } from '@/platforms/safe-photo-image-response'; +import { ImageResponse } from 'next/og'; export async function GET() { const [ @@ -25,23 +25,15 @@ export async function GET() { const { width, height } = IMAGE_OG_DIMENSION; - return safePhotoImageResponse( - photos, - isNextImageReady => ( - - ), - { + return new ImageResponse( + , + { width, height, fonts, headers }, ); } diff --git a/app/template-image/route.tsx b/app/template-image/route.tsx index 3c90537a..f5419fb5 100644 --- a/app/template-image/route.tsx +++ b/app/template-image/route.tsx @@ -7,7 +7,7 @@ import TemplateImageResponse from '@/app/TemplateImageResponse'; import { getIBMPlexMono } from '@/app/font'; import { getImageResponseCacheControlHeaders } from '@/image-response/cache'; -import { safePhotoImageResponse } from '@/platforms/safe-photo-image-response'; +import { ImageResponse } from 'next/og'; export async function GET() { const [ @@ -25,16 +25,13 @@ export async function GET() { const { width, height } = GRID_OG_DIMENSION; - return safePhotoImageResponse( - photos, - isNextImageReady => ( - - ), + return new ImageResponse( + , { width, height, fonts, headers }, ); } diff --git a/src/photo/PhotoImageResponse.tsx b/src/photo/PhotoImageResponse.tsx index 30be341b..83168bd1 100644 --- a/src/photo/PhotoImageResponse.tsx +++ b/src/photo/PhotoImageResponse.tsx @@ -12,13 +12,11 @@ export default function PhotoImageResponse({ width, height, fontFamily, - isNextImageReady = true, }: { photo: Photo width: NextImageSize height: number fontFamily: string - isNextImageReady: boolean }) { const caption = [ photo.model @@ -34,7 +32,7 @@ export default function PhotoImageResponse({ return ( => - photos.length > 0 && - fetch(getOptimizedPhotoUrl({ - imageUrl: photos[0].url, - size: 640, - addBypassSecret: IS_PREVIEW, - })) - .then(response => response.ok) - .catch(() => false); - -export const safePhotoImageResponse = async ( - photos: Photo[], - jsx: (isNextImageReady: boolean) => JSX.Element, - options: ConstructorParameters[1], - disableCheck = true, -) => { - // Make sure next/image can be reached from absolute urls, - // which may not exist on first pre-render - const isNextImageReady = ( - disableCheck || - await isNextImageReadyBasedOnPhotos(photos) - ); - - return new ImageResponse( - jsx(isNextImageReady), - options, - ); -};