summaryrefslogtreecommitdiff
path: root/components
diff options
context:
space:
mode:
authordujinkim <dujin.kim@dtsolution.co.kr>2025-09-01 09:12:09 +0000
committerdujinkim <dujin.kim@dtsolution.co.kr>2025-09-01 09:12:09 +0000
commit18954df6565108a469fb1608ea3715dd9bb1b02d (patch)
tree2675d254c547861a903a32459d89283a324e0e0d /components
parentf91cd16a872d9cda04aeb5c4e31538e3e2bd1895 (diff)
(대표님) 구매 기본계약, gtc 개발
Diffstat (limited to 'components')
-rw-r--r--components/ship-vendor-document-all/user-vendor-document-table-container.tsx57
-rw-r--r--components/ship-vendor-document/add-attachment-dialog.tsx8
-rw-r--r--components/ship-vendor-document/new-revision-dialog.tsx22
3 files changed, 60 insertions, 27 deletions
diff --git a/components/ship-vendor-document-all/user-vendor-document-table-container.tsx b/components/ship-vendor-document-all/user-vendor-document-table-container.tsx
index 157bdb03..3dcd12e0 100644
--- a/components/ship-vendor-document-all/user-vendor-document-table-container.tsx
+++ b/components/ship-vendor-document-all/user-vendor-document-table-container.tsx
@@ -36,6 +36,7 @@ import {
import { SimplifiedDocumentsView } from "@/db/schema"
import { WebViewerInstance } from "@pdftron/webviewer"
import { useRouter } from 'next/navigation'
+import { downloadFile } from "@/lib/file-download"
/* -------------------------------------------------------------------------------------------------
* Types & Constants
@@ -589,29 +590,49 @@ function SubTables() {
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}`)
+ // 파일 경로 처리
+ let downloadPath = attachment.filePath
+
+ // 공용 다운로드 함수 사용 (보안 검증, 파일 체크 모두 포함)
+ const result = await downloadFile(downloadPath, attachment.fileName, {
+ action: 'download',
+ showToast: true,
+ showSuccessToast: true,
+ })
- if (!response.ok) {
- const errorData = await response.json()
- throw new Error(errorData.error || 'Failed to download file.')
+ if (!result.success) {
+ throw new Error(result.error || 'Download failed')
}
- 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'}`)
+
+ // 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'}`)
+ }
}
}, [])
diff --git a/components/ship-vendor-document/add-attachment-dialog.tsx b/components/ship-vendor-document/add-attachment-dialog.tsx
index 61a078f7..1e9bfb51 100644
--- a/components/ship-vendor-document/add-attachment-dialog.tsx
+++ b/components/ship-vendor-document/add-attachment-dialog.tsx
@@ -75,10 +75,10 @@ const attachmentUploadSchema = z.object({
(files) => files.every((file) => file.size <= MAX_FILE_SIZE),
"File size must be 50MB or less"
)
- .refine(
- (files) => files.every((file) => ACCEPTED_FILE_TYPES.includes(file.type)),
- "Unsupported file format"
- ),
+ // .refine(
+ // (files) => files.every((file) => ACCEPTED_FILE_TYPES.includes(file.type)),
+ // "Unsupported file format"
+ // ),
})
interface AddAttachmentDialogProps {
diff --git a/components/ship-vendor-document/new-revision-dialog.tsx b/components/ship-vendor-document/new-revision-dialog.tsx
index 68c7a946..a1ddad13 100644
--- a/components/ship-vendor-document/new-revision-dialog.tsx
+++ b/components/ship-vendor-document/new-revision-dialog.tsx
@@ -62,11 +62,23 @@ const ACCEPTED_FILE_TYPES = [
'text/plain',
'application/zip',
'application/x-zip-compressed',
- // Presentations (added)
+ // Presentations
'application/vnd.ms-powerpoint', // .ppt
'application/vnd.openxmlformats-officedocument.presentationml.presentation', // .pptx
+ // CAD and Drawing files
+ 'application/acad', // .dwg
+ 'image/vnd.dwg', // .dwg (alternative MIME)
+ 'application/x-autocad', // .dwg (alternative MIME)
+ 'application/dxf', // .dxf
+ 'image/vnd.dxf', // .dxf (alternative MIME)
+ 'application/x-dxf', // .dxf (alternative MIME)
+ 'application/step', // .step/.stp
+ 'application/sla', // .stl
+ 'model/stl', // .stl (alternative MIME)
+ 'application/iges', // .iges/.igs
]
+
// drawingKind에 따른 동적 스키마 생성
const createRevisionUploadSchema = (drawingKind: string) => {
const baseSchema = {
@@ -80,10 +92,10 @@ const createRevisionUploadSchema = (drawingKind: string) => {
(files) => files.every((file) => file.size <= MAX_FILE_SIZE),
"File size must be 50MB or less"
)
- .refine(
- (files) => files.every((file) => ACCEPTED_FILE_TYPES.includes(file.type)),
- "Unsupported file format"
- ),
+ // .refine(
+ // (files) => files.every((file) => ACCEPTED_FILE_TYPES.includes(file.type)),
+ // "Unsupported file format"
+ // ),
}
// B3인 경우에만 usageType 필드 추가