diff --git a/src/module/user/index.ts b/src/module/user/index.ts index ee5ef0f..3781d28 100644 --- a/src/module/user/index.ts +++ b/src/module/user/index.ts @@ -3,9 +3,11 @@ import createLogUser from "./log/fun/createLogUser"; import { funGetAllmember } from './member/lib/api_member'; import Profile from './profile/ui/profile'; import EditProfile from './profile/ui/edit_profile'; +import { fileUpload } from './profile/lib/upload_img_profile'; export { createLogUser }; export type { TypeUser } export { funGetAllmember } export { Profile } export { EditProfile } +export { fileUpload } diff --git a/src/module/user/profile/lib/get_dir.ts b/src/module/user/profile/lib/get_dir.ts new file mode 100644 index 0000000..84ddf88 --- /dev/null +++ b/src/module/user/profile/lib/get_dir.ts @@ -0,0 +1,21 @@ +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); + } +} \ No newline at end of file diff --git a/src/module/user/profile/lib/upload_img_profile.ts b/src/module/user/profile/lib/upload_img_profile.ts new file mode 100644 index 0000000..a49ab70 --- /dev/null +++ b/src/module/user/profile/lib/upload_img_profile.ts @@ -0,0 +1,27 @@ +export async function fileUpload({ file }: { file: File}) { + const formData = new FormData(); + formData.append("file", file); + formData.append("dirId", "cm0x8dbwn0005bp5tgmfcthzw"); + + try { + const res = await fetch("https://wibu-storage.wibudev.com/api/upload", { + method: "POST", + body: formData, + headers: { + Authorization: `Bearer ${process.env.WS_APIKEY}` + } + }); + + if (res.ok) { + console.log("File uploaded successfullyAmalia"); + const hasil = await res.text() + console.log('berhasilAmalia',hasil) + + } else { + const errorText = await res.text(); + console.log('errorAmalia',errorText) + } + } catch (error) { + console.error("Upload error:", error); + } +} \ No newline at end of file