diff --git a/backend/routes/api.js b/backend/routes/api.js index df9f445..9d2a8be 100644 --- a/backend/routes/api.js +++ b/backend/routes/api.js @@ -134,4 +134,27 @@ router.get("/modpacks", async (req, res) => { } }); +// 모드팩 다운로드 API (S3 리디렉션) +router.get("/modpacks/:id/download", async (req, res) => { + try { + const { id } = req.params; + + const [rows] = await dbPool.query(`SELECT * FROM modpacks WHERE id = ?`, [ + id, + ]); + if (rows.length === 0) { + return res.status(404).json({ error: "모드팩을 찾을 수 없습니다" }); + } + + const modpack = rows[0]; + const downloadUrl = `https://s3.caadiq.co.kr/minecraft/${modpack.file_key}`; + + // Content-Disposition 헤더로 파일명 지정하여 리디렉션 + res.redirect(downloadUrl); + } catch (error) { + console.error("[API] 모드팩 다운로드 실패:", error.message); + res.status(500).json({ error: "다운로드 실패" }); + } +}); + export default router;