From d9b85151c35af7f666d38a4c1a66df5c42317746 Mon Sep 17 00:00:00 2001 From: YangJinSoo94 Date: Fri, 20 Jun 2025 14:41:50 +0900 Subject: [PATCH] =?UTF-8?q?-=20=ED=8E=98=EC=9D=B4=EC=A7=95=20=EC=B2=98?= =?UTF-8?q?=EB=A6=AC=EB=A5=BC=20=EC=9C=84=ED=95=9C=20getFetchWithCount=20f?= =?UTF-8?q?unction=20=EC=B6=94=EA=B0=80=20(return=20res)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/wr/components/lib/api/index.ts | 42 +++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/apps/wr/components/lib/api/index.ts b/apps/wr/components/lib/api/index.ts index ad0ab4729..452788eb0 100644 --- a/apps/wr/components/lib/api/index.ts +++ b/apps/wr/components/lib/api/index.ts @@ -46,6 +46,48 @@ export const getFetch = async (type: string, url: string) => { } }; +export const getFetchWithCount = async (type: string, url: string) => { + const div = + type === fetchType.COMMON + ? DEV_URL_FO + : type === fetchType.LOCAL + ? LOCAL_URL + : type === fetchType.CS + ? '' + : DEV_URL_WR; + + const response = await fetch(div + url, { + method: "GET", + headers: { + accept: "application/json", + }, + }); + + if (!response.ok) { + console.log(`오류 발생: ${response.status}`); + } + const contentType = response.headers.get("content-type") ?? ""; + + if (contentType.includes("application/json")) { + // JSON 응답 처리 + const res = await response.json(); + return res; + } else { + // 파일 응답 처리 (ex. PDF, Excel 등) + const blob = await response.blob(); + const blobUrl = window.URL.createObjectURL(blob); + const a = document.createElement("a"); + const filename = "downloaded_file.PDF"; + + a.href = blobUrl; + a.download = filename; + a.click(); + window.URL.revokeObjectURL(blobUrl); + + return null; // 다운로드이므로 반환값 없음 + } +}; + export const postFectch = async (url: string, params: any, type?: string) => { const div = type === fetchType.COMMON ? DEV_URL_FO : DEV_URL_WR;