diff --git a/bun.lockb b/bun.lockb index 9bb5d6f..0b76528 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/package.json b/package.json index 35dedb1..86623f1 100644 --- a/package.json +++ b/package.json @@ -53,6 +53,7 @@ "readdirp": "^3.6.0", "recharts": "2", "rrule": "^2.8.1", + "sharp": "^0.33.5", "supabase": "^1.192.5", "web-push": "^3.6.7", "wibu-cli": "^1.0.91", diff --git a/src/app/api/user/profile/route.ts b/src/app/api/user/profile/route.ts index 4676f6e..3a27995 100644 --- a/src/app/api/user/profile/route.ts +++ b/src/app/api/user/profile/route.ts @@ -3,6 +3,7 @@ import { funGetUserByCookies } from "@/module/auth"; import { createLogUser } from "@/module/user"; import _ from "lodash"; import { NextResponse } from "next/server"; +import sharp from "sharp"; // GET PROFILE BY COOKIES @@ -119,9 +120,24 @@ export async function PUT(request: Request) { if (String(file) != "undefined" && String(file) != "null") { const fExt = file.name.split(".").pop() const fileName = user.id + '.' + fExt; - const newFile = new File([file], fileName, { type: file.type }); + + // Resize ukuran + const imageBuffer = await file.arrayBuffer(); + const resize = await sharp(imageBuffer).resize(300).toBuffer(); + + // Convert buffer ke Blob + const blob = new Blob([resize], { type: file.type }); + + // Convert Blob ke File + const resizedFile = new File([blob], fileName, { + type: file.type, + lastModified: new Date().getTime(), + }); + + // const newFile = new File([file], fileName, { type: file.type }); + await funDeleteFile({ fileId: String(update.img) }) - const upload = await funUploadFile({ file: newFile, dirId: DIR.user }) + const upload = await funUploadFile({ file: resizedFile, dirId: DIR.user }) if (upload.success) { await prisma.user.update({ where: {