/** * πŸ“„ File Delete Utility * 파일 μ‚­μ œ μœ ν‹Έλ¦¬ν‹° * * - 첨뢀 파일 μ‚­μ œ κΈ°λŠ₯ (단일 파일 지원) * - μΏ ν‚€ 기반 인증 토큰 관리 및 μ‚¬μš©μž 쑰회 * - Axios 기반 HTTP μš”μ²­ 처리 * - νƒ€μž… μ•ˆμ „μ„± 보μž₯을 μœ„ν•œ μΈν„°νŽ˜μ΄μŠ€ ν™œμš© * - μ—λŸ¬ 핸듀링 및 응닡 처리 ν‘œμ€€ν™” * - 파일 μ‚­μ œ μ§„ν–‰ μƒνƒœ 콜백 지원 * * πŸ”— μ‚¬μš© API * - μ²¨λΆ€νŒŒμΌ μ‚­μ œλ° Soft Delete μ‚­μ œ(μ²¨λΆ€νŒŒμΌμ½”λ“œλ‘œ μ‚­μ œ): DELETE /api/v1/atfl/attachments/atflCd/{atflCd} (attach-service) */ import { getCookie } from "@/shared/lib"; import { ENDPOINT } from "../api/attachment/attachment-service"; const AUTH_USER_ID = process.env.NEXT_PUBLIC_AUTH_USER_ID || "token-id"; const CLAIM_NAME = process.env.NEXT_PUBLIC_CLAIM_NAME || "Authorization"; type DeleteOptions = { handleDeleteStart?: () => void; handleDeleteSuccess?: (response: Response) => void; handleDeleteError?: (error: Error) => void; }; export const handleDelete = async ( atflCd: string, options?: DeleteOptions ): Promise => { if (!atflCd) { const error = new Error("μ²¨λΆ€νŒŒμΌ μ½”λ“œκ°€ ν•„μš”ν•©λ‹ˆλ‹€."); options?.handleDeleteError?.(error); throw error; } try { options?.handleDeleteStart?.(); const response = await fetch( `${ENDPOINT.ATTACH_SERVICE.DELETE_FILE_BY_ATFLCD}/${atflCd}`, { method: "DELETE", headers: { "Content-Type": "application/json", [CLAIM_NAME]: getCookie(CLAIM_NAME) ?? "", [AUTH_USER_ID]: getCookie(AUTH_USER_ID) ?? "", }, } ); if (!response.ok) { throw new Error(`파일 μ‚­μ œ μ‹€νŒ¨: ${response.status} ${response.statusText}`); } options?.handleDeleteSuccess?.(response); } catch (error) { const deleteError = error instanceof Error ? error : new Error("파일 μ‚­μ œ 쀑 μ•Œ 수 μ—†λŠ” 였λ₯˜κ°€ λ°œμƒν–ˆμŠ΅λ‹ˆλ‹€."); console.error("파일 μ‚­μ œ 였λ₯˜:", deleteError); options?.handleDeleteError?.(deleteError); throw deleteError; } }; // μ—¬λŸ¬ νŒŒμΌμ„ μ‚­μ œν•˜λŠ” ν•¨μˆ˜ // export const handleMultipleDelete = async ( // atflCds: string[], // options?: DeleteOptions & { // handleProgress?: (completed: number, total: number) => void; // } // ): Promise => { // if (!atflCds || atflCds.length === 0) { // const error = new Error("μ‚­μ œν•  파일이 μ—†μŠ΅λ‹ˆλ‹€."); // options?.handleDeleteError?.(error); // throw error; // } // try { // options?.handleDeleteStart?.(); // const deletePromises = atflCds.map(async (atflCd, index) => { // try { // await handleDelete(atflCd); // options?.handleProgress?.(index + 1, atflCds.length); // return { success: true, atflCd }; // } catch (error) { // return { success: false, atflCd, error }; // } // }); // const results = await Promise.allSettled(deletePromises); // const failedDeletes = results // .filter((result): result is PromiseFulfilledResult<{ success: false; atflCd: string; error: any }> => // result.status === 'fulfilled' && !result.value.success // ) // .map(result => result.value); // if (failedDeletes.length > 0) { // const error = new Error( // `일뢀 파일 μ‚­μ œ μ‹€νŒ¨: ${failedDeletes.map(f => f.atflCd).join(', ')}` // ); // options?.handleDeleteError?.(error); // throw error; // } // options?.handleDeleteSuccess?.(new Response()); // } catch (error) { // const deleteError = error instanceof Error // ? error // : new Error("파일 μ‚­μ œ 쀑 μ•Œ 수 μ—†λŠ” 였λ₯˜κ°€ λ°œμƒν–ˆμŠ΅λ‹ˆλ‹€."); // console.error("파일 μ‚­μ œ 였λ₯˜:", deleteError); // options?.handleDeleteError?.(deleteError); // throw deleteError; // } // };