Feature logs
Deskripsi: - Fitur baru log untuk melihat error pada server upload - Baru di terapkan di create profile
This commit is contained in:
@@ -1,24 +1,50 @@
|
||||
export async function funGlobal_DeleteFileById({ fileId }: { fileId: string }) {
|
||||
try {
|
||||
const res = await fetch(
|
||||
`https://wibu-storage.wibudev.com/api/files/${fileId}/delete`,
|
||||
{
|
||||
method: "DELETE",
|
||||
headers: {
|
||||
Authorization: `Bearer ${process.env.WS_APIKEY}`,
|
||||
},
|
||||
}
|
||||
);
|
||||
import { clientLogger } from "@/util/clientLogger";
|
||||
|
||||
if (res.ok) {
|
||||
const hasil = await res.json();
|
||||
return { success: true };
|
||||
export async function funGlobal_DeleteFileById({
|
||||
fileId,
|
||||
dirId,
|
||||
}: {
|
||||
fileId: string;
|
||||
dirId?: string;
|
||||
}) {
|
||||
try {
|
||||
const res = await fetch("/api/image/delete", {
|
||||
method: "DELETE",
|
||||
body: JSON.stringify({ fileId, dirId }),
|
||||
});
|
||||
|
||||
const data = await res.json();
|
||||
|
||||
if (data.success) {
|
||||
clientLogger.info(`File ${fileId} deleted successfully`);
|
||||
return { success: true, message: "File berhasil dihapus" };
|
||||
} else {
|
||||
const errorText = await res.json();
|
||||
return { success: false };
|
||||
return { success: false, message: data.message };
|
||||
}
|
||||
} catch (error) {
|
||||
return { success: false };
|
||||
console.error("Upload error:", error);
|
||||
return { success: false, message: "An unexpected error occurred" };
|
||||
}
|
||||
// try {
|
||||
// const res = await fetch(
|
||||
// `https://wibu-storage.wibudev.com/api/files/${fileId}/delete`,
|
||||
// {
|
||||
// method: "DELETE",
|
||||
// headers: {
|
||||
// Authorization: `Bearer ${process.env.WS_APIKEY}`,
|
||||
// },
|
||||
// }
|
||||
// );
|
||||
|
||||
// if (res.ok) {
|
||||
// const hasil = await res.json();
|
||||
// return { success: true, message: "File berhasil dihapus" };
|
||||
// } else {
|
||||
// const errorText = await res.json();
|
||||
// return { success: false, message: errorText.message };
|
||||
// }
|
||||
// } catch (error) {
|
||||
// console.error("Upload error:", error);
|
||||
// return { success: false, message: "An unexpected error occurred" };
|
||||
// }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user