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/[id]/route.ts b/src/app/api/user/[id]/route.ts index 24e6875..9cb622f 100644 --- a/src/app/api/user/[id]/route.ts +++ b/src/app/api/user/[id]/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 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 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: { diff --git a/src/app/api/user/route.ts b/src/app/api/user/route.ts index 420c818..526a4a7 100644 --- a/src/app/api/user/route.ts +++ b/src/app/api/user/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 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: { diff --git a/src/app/api/version-app/route.ts b/src/app/api/version-app/route.ts index 854c05f..524f12b 100644 --- a/src/app/api/version-app/route.ts +++ b/src/app/api/version-app/route.ts @@ -2,7 +2,7 @@ import { NextResponse } from "next/server"; export async function GET(request: Request) { try { - return NextResponse.json({ success: true, version: "1.1.2", tahap: "beta", update:"-pdf viewer new -jumlah anggota pada grid list divisi" }, { status: 200 }); + return NextResponse.json({ success: true, version: "1.1.4", tahap: "beta", update:"-resize profile image user (create anggota, edit anggota, edit profile) -menghilangkan image extensi heic" }, { status: 200 }); } catch (error) { console.error(error); return NextResponse.json({ success: false, version: "Gagal mendapatkan version, coba lagi nanti (error: 500)", reason: (error as Error).message, }, { status: 500 }); diff --git a/src/module/banner/ui/create_banner.tsx b/src/module/banner/ui/create_banner.tsx index 8331050..0364387 100644 --- a/src/module/banner/ui/create_banner.tsx +++ b/src/module/banner/ui/create_banner.tsx @@ -120,9 +120,9 @@ function CreateBanner() { }} activateOnClick={false} maxSize={10 * 1024 ** 2} - accept={['image/png', 'image/jpeg', 'image/heic']} + accept={['image/png', 'image/jpeg']} onReject={(files) => { - return toast.error('File yang diizinkan: .png, .jpg, dan .heic dengan ukuran maksimal 10 MB') + return toast.error('File yang diizinkan: .png dan .jpg dengan ukuran maksimal 10 MB') }} onClick={() => openRef.current?.()} > @@ -159,17 +159,17 @@ function CreateBanner() {
- + Klik Untuk Upload Image - Mohon unggah gambar dalam resolusi + Mohon unggah gambar dalam resolusi - 1535 x 450 piksel untuk memastikan + 1535 x 450 piksel untuk memastikan - tampilan sesuai dengan kebutuhan desain. + tampilan sesuai dengan kebutuhan desain.
@@ -177,15 +177,15 @@ function CreateBanner() { - - {touched.image && !imgForm && ( - - Silahkan Pilih Gambar - - )} - + + {touched.image && !imgForm && ( + + Silahkan Pilih Gambar + + )} + - { - return toast.error('File yang diizinkan: .png, .jpg, dan .heic dengan ukuran maksimal 10 MB') + return toast.error('File yang diizinkan: .png dan .jpg dengan ukuran maksimal 10 MB') }} onClick={() => openRef.current?.()} > diff --git a/src/module/document/ui/drawer_menu_document_division.tsx b/src/module/document/ui/drawer_menu_document_division.tsx index a1d67bf..40771dc 100644 --- a/src/module/document/ui/drawer_menu_document_division.tsx +++ b/src/module/document/ui/drawer_menu_document_division.tsx @@ -149,12 +149,12 @@ export default function DrawerMenuDocumentDivision() { }} activateOnClick={false} maxSize={100 * 1024 ** 2} - accept={['image/png', 'image/jpeg', 'image/heic', 'application/pdf', 'application/msword', 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', 'application/vnd.ms-excel', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet']} + accept={['image/png', 'image/jpeg', 'application/pdf', 'application/msword', 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', 'application/vnd.ms-excel', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet']} onReject={(files) => { refresh.set(true) setOpenModal(false) setOpenDrawerDocument(false) - toast.error('File yang diizinkan: .csv, .png, .jpg, .heic, .pdf, .doc, .docx, .xls, .xlsx dengan ukuran maksimal 100 MB') + toast.error('File yang diizinkan: .csv, .png, .jpg, .pdf, .doc, .docx, .xls, .xlsx dengan ukuran maksimal 100 MB') }} > openRef.current?.()}> diff --git a/src/module/project/ui/add_file_detail_project.tsx b/src/module/project/ui/add_file_detail_project.tsx index 71f3582..f557e4b 100644 --- a/src/module/project/ui/add_file_detail_project.tsx +++ b/src/module/project/ui/add_file_detail_project.tsx @@ -106,9 +106,9 @@ export default function AddFileDetailProject() { }} activateOnClick={false} maxSize={100 * 1024 ** 2} - accept={['image/png', 'image/jpeg', 'image/heic', 'application/pdf', 'application/msword', 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', 'application/vnd.ms-excel', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet']} + accept={['image/png', 'image/jpeg', 'application/pdf', 'application/msword', 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', 'application/vnd.ms-excel', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet']} onReject={(files) => { - return toast.error('File yang diizinkan: .csv, .png, .jpg, .heic, .pdf, .doc, .docx, .xls, .xlsx dengan ukuran maksimal 100 MB') + return toast.error('File yang diizinkan: .csv, .png, .jpg, .pdf, .doc, .docx, .xls, .xlsx dengan ukuran maksimal 100 MB') }} > diff --git a/src/module/project/ui/create_project.tsx b/src/module/project/ui/create_project.tsx index 97a2ef3..886a919 100644 --- a/src/module/project/ui/create_project.tsx +++ b/src/module/project/ui/create_project.tsx @@ -200,7 +200,7 @@ export default function CreateProject() { label="Grup" size="md" styles={{ - input: { + input: { border: `1px solid ${"#D6D8F6"}`, borderRadius: 10, }, @@ -413,9 +413,9 @@ export default function CreateProject() { }} activateOnClick={false} maxSize={100 * 1024 ** 2} - accept={['image/png', 'image/jpeg', 'image/heic', 'application/pdf', 'application/msword', 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', 'application/vnd.ms-excel', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet']} + accept={['image/png', 'image/jpeg', 'application/pdf', 'application/msword', 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', 'application/vnd.ms-excel', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet']} onReject={(files) => { - return toast.error('File yang diizinkan: .csv, .png, .jpg, .heic, .pdf, .doc, .docx, .xls, .xlsx dengan ukuran maksimal 100 MB') + return toast.error('File yang diizinkan: .csv, .png, .jpg, .pdf, .doc, .docx, .xls, .xlsx dengan ukuran maksimal 100 MB') }} > diff --git a/src/module/task/ui/add_file_detail_task.tsx b/src/module/task/ui/add_file_detail_task.tsx index 25183e3..f252803 100644 --- a/src/module/task/ui/add_file_detail_task.tsx +++ b/src/module/task/ui/add_file_detail_task.tsx @@ -107,9 +107,9 @@ export default function AddFileDetailTask() { }} activateOnClick={false} maxSize={100 * 1024 ** 2} - accept={['image/png', 'image/jpeg', 'image/heic', 'application/pdf', 'application/msword', 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', 'application/vnd.ms-excel', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet']} + accept={['image/png', 'image/jpeg', 'application/pdf', 'application/msword', 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', 'application/vnd.ms-excel', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet']} onReject={(files) => { - return toast.error('File yang diizinkan: .csv, .png, .jpg, .heic, .pdf, .doc, .docx, .xls, .xlsx dengan ukuran maksimal 100 MB') + return toast.error('File yang diizinkan: .csv, .png, .jpg, .pdf, .doc, .docx, .xls, .xlsx dengan ukuran maksimal 100 MB') }} > diff --git a/src/module/task/ui/create_task.tsx b/src/module/task/ui/create_task.tsx index 70f4c7a..d83564a 100644 --- a/src/module/task/ui/create_task.tsx +++ b/src/module/task/ui/create_task.tsx @@ -336,9 +336,9 @@ export default function CreateTask() { }} activateOnClick={false} maxSize={100 * 1024 ** 2} - accept={['image/png', 'image/jpeg', 'image/heic', 'application/pdf', 'application/msword', 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', 'application/vnd.ms-excel', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet']} + accept={['image/png', 'image/jpeg', 'application/pdf', 'application/msword', 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', 'application/vnd.ms-excel', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet']} onReject={(files) => { - return toast.error('File yang diizinkan: .csv, .png, .jpg, .heic, .pdf, .doc, .docx, .xls, .xlsx dengan ukuran maksimal 100 MB') + return toast.error('File yang diizinkan: .csv, .png, .jpg, .pdf, .doc, .docx, .xls, .xlsx dengan ukuran maksimal 100 MB') }} > diff --git a/src/module/user/member/ui/create_member.tsx b/src/module/user/member/ui/create_member.tsx index 7c78b48..64105d2 100644 --- a/src/module/user/member/ui/create_member.tsx +++ b/src/module/user/member/ui/create_member.tsx @@ -284,9 +284,9 @@ export default function CreateMember() { }} activateOnClick={false} maxSize={10 * 1024 ** 2} - accept={['image/png', 'image/jpeg', 'image/heic']} + accept={['image/png', 'image/jpeg']} onReject={(files) => { - return toast.error('File yang diizinkan: .png, .jpg, dan .heic dengan ukuran maksimal 10 MB') + return toast.error('File yang diizinkan: .png dan .jpg dengan ukuran maksimal 10 MB') }} > diff --git a/src/module/user/member/ui/edit_member.tsx b/src/module/user/member/ui/edit_member.tsx index d47b630..56b4599 100644 --- a/src/module/user/member/ui/edit_member.tsx +++ b/src/module/user/member/ui/edit_member.tsx @@ -216,9 +216,9 @@ export default function EditMember({ id }: { id: string }) { }} activateOnClick={false} maxSize={10 * 1024 ** 2} - accept={['image/png', 'image/jpeg', 'image/heic']} + accept={['image/png', 'image/jpeg']} onReject={(files) => { - return toast.error('File yang diizinkan: .png, .jpg, dan .heic dengan ukuran maksimal 10 MB') + return toast.error('File yang diizinkan: .png dan .jpg dengan ukuran maksimal 10 MB') }} > diff --git a/src/module/user/profile/ui/edit_profile.tsx b/src/module/user/profile/ui/edit_profile.tsx index e0e6750..9859221 100644 --- a/src/module/user/profile/ui/edit_profile.tsx +++ b/src/module/user/profile/ui/edit_profile.tsx @@ -179,10 +179,10 @@ export default function EditProfile() { }} activateOnClick={false} maxSize={10 * 1024 ** 2} - accept={["image/png", "image/jpeg", "image/heic"]} + accept={["image/png", "image/jpeg"]} onReject={(files) => { return toast.error( - "File yang diizinkan: .png, .jpg, dan .heic dengan ukuran maksimal 10 MB" + "File yang diizinkan: .png dan .jpg dengan ukuran maksimal 10 MB" ); }} >