summaryrefslogtreecommitdiff
path: root/components/ship-vendor-document
diff options
context:
space:
mode:
authordujinkim <dujin.kim@dtsolution.co.kr>2025-08-28 00:36:01 +0000
committerdujinkim <dujin.kim@dtsolution.co.kr>2025-08-28 00:36:01 +0000
commit92ad8a740bfefa8c7465c23e41208a7e36caa59d (patch)
tree8ab923a87ac0d0b6113d41199f5874431c7bc62e /components/ship-vendor-document
parent7548e2ad6948f1c6aa102fcac408bc6c9c0f9796 (diff)
(대표님) dolce 문서리스트 파일 다운로드 함수 문제 처리, 파일다운로드 use client 추가
Diffstat (limited to 'components/ship-vendor-document')
-rw-r--r--components/ship-vendor-document/user-vendor-document-table-container.tsx79
1 files changed, 50 insertions, 29 deletions
diff --git a/components/ship-vendor-document/user-vendor-document-table-container.tsx b/components/ship-vendor-document/user-vendor-document-table-container.tsx
index 9e45df6b..c9118cd0 100644
--- a/components/ship-vendor-document/user-vendor-document-table-container.tsx
+++ b/components/ship-vendor-document/user-vendor-document-table-container.tsx
@@ -39,6 +39,7 @@ import { NewRevisionDialog } from "./new-revision-dialog"
import { useRouter } from 'next/navigation'
import { AddAttachmentDialog } from "./add-attachment-dialog" // ✅ import 추가
import { EditRevisionDialog } from "./edit-revision-dialog" // ✅ 추가
+import { downloadFile } from "@/lib/file-download" // ✅ 공용 다운로드 함수 import
/* -------------------------------------------------------------------------------------------------
* Types & Constants
@@ -764,6 +765,55 @@ function SubTables() {
}
}, [allData, editingRevision, setAllData, selectedRevisionId, setSelectedRevisionId, router])
+ // ✅ 파일 다운로드 함수 - 공용함수 사용
+ const handleDownloadFile = React.useCallback(async (attachment: AttachmentInfo) => {
+ try {
+ // 파일 경로 처리
+ let downloadPath = attachment.filePath
+
+ // 공용 다운로드 함수 사용 (보안 검증, 파일 체크 모두 포함)
+ const result = await downloadFile(downloadPath, attachment.fileName, {
+ action: 'download',
+ showToast: true,
+ showSuccessToast: true,
+ })
+
+ if (!result.success) {
+ throw new Error(result.error || 'Download failed')
+ }
+
+ } catch (error) {
+ console.error('File download error:', error)
+
+ // fallback: API 엔드포인트를 통한 다운로드 시도
+ try {
+ const queryParam = attachment.id
+ ? `id=${encodeURIComponent(attachment.id)}`
+ : `path=${encodeURIComponent(attachment.filePath)}`
+
+ const response = await fetch(`/api/document-download?${queryParam}`)
+
+ if (!response.ok) {
+ const errorData = await response.json()
+ throw new Error(errorData.error || 'Failed to download file.')
+ }
+
+ const blob = await response.blob()
+ const url = window.URL.createObjectURL(blob)
+ const link = window.document.createElement('a')
+ link.href = url
+ link.download = attachment.fileName
+ window.document.body.appendChild(link)
+ link.click()
+ window.document.body.removeChild(link)
+ window.URL.revokeObjectURL(url)
+ } catch (fallbackError) {
+ console.error('Fallback download also failed:', fallbackError)
+ alert(`File download failed: ${fallbackError instanceof Error ? fallbackError.message : 'Unknown error'}`)
+ }
+ }
+ }, [])
+
// 파일 삭제 함수
const handleDeleteFile = React.useCallback(async (attachment: AttachmentInfo) => {
try {
@@ -980,35 +1030,6 @@ function SubTables() {
initialized.current = false
}, [])
- // 파일 다운로드 함수
- const handleDownloadFile = React.useCallback(async (attachment: AttachmentInfo) => {
- try {
- const queryParam = attachment.id
- ? `id=${encodeURIComponent(attachment.id)}`
- : `path=${encodeURIComponent(attachment.filePath)}`
-
- const response = await fetch(`/api/document-download?${queryParam}`)
-
- if (!response.ok) {
- const errorData = await response.json()
- throw new Error(errorData.error || 'Failed to download file.')
- }
-
- const blob = await response.blob()
- const url = window.URL.createObjectURL(blob)
- const link = window.document.createElement('a')
- link.href = url
- link.download = attachment.fileName
- window.document.body.appendChild(link)
- link.click()
- window.document.body.removeChild(link)
- window.URL.revokeObjectURL(url)
- } catch (error) {
- console.error('File download error:', error)
- alert(`File download failed: ${error instanceof Error ? error.message : 'Unknown error'}`)
- }
- }, [])
-
// WebViewer 초기화
React.useEffect(() => {
if (viewerOpen && !initialized.current) {