summaryrefslogtreecommitdiff
path: root/app/api/tech-sales-rfqs
diff options
context:
space:
mode:
authordujinkim <dujin.kim@dtsolution.co.kr>2025-07-21 07:54:26 +0000
committerdujinkim <dujin.kim@dtsolution.co.kr>2025-07-21 07:54:26 +0000
commit14f61e24947fb92dd71ec0a7196a6e815f8e66da (patch)
tree317c501d64662d05914330628f867467fba78132 /app/api/tech-sales-rfqs
parent194bd4bd7e6144d5c09c5e3f5476d254234dce72 (diff)
(최겸)기술영업 RFQ 담당자 초대, 요구사항 반영
Diffstat (limited to 'app/api/tech-sales-rfqs')
-rw-r--r--app/api/tech-sales-rfqs/[rfqId]/vendors/[vendorId]/comments/route.ts32
1 files changed, 17 insertions, 15 deletions
diff --git a/app/api/tech-sales-rfqs/[rfqId]/vendors/[vendorId]/comments/route.ts b/app/api/tech-sales-rfqs/[rfqId]/vendors/[vendorId]/comments/route.ts
index e6bf2b93..ac17766f 100644
--- a/app/api/tech-sales-rfqs/[rfqId]/vendors/[vendorId]/comments/route.ts
+++ b/app/api/tech-sales-rfqs/[rfqId]/vendors/[vendorId]/comments/route.ts
@@ -8,10 +8,7 @@ import { techSalesRfqComments, techSalesRfqCommentAttachments, users } from "@/d
import { revalidateTag } from "next/cache"
import { eq, and } from "drizzle-orm"
-// 파일 저장을 위한 유틸리티
-import { writeFile, mkdir } from 'fs/promises'
-import { join } from 'path'
-import crypto from 'crypto'
+// 파일 저장을 위한 유틸리티는 이제 saveFile 함수를 사용
/**
* 코멘트 조회 API 엔드포인트
@@ -74,6 +71,7 @@ export async function GET(
.select({
id: techSalesRfqCommentAttachments.id,
fileName: techSalesRfqCommentAttachments.fileName,
+ originalFileName: techSalesRfqCommentAttachments.originalFileName,
fileSize: techSalesRfqCommentAttachments.fileSize,
fileType: techSalesRfqCommentAttachments.fileType,
filePath: techSalesRfqCommentAttachments.filePath,
@@ -185,18 +183,20 @@ export async function POST(
if (files.length > 0) {
console.log("첨부파일 처리 시작:", files.length);
- // 디렉토리 생성
- const uploadDir = join(process.cwd(), "public", `tech-sales-rfq-${rfqId}`, `vendor-${vendorId}`, `comment-${comment.id}`)
- await mkdir(uploadDir, { recursive: true })
+ // saveFile 함수 import
+ const { saveFile } = await import('@/lib/file-stroage')
// 각 파일 저장
for (const file of files) {
- const buffer = Buffer.from(await file.arrayBuffer())
- const filename = `${Date.now()}-${crypto.randomBytes(8).toString("hex")}-${file.name.replace(/[^a-zA-Z0-9.-]/g, "_")}`
- const filePath = join(uploadDir, filename)
-
- // 파일 쓰기
- await writeFile(filePath, buffer)
+ const saveResult = await saveFile({
+ file,
+ directory: `tech-sales-rfq-${rfqId}/vendor-${vendorId}/comment-${comment.id}`,
+ originalName: file.name
+ })
+
+ if (!saveResult.success) {
+ throw new Error(saveResult.error || '파일 저장에 실패했습니다.')
+ }
// DB에 첨부파일 정보 저장
const [attachment] = await db
@@ -204,10 +204,11 @@ export async function POST(
.values({
rfqId,
commentId: comment.id,
- fileName: file.name,
+ fileName: saveResult.fileName!, // 해시된 파일명 (저장용)
+ originalFileName: saveResult.originalName!, // 원본 파일명 (표시용)
fileSize: file.size,
fileType: file.type,
- filePath: `/tech-sales-rfq-${rfqId}/vendor-${vendorId}/comment-${comment.id}/${filename}`,
+ filePath: saveResult.publicPath!,
isVendorUpload: isVendorComment,
uploadedBy: parseInt(session.user.id),
vendorId,
@@ -218,6 +219,7 @@ export async function POST(
attachments.push({
id: attachment.id,
fileName: attachment.fileName,
+ originalFileName: attachment.originalFileName,
fileSize: attachment.fileSize,
fileType: attachment.fileType,
filePath: attachment.filePath,