upd: edit profile
- Deskripsi: - resize image 300px No Issues
This commit is contained in:
@@ -53,6 +53,7 @@
|
|||||||
"readdirp": "^3.6.0",
|
"readdirp": "^3.6.0",
|
||||||
"recharts": "2",
|
"recharts": "2",
|
||||||
"rrule": "^2.8.1",
|
"rrule": "^2.8.1",
|
||||||
|
"sharp": "^0.33.5",
|
||||||
"supabase": "^1.192.5",
|
"supabase": "^1.192.5",
|
||||||
"web-push": "^3.6.7",
|
"web-push": "^3.6.7",
|
||||||
"wibu-cli": "^1.0.91",
|
"wibu-cli": "^1.0.91",
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import { funGetUserByCookies } from "@/module/auth";
|
|||||||
import { createLogUser } from "@/module/user";
|
import { createLogUser } from "@/module/user";
|
||||||
import _ from "lodash";
|
import _ from "lodash";
|
||||||
import { NextResponse } from "next/server";
|
import { NextResponse } from "next/server";
|
||||||
|
import sharp from "sharp";
|
||||||
|
|
||||||
|
|
||||||
// GET PROFILE BY COOKIES
|
// GET PROFILE BY COOKIES
|
||||||
@@ -119,9 +120,24 @@ export async function PUT(request: Request) {
|
|||||||
if (String(file) != "undefined" && String(file) != "null") {
|
if (String(file) != "undefined" && String(file) != "null") {
|
||||||
const fExt = file.name.split(".").pop()
|
const fExt = file.name.split(".").pop()
|
||||||
const fileName = user.id + '.' + fExt;
|
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) })
|
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) {
|
if (upload.success) {
|
||||||
await prisma.user.update({
|
await prisma.user.update({
|
||||||
where: {
|
where: {
|
||||||
|
|||||||
Reference in New Issue
Block a user