diff options
Diffstat (limited to 'lib/tech-vendors/service.ts')
| -rw-r--r-- | lib/tech-vendors/service.ts | 37 |
1 files changed, 6 insertions, 31 deletions
diff --git a/lib/tech-vendors/service.ts b/lib/tech-vendors/service.ts index e8dcb5dc..c5926e8e 100644 --- a/lib/tech-vendors/service.ts +++ b/lib/tech-vendors/service.ts @@ -1171,43 +1171,18 @@ export async function getTechVendorDetailById(id: number) { export async function downloadTechVendorAttachments(vendorId:number, fileId?:number) { try { // API 경로 생성 (단일 파일 또는 모든 파일) - const url = fileId + const path = fileId ? `/api/tech-vendors/attachments/download?id=${fileId}&vendorId=${vendorId}` : `/api/tech-vendors/attachments/download-all?vendorId=${vendorId}`; - // fetch 요청 (기본적으로 Blob으로 응답 받기) - const response = await fetch(url, { - method: 'GET', - headers: { - 'Content-Type': 'application/json', - }, - }); - - if (!response.ok) { - throw new Error(`Server responded with ${response.status}: ${response.statusText}`); - } - - // 파일명 가져오기 (Content-Disposition 헤더에서) - const contentDisposition = response.headers.get('content-disposition'); - let fileName = fileId ? `file-${fileId}.zip` : `tech-vendor-${vendorId}-files.zip`; - - if (contentDisposition) { - const matches = /filename[^;=\n]*=((['"]).*?\2|[^;\n]*)/.exec(contentDisposition); - if (matches && matches[1]) { - fileName = matches[1].replace(/['"]/g, ''); - } - } - - // Blob으로 응답 변환 - const blob = await response.blob(); - - // Blob URL 생성 - const blobUrl = window.URL.createObjectURL(blob); + // 서버에서는 URL만 반환하고, 클라이언트에서 실제 다운로드 처리 + // 파일명도 기본값으로 설정 + const fileName = fileId ? `file-${fileId}.zip` : `tech-vendor-${vendorId}-attachments.zip`; return { - url: blobUrl, + url: path, // 상대 경로 반환 fileName, - blob + isServerAction: true // 서버 액션임을 표시 }; } catch (error) { console.error('Download API error:', error); |
