upd: user
Deskripsi: - resize image user create anggota dan edit anggota No Issues
This commit is contained in:
@@ -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 ONE MEMBER / USER
|
// GET ONE MEMBER / USER
|
||||||
export async function GET(request: Request, context: { params: { id: string } }) {
|
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") {
|
if (String(file) != "undefined" && String(file) != "null") {
|
||||||
const fExt = file.name.split(".").pop()
|
const fExt = file.name.split(".").pop()
|
||||||
const fileName = id + '.' + fExt;
|
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) })
|
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({
|
await prisma.user.update({
|
||||||
where: {
|
where: {
|
||||||
id: id
|
id: id
|
||||||
|
|||||||
@@ -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 ALL MEMBER / USER
|
// GET ALL MEMBER / USER
|
||||||
export async function GET(request: Request) {
|
export async function GET(request: Request) {
|
||||||
@@ -194,8 +195,23 @@ export async function POST(request: Request) {
|
|||||||
|
|
||||||
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 });
|
|
||||||
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) {
|
if (upload.success) {
|
||||||
await prisma.user.update({
|
await prisma.user.update({
|
||||||
where: {
|
where: {
|
||||||
|
|||||||
Reference in New Issue
Block a user