From e8a8ad56e58bdb8cde6e9a6bf79ba13398371b15 Mon Sep 17 00:00:00 2001 From: Rizky Date: Mon, 1 Apr 2024 16:46:54 +0700 Subject: [PATCH] wip fix --- pkgs/api/_img.ts | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/pkgs/api/_img.ts b/pkgs/api/_img.ts index 93411b8..98799c6 100644 --- a/pkgs/api/_img.ts +++ b/pkgs/api/_img.ts @@ -16,7 +16,7 @@ export const _ = { const w = parseInt(req.query_parameters.w); const h = parseInt(req.query_parameters.h); - const format = req.query_parameters.f; + const fit = req.query_parameters.fit; let force = typeof req.query_parameters.force === "string"; let rpath = decodeURIComponent(req.params._); @@ -49,7 +49,9 @@ export const _ = { return new Response(original); } - let path = `${w ? `w-${w}` : ""}${h ? `h-${h}` : ``}`; + let path = `${w ? `w-${w}` : ""}${h ? `h-${h}` : ``}${ + fit ? `-${fit}` : "" + }`; let file_name = dir( `${g.datadir}/files/upload/thumb/${path}/${rpath}.webp` ); @@ -61,12 +63,12 @@ export const _ = { if (force) { const img = sharp(await original.arrayBuffer()); - const arg: any = { fit: "inside" }; + const arg: any = { fit: fit || "inside" }; if (w) { arg.width = w; } if (h) { - arg.width = h; + arg.height = h; } let out = img.resize(arg).webp({ quality: 75 }); out = out.webp();