Enable remote launcher catalog source
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:46:03 +09:00
parent 9e8fd9e74b
commit 87c56a21d5
11 changed files with 188 additions and 38 deletions

View File

@@ -6,6 +6,8 @@ const ConfigManager = require('./configmanager')
const { DEFAULT_REMOTE_DISTRO_URL, setRemoteDistributionUrl } = require('./distromanager')
const LOCAL_CATALOG_PATH = path.join(__dirname, '..', 'launcher', 'catalog.json')
const ROOT_ASSET_PATH = path.join(__dirname, '..', '..', '..')
const DEFAULT_REMOTE_CATALOG_URL = normalizeNullableText(process.env.LAUNCHER_CATALOG_URL) || 'http://127.0.0.1:8787/catalog.json'
function normalizeText(value){
return typeof value === 'string' ? value.trim() : ''
@@ -28,6 +30,14 @@ function normalizePositiveInteger(value, fallback, minimum = 1){
return fallback
}
function isRemoteSource(source){
return /^https?:\/\//i.test(source)
}
function isAbsoluteFileSystemPath(source){
return path.isAbsolute(source) || /^[a-zA-Z]:[\\/]/.test(source)
}
function deriveFeatureFlags(rawProfile){
const legacyKind = normalizeText(rawProfile?.kind)
@@ -77,7 +87,24 @@ function resolveLegacyServerJar(rawProfile){
return null
}
function toStoredProfile(rawProfile){
function resolveProfileSourceValue(value, catalogSource){
const nextValue = normalizeNullableText(value)
if(nextValue == null){
return null
}
if(isRemoteSource(nextValue) || nextValue.startsWith('file://') || isAbsoluteFileSystemPath(nextValue)){
return nextValue
}
if(isRemoteSource(catalogSource)){
return new URL(nextValue, catalogSource).toString()
}
return path.resolve(ROOT_ASSET_PATH, nextValue)
}
function toStoredProfile(rawProfile, catalogSource){
const flags = deriveFeatureFlags(rawProfile)
const storedProfile = {
id: normalizeText(rawProfile.id),
@@ -85,19 +112,19 @@ function toStoredProfile(rawProfile){
kind: deriveLegacyKind(flags),
description: normalizeText(rawProfile.description),
details: normalizeText(rawProfile.details),
distributionUrl: normalizeNullableText(rawProfile.distributionUrl),
distributionUrl: resolveProfileSourceValue(rawProfile.distributionUrl, catalogSource),
modsEnabled: flags.modsEnabled,
pluginsEnabled: flags.pluginsEnabled,
serverEnabled: flags.serverEnabled,
worldArchiveUrl: normalizeNullableText(rawProfile.worldArchiveUrl),
worldArchiveUrl: resolveProfileSourceValue(rawProfile.worldArchiveUrl, catalogSource),
worldDirectoryName: normalizeNullableText(rawProfile.worldDirectoryName),
serverJarUrl: resolveLegacyServerJar(rawProfile),
serverJarUrl: resolveProfileSourceValue(resolveLegacyServerJar(rawProfile), catalogSource),
serverDirectoryName: normalizeText(rawProfile.serverDirectoryName) || 'server',
serverPort: Number.isFinite(Number(rawProfile.serverPort)) ? Number(rawProfile.serverPort) : 25565,
serverMemoryMb: normalizePositiveInteger(rawProfile.serverMemoryMb, 4096, 512),
serverMaxPlayers: normalizePositiveInteger(rawProfile.serverMaxPlayers, 20, 1),
serverWhitelistEnabled: normalizeBoolean(rawProfile.serverWhitelistEnabled),
artwork: normalizeText(rawProfile.artwork)
artwork: resolveProfileSourceValue(rawProfile.artwork, catalogSource) ?? ''
}
if(!storedProfile.serverEnabled){
@@ -112,8 +139,8 @@ function toStoredProfile(rawProfile){
return storedProfile
}
function normalizeProfile(rawProfile, sourceType = 'catalog'){
const storedProfile = toStoredProfile(rawProfile)
function normalizeProfile(rawProfile, sourceType = 'catalog', catalogSource = LOCAL_CATALOG_PATH){
const storedProfile = toStoredProfile(rawProfile, catalogSource)
const launchIssues = []
const hostIssues = []
@@ -168,19 +195,39 @@ exports.getLocalCatalogPath = function(){
return LOCAL_CATALOG_PATH
}
exports.getDefaultRemoteCatalogUrl = function(){
return DEFAULT_REMOTE_CATALOG_URL
}
function buildCatalogSourceCandidates(configuredSource){
const trimmedSource = normalizeNullableText(configuredSource)
if(trimmedSource != null){
return [trimmedSource]
}
return [DEFAULT_REMOTE_CATALOG_URL, LOCAL_CATALOG_PATH]
}
exports.loadCatalog = async function(){
const configuredSource = ConfigManager.getLibraryCatalogSource()
const source = configuredSource != null && configuredSource.trim().length > 0 ? configuredSource.trim() : LOCAL_CATALOG_PATH
const sourceCandidates = buildCatalogSourceCandidates(configuredSource)
let rawCatalog = {
version: 1,
profiles: []
}
let sourceError = null
let source = sourceCandidates[sourceCandidates.length - 1]
try {
rawCatalog = await readCatalogSource(source)
} catch (error) {
sourceError = error
for(const candidate of sourceCandidates){
try {
rawCatalog = await readCatalogSource(candidate)
source = candidate
sourceError = null
break
} catch (error) {
source = candidate
sourceError = error
}
}
const rawProfiles = Array.isArray(rawCatalog.profiles) ? rawCatalog.profiles : []
@@ -191,7 +238,7 @@ exports.loadCatalog = async function(){
sourceError,
profiles: rawProfiles
.filter((profile) => profile != null && typeof profile.id === 'string' && typeof profile.name === 'string')
.map((profile) => normalizeProfile(profile, 'catalog'))
.map((profile) => normalizeProfile(profile, 'catalog', source))
.sort((left, right) => left.name.localeCompare(right.name, 'ko'))
}
}