diff --git a/routes/api/recipes/images/[image].ts b/routes/api/recipes/images/[image].ts index 69695d6..7e9c21b 100644 --- a/routes/api/recipes/images/[image].ts +++ b/routes/api/recipes/images/[image].ts @@ -109,17 +109,16 @@ export const handler = async ( return new Response(params, { status: 400 }); } + const imageId = `${imageUrl}.${params.width}.${params.height}`; + if (cache.has(imageId)) { + return (await cache.get(imageId)!).clone(); + } + const remoteImage = await getRemoteImage(imageUrl); if (typeof remoteImage === "string") { return new Response(remoteImage, { status: 400 }); } - const imageId = `${imageUrl}.${params.width}.${params.height}`; - - if (cache.has(imageId)) { - return (await cache.get(imageId)!).clone(); - } - const response = getImageResponse(imageUrl, remoteImage, params); cache.set(imageId, response);