Improve admin distribution editing flow
Some checks failed
Build / release (macos-latest) (push) Has been cancelled
Build / release (ubuntu-latest) (push) Has been cancelled
Build / release (windows-latest) (push) Has been cancelled
Windows Smoke Test / windows-smoke (push) Has been cancelled

This commit is contained in:
2026-05-05 22:32:55 +09:00
parent 429a3d2284
commit 9e8fd9e74b
9 changed files with 147 additions and 19 deletions

View File

@@ -13,6 +13,7 @@ const RUNTIME_CATALOG_PATH = path.join(RUNTIME_DATA_DIR, 'catalog.json')
const LAUNCHER_CATALOG_PATH = path.join(PROJECT_ROOT, 'app', 'assets', 'launcher', 'catalog.json')
const PUBLIC_DIR = path.join(__dirname, 'public')
const SAMPLE_DISTRIBUTION_PATH = path.join(PROJECT_ROOT, 'docs', 'sample_distribution.json')
const EXAMPLE_DISTRIBUTION_PREFIX = 'https://example.com/launcher/'
function normalizeText(value){
return typeof value === 'string' ? value.trim() : ''
@@ -163,6 +164,53 @@ async function ensureRuntimeCatalog(){
await fs.writeJson(RUNTIME_CATALOG_PATH, { version: 1, profiles: [] }, { spaces: 2 })
}
}
await migrateExampleCatalog()
}
async function ensureLocalSampleDistribution(profileId, profileName){
const fileName = createDistributionFileName(profileId)
const targetPath = path.join(DISTRIBUTIONS_DIR, fileName)
if(!(await fs.pathExists(targetPath))){
const template = JSON.parse(await fs.readFile(SAMPLE_DISTRIBUTION_PATH, 'utf8'))
template.servers = [
{
id: profileId,
name: profileName || profileId,
description: '관리자 사이트 로컬 샘플 distribution입니다.',
version: '1.20.1',
minecraftVersion: '1.20.1',
mainServer: true,
autoconnect: false,
modules: []
}
]
await fs.writeFile(targetPath, JSON.stringify(template, null, 2) + '\n', 'utf8')
}
return toProjectRelativePath(targetPath)
}
async function migrateExampleCatalog(){
if(!(await fs.pathExists(RUNTIME_CATALOG_PATH))){
return
}
const runtimeCatalog = sanitizeCatalog(await fs.readJson(RUNTIME_CATALOG_PATH))
let changed = false
for(const profile of runtimeCatalog.profiles){
if(normalizeText(profile.distributionUrl).startsWith(EXAMPLE_DISTRIBUTION_PREFIX)){
profile.distributionUrl = await ensureLocalSampleDistribution(profile.id, profile.name)
changed = true
}
}
if(changed){
await fs.writeJson(RUNTIME_CATALOG_PATH, runtimeCatalog, { spaces: 2 })
await fs.writeJson(LAUNCHER_CATALOG_PATH, runtimeCatalog, { spaces: 2 })
}
}
async function readCatalog(){
@@ -248,9 +296,18 @@ async function start(){
}
if(/^https?:\/\//i.test(requestedPath)){
res.status(400).json({
ok: false,
message: '원격 URL은 사이트에서 직접 수정할 수 없습니다. 업로드하거나 새로 생성하세요.'
const response = await fetch(requestedPath, {
signal: AbortSignal.timeout(10000)
})
if(!response.ok){
throw new Error(`원격 distribution을 불러오지 못했습니다. (${response.status})`)
}
const content = await response.text()
JSON.parse(content)
res.json({
ok: true,
content
})
return
}