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>
61 lines
1.7 KiB
TypeScript
61 lines
1.7 KiB
TypeScript
import https from 'node:https'
|
|
|
|
interface MojangVersionEntry {
|
|
id: string
|
|
type: string
|
|
}
|
|
|
|
interface MojangVersionManifest {
|
|
versions: MojangVersionEntry[]
|
|
}
|
|
|
|
const MANIFEST_URL = 'https://piston-meta.mojang.com/mc/game/version_manifest_v2.json'
|
|
|
|
let cachedReleases: string[] | null = null
|
|
let cachedAt = 0
|
|
const CACHE_TTL_MS = 60 * 60 * 1000
|
|
|
|
export async function fetchReleaseVersions(): Promise<string[]> {
|
|
if (cachedReleases && Date.now() - cachedAt < CACHE_TTL_MS) {
|
|
return cachedReleases
|
|
}
|
|
try {
|
|
const data = await fetchJson<MojangVersionManifest>(MANIFEST_URL)
|
|
const releases = data.versions.filter((entry) => entry.type === 'release').map((entry) => entry.id)
|
|
cachedReleases = releases
|
|
cachedAt = Date.now()
|
|
return releases
|
|
} catch {
|
|
return cachedReleases ?? FALLBACK_RELEASES
|
|
}
|
|
}
|
|
|
|
function fetchJson<T>(url: string): Promise<T> {
|
|
return new Promise((resolve, reject) => {
|
|
const request = https.get(url, { timeout: 8000 }, (response) => {
|
|
if (response.statusCode !== 200) {
|
|
response.resume()
|
|
reject(new Error(`Mojang manifest HTTP ${response.statusCode}`))
|
|
return
|
|
}
|
|
const chunks: Buffer[] = []
|
|
response.on('data', (chunk: Buffer) => chunks.push(chunk))
|
|
response.on('end', () => {
|
|
try {
|
|
resolve(JSON.parse(Buffer.concat(chunks).toString('utf8')) as T)
|
|
} catch (error) {
|
|
reject(error as Error)
|
|
}
|
|
})
|
|
})
|
|
request.on('error', reject)
|
|
request.on('timeout', () => {
|
|
request.destroy(new Error('Mojang manifest timeout'))
|
|
})
|
|
})
|
|
}
|
|
|
|
const FALLBACK_RELEASES = [
|
|
'1.21', '1.20.6', '1.20.4', '1.20.2', '1.20.1', '1.19.4', '1.19.2', '1.18.2', '1.17.1', '1.16.5'
|
|
]
|