feat: 모드팩 목록 조회 API 추가
- GET /api/modpacks: DB에서 모드팩 목록 조회 - contents_json을 파싱하여 contents 객체로 반환 - created_at DESC 정렬
This commit is contained in:
parent
e25faa498e
commit
b9dd596652
1 changed files with 25 additions and 1 deletions
|
|
@ -1,5 +1,5 @@
|
|||
import express from "express";
|
||||
import { getTranslations, getIcons, getGamerules } from "../lib/db.js";
|
||||
import { getTranslations, getIcons, getGamerules, dbPool } from "../lib/db.js";
|
||||
import { getIconUrl } from "../lib/icons.js";
|
||||
import {
|
||||
MOD_API_URL,
|
||||
|
|
@ -110,4 +110,28 @@ router.get("/worlds", async (req, res) => {
|
|||
}
|
||||
});
|
||||
|
||||
// 모드팩 목록 조회 API
|
||||
router.get("/modpacks", async (req, res) => {
|
||||
try {
|
||||
const [rows] = await dbPool.query(`
|
||||
SELECT id, name, version, minecraft_version, mod_loader, changelog,
|
||||
file_size, contents_json, created_at, updated_at
|
||||
FROM modpacks
|
||||
ORDER BY created_at DESC
|
||||
`);
|
||||
|
||||
// contents_json을 파싱하여 반환
|
||||
const modpacks = rows.map((row) => ({
|
||||
...row,
|
||||
contents: row.contents_json ? JSON.parse(row.contents_json) : null,
|
||||
contents_json: undefined, // 원본 JSON 문자열은 제거
|
||||
}));
|
||||
|
||||
res.json(modpacks);
|
||||
} catch (error) {
|
||||
console.error("[API] 모드팩 목록 조회 실패:", error.message);
|
||||
res.status(500).json({ error: "서버 오류" });
|
||||
}
|
||||
});
|
||||
|
||||
export default router;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue