upd: user

Deskripsi:
- resize image user

create anggota dan edit anggota

No Issues
This commit is contained in:
amel
2025-01-22 15:48:47 +08:00
parent 4fb41bde46
commit 53b803d7ac
2 changed files with 36 additions and 4 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 ONE MEMBER / USER
export async function GET(request: Request, context: { params: { id: string } }) {
@@ -207,9 +208,24 @@ export async function PUT(request: Request, context: { params: { id: string } })
if (String(file) != "undefined" && String(file) != "null") {
const fExt = file.name.split(".").pop()
const fileName = 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(updates.img) })
const upload = await funUploadFile({ file: newFile, dirId: DIR.user })
const upload = await funUploadFile({ file: resizedFile, dirId: DIR.user })
await prisma.user.update({
where: {
id: id

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 ALL MEMBER / USER
export async function GET(request: Request) {
@@ -194,8 +195,23 @@ export async function POST(request: Request) {
const fExt = file.name.split(".").pop()
const fileName = user.id + '.' + fExt;
const newFile = new File([file], fileName, { type: file.type });
const upload = await funUploadFile({ file: newFile, dirId: DIR.user })
// 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 });
const upload = await funUploadFile({ file: resizedFile, dirId: DIR.user })
if (upload.success) {
await prisma.user.update({
where: {