From ae6f89bfff4a8a2441f3e30f4d7e7374e1c7a953 Mon Sep 17 00:00:00 2001 From: Rizky Date: Mon, 1 Apr 2024 16:41:59 +0700 Subject: [PATCH] wip fix --- pkgs/api/_img.ts | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/pkgs/api/_img.ts b/pkgs/api/_img.ts index 0b68f3c..93411b8 100644 --- a/pkgs/api/_img.ts +++ b/pkgs/api/_img.ts @@ -49,17 +49,16 @@ export const _ = { return new Response(original); } - let file_name = dir(`${g.datadir}/files/upload/thumb/${w}/${rpath}`); + let path = `${w ? `w-${w}` : ""}${h ? `h-${h}` : ``}`; + let file_name = dir( + `${g.datadir}/files/upload/thumb/${path}/${rpath}.webp` + ); let file = Bun.file(file_name); if (!(await file.exists())) { await dirAsync(dirname(file_name)); force = true; } - if (format === "jpg" && !file_name.endsWith(".jpg")) { - force = true; - } - if (force) { const img = sharp(await original.arrayBuffer()); const arg: any = { fit: "inside" }; @@ -69,12 +68,8 @@ export const _ = { if (h) { arg.width = h; } - let out = img.resize(arg); - - if (format === "jpg" && !file_name.endsWith(".jpg")) { - file_name = file_name + ".jpg"; - out = out.toFormat("jpg"); - } + let out = img.resize(arg).webp({ quality: 75 }); + out = out.webp(); await Bun.write(file_name, await out.toBuffer()); file = Bun.file(file_name);