From fd4909bba7be8abc1eeab9ae1b4621c66a61604a Mon Sep 17 00:00:00 2001 From: joonhoekim <26rote@gmail.com> Date: Sun, 23 Nov 2025 16:40:37 +0900 Subject: (김준회) 돌체 재개발 - 1차 (다운로드 오류 수정 필요) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/dolce/download/route.ts | 43 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 app/api/dolce/download/route.ts (limited to 'app/api') diff --git a/app/api/dolce/download/route.ts b/app/api/dolce/download/route.ts new file mode 100644 index 00000000..9d5eb601 --- /dev/null +++ b/app/api/dolce/download/route.ts @@ -0,0 +1,43 @@ +import { NextRequest, NextResponse } from "next/server"; +import { downloadDolceFile } from "@/lib/dolce/actions"; + +export async function POST(request: NextRequest) { + try { + const body = await request.json(); + const { fileId, userId, fileName } = body; + + if (!fileId || !userId || !fileName) { + return NextResponse.json( + { error: "필수 파라미터가 누락되었습니다" }, + { status: 400 } + ); + } + + console.log("[DOLCE Download API] 요청:", { fileId, userId, fileName }); + + // DOLCE API를 통해 파일 다운로드 + const { blob, fileName: downloadFileName } = await downloadDolceFile({ + fileId, + userId, + fileName, + }); + + // ArrayBuffer로 변환하여 Response 생성 + const arrayBuffer = await blob.arrayBuffer(); + + return new NextResponse(arrayBuffer, { + headers: { + "Content-Type": "application/octet-stream", + "Content-Disposition": `attachment; filename*=UTF-8''${encodeURIComponent(downloadFileName)}`, + "Content-Length": arrayBuffer.byteLength.toString(), + }, + }); + } catch (error) { + console.error("파일 다운로드 API 오류:", error); + return NextResponse.json( + { error: error instanceof Error ? error.message : "파일 다운로드 중 오류가 발생했습니다" }, + { status: 500 } + ); + } +} + -- cgit v1.2.3