upd: edit profile

- Deskripsi:
- resize image 300px

No Issues
This commit is contained in:
amel
2025-01-22 14:52:38 +08:00
parent 9144951c50
commit 4fb41bde46
3 changed files with 19 additions and 2 deletions

View File

@@ -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: {