upd: upload foto user

This commit is contained in:
amel
2024-09-12 10:55:56 +08:00
parent 6cd32ceb22
commit c23b94ff07
8 changed files with 65 additions and 91 deletions

View File

@@ -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);
}
}

View File

@@ -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: {} }
}
}