From 02062af723f1a3c2994c3e80148da47b07712713 Mon Sep 17 00:00:00 2001
From: joonhoekim <26rote@gmail.com>
Date: Mon, 27 Oct 2025 17:14:44 +0900
Subject: (김준회) SWP 다운로드, 업로드 api route 처리, 옥프로 컬럼 순서 조정
 처리, 환경변수 오타 수정
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 lib/swp/table/swp-table-columns.tsx | 66 ++++++++++++++++++-------------------
 1 file changed, 33 insertions(+), 33 deletions(-)

(limited to 'lib/swp/table/swp-table-columns.tsx')

diff --git a/lib/swp/table/swp-table-columns.tsx b/lib/swp/table/swp-table-columns.tsx
index 9954ab73..9aecea96 100644
--- a/lib/swp/table/swp-table-columns.tsx
+++ b/lib/swp/table/swp-table-columns.tsx
@@ -7,7 +7,6 @@ import { ChevronDown, ChevronRight, FileIcon, Download, Loader2 } from "lucide-r
 import { formatDistanceToNow } from "date-fns";
 import { ko } from "date-fns/locale";
 import type { SwpDocumentWithStats } from "../actions";
-import { downloadSwpFile } from "../actions";
 import { useState } from "react";
 import { toast } from "sonner";
 
@@ -28,6 +27,28 @@ export const swpDocumentColumns: ColumnDef<SwpDocumentWithStats>[] = [
     },
     size: 50,
   },
+  {
+    accessorKey: "LTST_ACTV_STAT",
+    header: "상태 (최신 액티비티)",
+    cell: ({ row }) => {
+      const status = row.original.LTST_ACTV_STAT;
+      if (!status) return "-";
+
+      // 상태에 따른 색상 설정 (필요에 따라 조정 가능)
+      const color =
+        status === "Complete" ? "bg-green-100 text-green-800" :
+        status === "In Progress" ? "bg-blue-100 text-blue-800" :
+        status === "Pending" ? "bg-yellow-100 text-yellow-800" :
+        "bg-gray-100 text-gray-800";
+
+      return (
+        <Badge variant="outline" className={color}>
+          {status}
+        </Badge>
+      );
+    },
+    size: 100,
+  },
   {
     accessorKey: "DOC_NO",
     header: "문서번호",
@@ -90,12 +111,12 @@ export const swpDocumentColumns: ColumnDef<SwpDocumentWithStats>[] = [
     cell: ({ row }) => {
       const stage = row.original.STAGE;
       if (!stage) return "-";
-      
-      const color = 
+
+      const color =
         stage === "IFC" ? "bg-green-100 text-green-800" :
         stage === "IFA" ? "bg-blue-100 text-blue-800" :
         "bg-gray-100 text-gray-800";
-      
+
       return (
         <Badge variant="outline" className={color}>
           {stage}
@@ -122,28 +143,6 @@ export const swpDocumentColumns: ColumnDef<SwpDocumentWithStats>[] = [
     ),
     size: 100,
   },
-  {
-    accessorKey: "LTST_ACTV_STAT",
-    header: "상태 (최신 액티비티)",
-    cell: ({ row }) => {
-      const status = row.original.LTST_ACTV_STAT;
-      if (!status) return "-";
-
-      // 상태에 따른 색상 설정 (필요에 따라 조정 가능)
-      const color =
-        status === "Complete" ? "bg-green-100 text-green-800" :
-        status === "In Progress" ? "bg-blue-100 text-blue-800" :
-        status === "Pending" ? "bg-yellow-100 text-yellow-800" :
-        "bg-gray-100 text-gray-800";
-
-      return (
-        <Badge variant="outline" className={color}>
-          {status}
-        </Badge>
-      );
-    },
-    size: 100,
-  },
   {
     accessorKey: "last_synced_at",
     header: "동기화",
@@ -399,26 +398,27 @@ function DownloadButton({ fileId, fileName }: DownloadButtonProps) {
     try {
       setIsDownloading(true);
       
-      // 서버 액션 호출
-      const result = await downloadSwpFile(fileId);
+      // API Route 호출 (바이너리 직접 전송)
+      const response = await fetch(`/api/swp/download/${fileId}`);
 
-      if (!result.success || !result.data) {
-        toast.error(result.error || "파일 다운로드 실패");
+      if (!response.ok) {
+        const errorData = await response.json().catch(() => ({ error: "다운로드 실패" }));
+        toast.error(errorData.error || "파일 다운로드 실패");
         return;
       }
 
       // Blob 생성 및 다운로드
-      const blob = new Blob([result.data as unknown as BlobPart], { type: result.mimeType });
+      const blob = await response.blob();
       const url = window.URL.createObjectURL(blob);
       const link = document.createElement("a");
       link.href = url;
-      link.download = result.fileName || fileName;
+      link.download = fileName;
       document.body.appendChild(link);
       link.click();
       document.body.removeChild(link);
       window.URL.revokeObjectURL(url);
 
-      toast.success(`파일 다운로드 완료: ${result.fileName}`);
+      toast.success(`파일 다운로드 완료: ${fileName}`);
     } catch (error) {
       console.error("다운로드 오류:", error);
       toast.error("파일 다운로드 중 오류가 발생했습니다.");
-- 
cgit v1.2.3

