upd: upload foto user
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { funDeleteFile, funUploadFile, prisma } from "@/module/_global";
|
||||
import { DIR, funDeleteFile, funUploadFile, prisma } from "@/module/_global";
|
||||
import { funGetUserByCookies } from "@/module/auth";
|
||||
import _ from "lodash";
|
||||
import { NextResponse } from "next/server";
|
||||
@@ -119,34 +119,21 @@ 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 fileName = 'COBAAYAA.' + fExt;
|
||||
const fileName = user.id + '.' + fExt;
|
||||
const newFile = new File([file], fileName, { type: file.type });
|
||||
console.log(fileName, newFile.name)
|
||||
await funDeleteFile({ name: fileName, dirId: "cm0x8dbwn0005bp5tgmfcthzw" })
|
||||
await funUploadFile({ file: newFile, dirId: "cm0x8dbwn0005bp5tgmfcthzw" })
|
||||
await funDeleteFile({ fileId: String(update.img) })
|
||||
const upload = await funUploadFile({ file: newFile, dirId: DIR.user })
|
||||
if (upload.success) {
|
||||
await prisma.user.update({
|
||||
where: {
|
||||
id: user.id
|
||||
},
|
||||
data: {
|
||||
img: upload.data.id
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
// fs.unlink(`./public/image/user/${update.img}`, (err) => { })
|
||||
// const root = path.join(process.cwd(), "./public/image/user/");
|
||||
// const fExt = file.name.split(".").pop()
|
||||
// const fileName = user.id + '.' + fExt;
|
||||
// const filePath = path.join(root, fileName);
|
||||
|
||||
// // Konversi ArrayBuffer ke Buffer
|
||||
// const buffer = Buffer.from(await file.arrayBuffer());
|
||||
|
||||
// // Tulis file ke sistem
|
||||
// fs.writeFileSync(filePath, buffer);
|
||||
|
||||
// await prisma.user.update({
|
||||
// where: {
|
||||
// id: user.id
|
||||
// },
|
||||
// data: {
|
||||
// img: fileName
|
||||
// }
|
||||
// })
|
||||
}
|
||||
|
||||
const log = await createLogUser({ act: 'UPDATE', desc: 'User mengupdate data profile', table: 'user', data: user.id })
|
||||
|
||||
@@ -1,4 +1,12 @@
|
||||
import { hookstate } from "@hookstate/core"
|
||||
|
||||
export const pwd_key_config = "fchgvjknlmdfnbvghhujlaknsdvjbhknlkmsdbdyu567t8y9u30r4587638y9uipkoeghjvuyi89ipkoefmnrjbhtiu4or9ipkoemnjfbhjiuoijdklnjhbviufojkejnshbiuojijknehgruyu"
|
||||
export const globalRole = hookstate<string>('')
|
||||
export const globalRole = hookstate<string>('')
|
||||
export const DIR = {
|
||||
task: "cm0xhcqf0000dacbbixjb09yn",
|
||||
project: "cm0xhc9sv000bacbb7rfikw1k",
|
||||
document: "cm0xhbkf50009acbbtw03qo4l",
|
||||
village: "cm0xhb91o0007acbbkx8rk8hj",
|
||||
user: "cm0x8dbwn0005bp5tgmfcthzw",
|
||||
|
||||
}
|
||||
@@ -1,22 +1,21 @@
|
||||
export async function funDeleteFile({ name, dirId }: { name: String, dirId: string }) {
|
||||
export async function funDeleteFile({ fileId }: { fileId: string }) {
|
||||
try {
|
||||
const res = await fetch(`https://wibu-storage.wibudev.com/api/dir/${dirId}/${name}`, {
|
||||
method: "GET",
|
||||
const res = await fetch(`https://wibu-storage.wibudev.com/api/files/${fileId}/delete`, {
|
||||
method: "DELETE",
|
||||
headers: {
|
||||
Authorization: `Bearer eyJhbGciOiJIUzI1NiJ9.eyJ1c2VyIjp7ImlkIjoiY20wdnQ4bzFrMDAwMDEyenE1eXl1emd5YiIsIm5hbWUiOiJhbWFsaWEiLCJlbWFpbCI6ImFtYWxpYUBiaXAuY29tIiwiQXBpS2V5IjpbeyJpZCI6ImNtMHZ0OG8xcjAwMDIxMnpxZDVzejd3eTgiLCJuYW1lIjoiZGVmYXVsdCJ9XX0sImlhdCI6MTcyNTkzNTE5MiwiZXhwIjo0ODgxNjk1MTkyfQ.7U-HUnNBDmeq_6XXohiFZjFnh2rSzUPMHDdrUKOd7G4`
|
||||
Authorization: `Bearer ${process.env.WS_APIKEY}`
|
||||
}
|
||||
});
|
||||
|
||||
if (res.ok) {
|
||||
console.log("Berhasil dapat");
|
||||
const hasil = await res.json()
|
||||
console.log('berhasilAmalia', hasil)
|
||||
|
||||
return { success: true }
|
||||
} else {
|
||||
const errorText = await res.json();
|
||||
console.log('errorAmalia', errorText)
|
||||
return { success: false }
|
||||
}
|
||||
} catch (error) {
|
||||
return { success: false }
|
||||
console.error("Upload error:", error);
|
||||
}
|
||||
}
|
||||
@@ -13,12 +13,14 @@ export async function funUploadFile({ file, dirId }: { file: File, dirId: string
|
||||
});
|
||||
|
||||
if (res.ok) {
|
||||
console.log("File uploaded successfully");
|
||||
const hasil = await res.json()
|
||||
return { success: true, data: hasil.data }
|
||||
} else {
|
||||
const errorText = await res.text();
|
||||
console.log('errorAmalia', errorText)
|
||||
return { success: false, data: {} }
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Upload error:", error);
|
||||
return { success: false, data: {} }
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
import prisma from "./bin/prisma";
|
||||
import { globalRole, pwd_key_config } from "./bin/val_global";
|
||||
import { DIR, globalRole, pwd_key_config } from "./bin/val_global";
|
||||
import SkeletonDetailDiscussionComment from "./components/skeleton_detail_discussion_comment";
|
||||
import SkeletonDetailDiscussionMember from "./components/skeleton_detail_discussion_member";
|
||||
import SkeletonDetailListTugasTask from "./components/skeleton_detail_list_tugas_task";
|
||||
@@ -40,3 +40,4 @@ export { WrapLayout }
|
||||
export { NoZoom }
|
||||
export { funUploadFile }
|
||||
export { funDeleteFile }
|
||||
export { DIR }
|
||||
|
||||
@@ -1,21 +0,0 @@
|
||||
export async function getListDir() {
|
||||
try {
|
||||
const res = await fetch("https://wibu-storage.wibudev.com/api/dir/cm0x8a1as0001bp5te7354yrp/list", {
|
||||
method: "GET",
|
||||
headers: {
|
||||
Authorization: `Bearer eyJhbGciOiJIUzI1NiJ9.eyJ1c2VyIjp7ImlkIjoiY20wdnQ4bzFrMDAwMDEyenE1eXl1emd5YiIsIm5hbWUiOiJhbWFsaWEiLCJlbWFpbCI6ImFtYWxpYUBiaXAuY29tIiwiQXBpS2V5IjpbeyJpZCI6ImNtMHZ0OG8xcjAwMDIxMnpxZDVzejd3eTgiLCJuYW1lIjoiZGVmYXVsdCJ9XX0sImlhdCI6MTcyNTkzNTE5MiwiZXhwIjo0ODgxNjk1MTkyfQ.7U-HUnNBDmeq_6XXohiFZjFnh2rSzUPMHDdrUKOd7G4`
|
||||
}
|
||||
});
|
||||
|
||||
if (res.ok) {
|
||||
const hasil = await res.json()
|
||||
console.log("File uploaded successfully");
|
||||
console.log(hasil)
|
||||
} else {
|
||||
const errorText = await res.text();
|
||||
console.log(errorText)
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Upload error:", error);
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
"use client"
|
||||
import { LayoutNavbarNew, WARNA } from "@/module/_global";
|
||||
import { DIR, LayoutNavbarNew, WARNA } from "@/module/_global";
|
||||
import { Avatar, Box, Button, Flex, Indicator, Modal, rem, Select, Skeleton, Stack, Text, TextInput } from "@mantine/core";
|
||||
import toast from "react-hot-toast";
|
||||
import LayoutModal from "@/module/_global/layout/layout_modal";
|
||||
@@ -45,7 +45,7 @@ export default function EditProfile() {
|
||||
setLoading(true)
|
||||
const res = await funGetProfileByCookies()
|
||||
setData(res.data)
|
||||
setIMG(`/api/file/img?jenis=image&cat=user&file=${res.data.img}`)
|
||||
setIMG(`https://wibu-storage.wibudev.com/api/files/${res.data.img}`)
|
||||
setLoading(false)
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
@@ -258,31 +258,31 @@ export default function EditProfile() {
|
||||
zIndex: 999,
|
||||
backgroundColor: `${WARNA.bgWhite}`,
|
||||
}}>
|
||||
{loading ?
|
||||
<Skeleton height={50} radius={30} />
|
||||
{loading ?
|
||||
<Skeleton height={50} radius={30} />
|
||||
:
|
||||
<Button
|
||||
c={"white"}
|
||||
bg={WARNA.biruTua}
|
||||
size="md"
|
||||
radius={30}
|
||||
fullWidth
|
||||
onClick={() => {
|
||||
if (
|
||||
data.nik !== "" &&
|
||||
data.name !== "" &&
|
||||
data.email !== "" &&
|
||||
data.phone !== "" &&
|
||||
data.gender !== ""
|
||||
) {
|
||||
setValModal(true)
|
||||
} else {
|
||||
toast.error("Mohon lengkapi semua form");
|
||||
}
|
||||
}}
|
||||
>
|
||||
Simpan
|
||||
</Button>
|
||||
<Button
|
||||
c={"white"}
|
||||
bg={WARNA.biruTua}
|
||||
size="md"
|
||||
radius={30}
|
||||
fullWidth
|
||||
onClick={() => {
|
||||
if (
|
||||
data.nik !== "" &&
|
||||
data.name !== "" &&
|
||||
data.email !== "" &&
|
||||
data.phone !== "" &&
|
||||
data.gender !== ""
|
||||
) {
|
||||
setValModal(true)
|
||||
} else {
|
||||
toast.error("Mohon lengkapi semua form");
|
||||
}
|
||||
}}
|
||||
>
|
||||
Simpan
|
||||
</Button>
|
||||
}
|
||||
</Box>
|
||||
<LayoutModal opened={isValModal} onClose={() => setValModal(false)}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
"use client"
|
||||
import { LayoutIconBack, LayoutNavbarHome, SkeletonDetailProfile, WARNA } from "@/module/_global";
|
||||
import { ActionIcon, Anchor, Avatar, Box, Button, Flex, Grid, Group, SimpleGrid, Skeleton, Stack, Text } from "@mantine/core";
|
||||
import { HiUser } from "react-icons/hi2";
|
||||
import { DIR, LayoutIconBack, LayoutNavbarHome, SkeletonDetailProfile, WARNA } from "@/module/_global";
|
||||
import { ActionIcon, Avatar, Box, Grid, Group, Skeleton, Stack, Text } from "@mantine/core";
|
||||
import { RiIdCardFill } from "react-icons/ri";
|
||||
import { FaSquarePhone } from "react-icons/fa6";
|
||||
import { MdEmail } from "react-icons/md";
|
||||
@@ -27,8 +26,7 @@ export default function Profile() {
|
||||
setLoading(true)
|
||||
const res = await funGetProfileByCookies()
|
||||
setData(res.data)
|
||||
setIMG(`/api/file/img?jenis=image&cat=user&file=${res.data.img}`)
|
||||
// setIMG(`https://wibu-storage.wibudev.com/api/files/view/cm0x8dbwn0005bp5tgmfcthzw/${res.data.img}`)
|
||||
setIMG(`https://wibu-storage.wibudev.com/api/files/${res.data.img}`)
|
||||
setLoading(false)
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
|
||||
Reference in New Issue
Block a user