summaryrefslogtreecommitdiff
path: root/app/api
diff options
context:
space:
mode:
Diffstat (limited to 'app/api')
-rw-r--r--app/api/upload/rfq-attachment-revision/route.ts67
-rw-r--r--app/api/upload/rfq-attachment/route.ts66
2 files changed, 133 insertions, 0 deletions
diff --git a/app/api/upload/rfq-attachment-revision/route.ts b/app/api/upload/rfq-attachment-revision/route.ts
new file mode 100644
index 00000000..a7dd4117
--- /dev/null
+++ b/app/api/upload/rfq-attachment-revision/route.ts
@@ -0,0 +1,67 @@
+import { NextRequest, NextResponse } from "next/server"
+import { writeFile, mkdir } from "fs/promises"
+import { existsSync } from "fs"
+import path from "path"
+
+export async function POST(request: NextRequest) {
+ try {
+ const formData = await request.formData()
+ const attachmentId = formData.get("attachmentId") as string
+ const file = formData.get("file") as File
+ const isRevision = formData.get("isRevision") as string
+
+ if (!attachmentId) {
+ return NextResponse.json(
+ { message: "첨부파일 ID가 필요합니다." },
+ { status: 400 }
+ )
+ }
+
+ if (!file) {
+ return NextResponse.json(
+ { message: "파일이 선택되지 않았습니다." },
+ { status: 400 }
+ )
+ }
+
+ // 파일 크기 검증
+ if (file.size > 10 * 1024 * 1024) { // 10MB
+ return NextResponse.json(
+ { message: `파일이 너무 큽니다. (최대 10MB)` },
+ { status: 400 }
+ )
+ }
+
+ // 업로드 디렉토리 생성 (첨부파일 ID별)
+ const uploadDir = path.join(process.cwd(), "public", "uploads", "rfq", "revisions", attachmentId)
+ if (!existsSync(uploadDir)) {
+ await mkdir(uploadDir, { recursive: true })
+ }
+
+ // 고유한 파일명 생성 (리비전용)
+ const timestamp = Date.now()
+ const sanitizedName = file.name.replace(/[^a-zA-Z0-9.-]/g, "_")
+ const fileName = `${timestamp}_${sanitizedName}`
+ const filePath = `/uploads/rfq/revisions/${attachmentId}/${fileName}`
+ const fullPath = path.join(uploadDir, fileName)
+
+ // 파일 저장
+ const buffer = Buffer.from(await file.arrayBuffer())
+ await writeFile(fullPath, buffer)
+
+ return NextResponse.json({
+ fileName,
+ originalFileName: file.name,
+ filePath,
+ fileSize: file.size,
+ fileType: file.type || path.extname(file.name).slice(1),
+ })
+
+ } catch (error) {
+ console.error("File upload error:", error)
+ return NextResponse.json(
+ { message: "파일 업로드 중 오류가 발생했습니다." },
+ { status: 500 }
+ )
+ }
+} \ No newline at end of file
diff --git a/app/api/upload/rfq-attachment/route.ts b/app/api/upload/rfq-attachment/route.ts
new file mode 100644
index 00000000..306919fb
--- /dev/null
+++ b/app/api/upload/rfq-attachment/route.ts
@@ -0,0 +1,66 @@
+import { NextRequest, NextResponse } from "next/server"
+import { writeFile, mkdir } from "fs/promises"
+import { existsSync } from "fs"
+import path from "path"
+
+export async function POST(request: NextRequest) {
+ try {
+ const formData = await request.formData()
+ const rfqId = formData.get("rfqId") as string
+ const file = formData.get("file") as File
+
+ if (!rfqId) {
+ return NextResponse.json(
+ { message: "RFQ ID가 필요합니다." },
+ { status: 400 }
+ )
+ }
+
+ if (!file) {
+ return NextResponse.json(
+ { message: "파일이 선택되지 않았습니다." },
+ { status: 400 }
+ )
+ }
+
+ // 파일 크기 검증
+ if (file.size > 10 * 1024 * 1024) { // 10MB
+ return NextResponse.json(
+ { message: `파일이 너무 큽니다. (최대 10MB)` },
+ { status: 400 }
+ )
+ }
+
+ // 업로드 디렉토리 생성
+ const uploadDir = path.join(process.cwd(), "public", "uploads", "rfq", rfqId)
+ if (!existsSync(uploadDir)) {
+ await mkdir(uploadDir, { recursive: true })
+ }
+
+ // 고유한 파일명 생성 (타임스탬프 + 원본명)
+ const timestamp = Date.now()
+ const sanitizedName = file.name.replace(/[^a-zA-Z0-9.-]/g, "_")
+ const fileName = `${timestamp}_${sanitizedName}`
+ const filePath = `/uploads/rfq/${rfqId}/${fileName}`
+ const fullPath = path.join(uploadDir, fileName)
+
+ // 파일 저장
+ const buffer = Buffer.from(await file.arrayBuffer())
+ await writeFile(fullPath, buffer)
+
+ return NextResponse.json({
+ fileName,
+ originalFileName: file.name,
+ filePath,
+ fileSize: file.size,
+ fileType: file.type || path.extname(file.name).slice(1),
+ })
+
+ } catch (error) {
+ console.error("File upload error:", error)
+ return NextResponse.json(
+ { message: "파일 업로드 중 오류가 발생했습니다." },
+ { status: 500 }
+ )
+ }
+} \ No newline at end of file