Fix investasi

Deksripsi:
- Fix notifikasi
This commit is contained in:
2024-12-23 07:51:35 +08:00
parent b1d7a565e7
commit 1fac36336c
19 changed files with 1145 additions and 719 deletions

View File

@@ -1,5 +1,7 @@
import { funGlobal_DeleteFileById } from "./delete/fun_delete_file_by_id";
import { funGlobal_UploadToStorage } from "./upload/fun_upload_to_storage";
import { funValidasiUploadCreatedFile } from "./upload/fun_validasi_upload_created_file";
export { funGlobal_UploadToStorage };
export { funGlobal_DeleteFileById };
export { funValidasiUploadCreatedFile };

View File

@@ -0,0 +1,106 @@
import { clientLogger } from "@/util/clientLogger";
import { MAX_SIZE } from "../../lib";
import { PemberitahuanMaksimalFile } from "../../lib/max_size";
import { ComponentGlobal_NotifikasiPeringatan } from "../../notif_global";
import { funGlobal_DeleteFileById } from "../delete/fun_delete_file_by_id";
import { funGlobal_UploadToStorage } from "./fun_upload_to_storage";
export async function funValidasiUploadCreatedFile({
files,
dirId,
fileId,
onSetFileId,
onSetImageBuffer,
}: {
files: any | null;
dirId: string;
fileId: string;
onSetFileId: (val: string) => void;
onSetImageBuffer: (val: any | null) => void;
}) {
try {
const buffer = URL.createObjectURL(
new Blob([new Uint8Array(await files.arrayBuffer())])
);
if (files.size > MAX_SIZE) {
ComponentGlobal_NotifikasiPeringatan(PemberitahuanMaksimalFile);
onSetImageBuffer(null);
return false;
}
if (fileId != "") {
const deleteFotoProfile = await funGlobal_DeleteFileById({
fileId: fileId,
dirId: dirId,
});
if (!deleteFotoProfile.success) {
console.log(
`Client failed delete ${dirId}:` + deleteFotoProfile.message
);
onSetImageBuffer(null);
return false;
}
if (deleteFotoProfile.success) {
onSetFileId("");
onSetImageBuffer(null);
const uploadPhoto = await funGlobal_UploadToStorage({
file: files,
dirId: dirId,
});
if (!uploadPhoto.success) {
clientLogger.error(
`Client failed upload ${dirId}:` + uploadPhoto.message
);
return false;
}
if (uploadPhoto.success) {
clientLogger.info(`Client success upload ${dirId}`);
onSetFileId("");
onSetImageBuffer(buffer);
return true;
} else {
clientLogger.error("Client failed upload foto:", uploadPhoto.message);
ComponentGlobal_NotifikasiPeringatan(`Gagal upload ${dirId}`);
}
}
} else {
const uploadPhoto = await funGlobal_UploadToStorage({
file: files,
dirId: dirId,
});
if (!uploadPhoto.success) {
clientLogger.error(
`Client failed upload ${dirId}:` + uploadPhoto.message
);
return false;
}
if (uploadPhoto.success) {
clientLogger.info(`Client success upload ${dirId}`);
onSetFileId("");
onSetImageBuffer(buffer);
return true;
} else {
clientLogger.error("Client failed upload foto:", uploadPhoto.message);
ComponentGlobal_NotifikasiPeringatan(`Gagal upload ${dirId}`);
return false;
}
}
} catch (error) {
console.log(error);
return false;
}
}