From bfe4725537d026cd02749ae5583d2235df9bdfa3 Mon Sep 17 00:00:00 2001 From: Max Richter Date: Wed, 26 Jul 2023 15:55:00 +0200 Subject: [PATCH] feat: actually cache resized imaged --- routes/api/recipes/images/[image].ts | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) 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);