From 5ea8551d604d8b7debc92798cb886000ad0e0d3f Mon Sep 17 00:00:00 2001 From: Gabriel20xx Date: Sun, 6 Sep 2026 21:59:45 +0200 Subject: [PATCH] Fix stale MediaServant project entry surviving the CarrierNode rename The configured_central/main rename to CarrierNode only ran when both lists were still empty, so an already-populated list kept the old MediaServant entry and gained a duplicate CarrierNode one. Also migrate the per-project JSON blobs (labels, login, mounts, tab meta) keyed by the old name so their data isn't orphaned. Co-Authored-By: Claude Sonnet 5 --- .../src/lib/features/ConfigWorkspace.svelte | 64 ++++++++++++------- 1 file changed, 41 insertions(+), 23 deletions(-) diff --git a/shared/webui/src/lib/features/ConfigWorkspace.svelte b/shared/webui/src/lib/features/ConfigWorkspace.svelte index ce03aff..83b2561 100644 --- a/shared/webui/src/lib/features/ConfigWorkspace.svelte +++ b/shared/webui/src/lib/features/ConfigWorkspace.svelte @@ -647,27 +647,51 @@ // MediaServant -> CarrierNode, and the old flat configured_projects list (which mixed // MediaConfig/MediaServant in with every other project) split into configured_central / // configured_main. + const LEGACY_RENAMES: [string, string][] = [ + ['mediaconfig', 'projectconfigurator'], + ['mediaservant', 'carriernode'], + ] + const LEGACY_RENAME_LABELS: Record = { + projectconfigurator: 'ProjectConfigurator', + carriernode: 'CarrierNode', + } + + // Renames a project name that may still carry a pre-rename base (e.g. "MediaServant" or + // "MediaServant_2"), regardless of whether it lives in a fresh configured_central/main list or + // the old flat configured_projects one - both can still hold the stale name. + function migrateLegacyProjectName(project: string): string { + const base = getBaseProject(project) + const to = LEGACY_RENAMES.find(([from]) => projectKey(base) === from) + if (!to) return project + return project.replace(new RegExp(`^${base}`, 'i'), LEGACY_RENAME_LABELS[to[1]]) + } + + // Renames legacy base keys inside a settingKey's JSON blob (each keyed by lowercased project + // name, e.g. configured_mounts.mediaservant) so per-project data saved under the old name isn't + // orphaned once the project list itself has been renamed (see migrateLegacyProjectName). + function migrateLegacyKeyedJson(nextSettings: Record, settingKey: string) { + const obj = parseJson(nextSettings[settingKey], {}) + let changed = false + LEGACY_RENAMES.forEach(([from, to]) => { + if (obj[from] !== undefined && obj[to] === undefined) { + obj[to] = obj[from] + changed = true + } + }) + if (changed) nextSettings[settingKey] = JSON.stringify(obj) + } + function migrateLegacySettings(nextSettings: Record) { - const renames: [string, string][] = [ - ['mediaconfig', 'projectconfigurator'], - ['mediaservant', 'carriernode'], - ] - renames.forEach(([from, to]) => { + LEGACY_RENAMES.forEach(([from, to]) => { if (nextSettings[`${from}_url`] && !nextSettings[`${to}_url`]) nextSettings[`${to}_url`] = nextSettings[`${from}_url`] if (nextSettings[`${from}_label`] && !nextSettings[`${to}_label`]) { nextSettings[`${to}_label`] = nextSettings[`${from}_label`] } }) - const legacyLogin = parseJson(nextSettings.configured_login_required, {}) - let loginChanged = false - renames.forEach(([from, to]) => { - if (legacyLogin[from] !== undefined && legacyLogin[to] === undefined) { - legacyLogin[to] = legacyLogin[from] - loginChanged = true - } - }) - if (loginChanged) nextSettings.configured_login_required = JSON.stringify(legacyLogin) + ;['configured_labels', 'configured_login_required', 'configured_project_meta', 'configured_mounts'].forEach( + (settingKey) => migrateLegacyKeyedJson(nextSettings, settingKey), + ) } async function load() { @@ -682,17 +706,11 @@ migrateLegacySettings(nextSettings) settings = nextSettings - let nextCentral = parseJson(nextSettings.configured_central, []) - let nextMain = parseJson(nextSettings.configured_main, []) + let nextCentral = parseJson(nextSettings.configured_central, []).map(migrateLegacyProjectName) + let nextMain = parseJson(nextSettings.configured_main, []).map(migrateLegacyProjectName) if (nextCentral.length === 0 && nextMain.length === 0) { const centralBases = CENTRAL_KINDS.map((kind) => kind.base.toLowerCase()) - const legacyProjects = parseJson(nextSettings.configured_projects, []).map((project) => - projectKey(project) === 'mediaconfig' - ? 'ProjectConfigurator' - : projectKey(getBaseProject(project)) === 'mediaservant' - ? project.replace(/mediaservant/i, 'CarrierNode') - : project, - ) + const legacyProjects = parseJson(nextSettings.configured_projects, []).map(migrateLegacyProjectName) nextCentral = legacyProjects.filter((project) => centralBases.includes(getBaseProject(project).toLowerCase())) nextMain = legacyProjects.filter((project) => !centralBases.includes(getBaseProject(project).toLowerCase())) }