Build music-quiz installer and management site per spec

Implements the full spec described in README.md:

Management site (Node + TypeScript + Express + EJS):
- Public main page lists packs registered in manifest.json.
- /op login (account.json, internal-only), /op/dashboard manages packs
  with horizontal-scroll cards, add/select-and-delete flow, and the
  /op/dashboard/:packName editor (Mojang release dropdown, dynamic
  mods/resourcepacks lists, platform/RAM fields, file rename).
- Routes for /manifest.json (public) and /file/* (server pack files).
- Middleware blocks /account.json and /manifest/* directory access.

Installer (Electron):
- Five page renderer driven by IPC (preload contextBridge API):
  pack pick → single/multi → server install (path no-Korean check, JDK
  detect, file download, EULA, RAM gating, local web config editor,
  UPnP/port-forward check) → client install (.mc_custom mods +
  resourcepacks + launcher_profiles.json gameDir/javaArgs) → finish
  toggles (server folder, shortcut, server start, launcher start).

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
2026-05-09 21:34:27 +09:00
parent 42a7cf3426
commit 8fd7cfaaef
32 changed files with 7817 additions and 0 deletions

163
src/server/routes/op.ts Normal file
View File

@@ -0,0 +1,163 @@
import { Router } from 'express'
import {
createPack,
deletePackKeys,
listPackKeys,
loadPackDefinition,
normalizePackDefinition,
readAccounts,
renamePack,
sanitizePackKey
} from '../../shared/store'
import { fetchReleaseVersions } from '../../shared/mojang'
import { requireAuth } from '../middleware/auth'
import type { PackDefinition } from '../../shared/types'
export const opRouter = Router()
function pickFirstValue(value: unknown): string {
if (Array.isArray(value)) return typeof value[0] === 'string' ? value[0] : ''
return typeof value === 'string' ? value : ''
}
function pickStringArray(value: unknown): string[] {
if (Array.isArray(value)) {
return value.filter((item): item is string => typeof item === 'string')
}
if (typeof value === 'string') return [value]
return []
}
opRouter.get('/op', (req, res) => {
if (req.session?.userId) {
res.redirect('/op/dashboard')
return
}
res.render('op/login', { error: null })
})
opRouter.post('/op', async (req, res, next) => {
try {
const id = pickFirstValue(req.body.id).trim()
const password = pickFirstValue(req.body.password)
const accounts = await readAccounts()
const matched = accounts.find((entry) => entry.id === id && entry.password === password)
if (!matched) {
res.status(401).render('op/login', { error: '아이디 또는 비밀번호가 올바르지 않습니다.' })
return
}
req.session.userId = matched.id
res.redirect('/op/dashboard')
} catch (error) {
next(error)
}
})
opRouter.post('/op/logout', (req, res) => {
req.session.destroy(() => {
res.redirect('/op')
})
})
opRouter.get('/op/dashboard', requireAuth, async (req, res, next) => {
try {
const keys = await listPackKeys()
const items = await Promise.all(keys.map(async (key) => ({
key,
definition: await loadPackDefinition(key)
})))
res.render('op/dashboard', {
userId: req.session.userId,
items
})
} catch (error) {
next(error)
}
})
opRouter.post('/op/dashboard/create', requireAuth, async (_req, res, next) => {
try {
const { key } = await createPack()
res.redirect(`/op/dashboard/${key}`)
} catch (error) {
next(error)
}
})
opRouter.post('/op/dashboard/delete', requireAuth, async (req, res, next) => {
try {
const keys = pickStringArray(req.body.targetKey)
.map((key) => sanitizePackKey(key))
.filter((key) => key.length > 0)
if (keys.length > 0) {
await deletePackKeys(keys)
}
res.redirect('/op/dashboard')
} catch (error) {
next(error)
}
})
opRouter.get('/op/dashboard/:packName', requireAuth, async (req, res, next) => {
try {
const packKey = sanitizePackKey(pickFirstValue(req.params.packName))
const definition = await loadPackDefinition(packKey)
if (!definition) {
res.status(404).send('해당 음악퀴즈를 찾을 수 없습니다.')
return
}
const releases = await fetchReleaseVersions()
res.render('op/editor', {
userId: req.session.userId,
packKey,
pack: definition,
releases
})
} catch (error) {
next(error)
}
})
opRouter.post('/op/dashboard/:packName', requireAuth, async (req, res, next) => {
try {
const packKey = sanitizePackKey(pickFirstValue(req.params.packName))
const requestedKey = sanitizePackKey(pickFirstValue(req.body.fileName)) || packKey
const modNames = pickStringArray(req.body['modName']).map((value) => value.trim())
const modUrls = pickStringArray(req.body['modUrl']).map((value) => value.trim())
const mods = modNames.map((name, index) => ({ name, downloadUrl: modUrls[index] ?? '' }))
const resourceNames = pickStringArray(req.body['resourceName']).map((value) => value.trim())
const resourceUrls = pickStringArray(req.body['resourceUrl']).map((value) => value.trim())
const resourcepacks = resourceNames.map((name, index) => ({ name, downloadUrl: resourceUrls[index] ?? '' }))
const platformType = pickFirstValue(req.body.platformType)
const platformDownloadUrl = pickFirstValue(req.body.platformDownloadUrl).trim()
const partial: Partial<PackDefinition> & Record<string, unknown> = {
name: pickFirstValue(req.body.displayName),
mcVersion: pickFirstValue(req.body.mcVersion),
platform: {
type: (platformType as PackDefinition['platform']['type']) || 'vanilla',
downloadUrl: platformDownloadUrl.length > 0 ? platformDownloadUrl : undefined
},
mods,
resourcepacks,
serverMinRam: Number(pickFirstValue(req.body.serverMinRam)),
serverMaxRam: Number(pickFirstValue(req.body.serverMaxRam)),
clientMinRam: Number(pickFirstValue(req.body.clientMinRam)),
clientRecommendedRam: Number(pickFirstValue(req.body.clientRecommendedRam)),
packPath: pickFirstValue(req.body.packPath)
}
const normalized = normalizePackDefinition(partial)
if (normalized.clientMinRam > normalized.clientRecommendedRam) {
res.status(400).send('clientMinRam은 clientRecommendedRam보다 클 수 없습니다.')
return
}
const finalKey = await renamePack(packKey, requestedKey, normalized)
res.redirect(`/op/dashboard/${finalKey}`)
} catch (error) {
next(error)
}
})