From febd2ba39e2b0e4a23f80b3861e51b45b18358f1 Mon Sep 17 00:00:00 2001 From: log101 Date: Thu, 22 Feb 2024 16:51:26 +0300 Subject: [PATCH] feat: add astro sharp service --- src/pages/api/content/index.ts | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/pages/api/content/index.ts b/src/pages/api/content/index.ts index 39cedad..225f94f 100644 --- a/src/pages/api/content/index.ts +++ b/src/pages/api/content/index.ts @@ -2,6 +2,7 @@ import { createClient } from "@supabase/supabase-js" import type { APIRoute } from "astro" import { createKysely } from "@vercel/postgres-kysely" import { customAlphabet } from "nanoid" +import sharpService from "astro/assets/services/sharp" import type { Database } from "@/lib/db" @@ -39,7 +40,15 @@ export const POST: APIRoute = async ({ request }) => { const imageName = `${image.name.replace(/\.[^/.]+$/, "")}${randomImageId}.jpg` - const { error } = await supabase.storage.from("images").upload(`public/${imageName}`, image, { + const imageBuf = await image.arrayBuffer() + + const { data } = await sharpService.transform( + new Uint8Array(imageBuf), + { src: imageName }, + { domains: [], remotePatterns: [], service: { entrypoint: "", config: { limitInputPixels: false } } } + ) + + const { error } = await supabase.storage.from("images").upload(`public/${imageName}`, data, { cacheControl: "3600", upsert: false })