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 <noreply@anthropic.com>
This commit is contained in:
Gabriel20xxandClaude Sonnet 5 committed 2026-09-06 21:02:27 +02:00
1 parent ee59571552
commit 4cca0ddf72
1 file changed
+39 -21
+39 -21
View File
@@ -647,27 +647,51 @@
// MediaServant -> CarrierNode, and the old flat configured_projects list (which mixed // MediaServant -> CarrierNode, and the old flat configured_projects list (which mixed
// MediaConfig/MediaServant in with every other project) split into configured_central / // MediaConfig/MediaServant in with every other project) split into configured_central /
// configured_main. // configured_main.
function migrateLegacySettings(nextSettings: Record<string, string>) { const LEGACY_RENAMES: [string, string][] = [
const renames: [string, string][] = [
['mediaconfig', 'projectconfigurator'], ['mediaconfig', 'projectconfigurator'],
['mediaservant', 'carriernode'], ['mediaservant', 'carriernode'],
] ]
renames.forEach(([from, to]) => { const LEGACY_RENAME_LABELS: Record<string, string> = {
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<string, string>, settingKey: string) {
const obj = parseJson<Json>(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<string, string>) {
LEGACY_RENAMES.forEach(([from, to]) => {
if (nextSettings[`${from}_url`] && !nextSettings[`${to}_url`]) if (nextSettings[`${from}_url`] && !nextSettings[`${to}_url`])
nextSettings[`${to}_url`] = nextSettings[`${from}_url`] nextSettings[`${to}_url`] = nextSettings[`${from}_url`]
if (nextSettings[`${from}_label`] && !nextSettings[`${to}_label`]) { if (nextSettings[`${from}_label`] && !nextSettings[`${to}_label`]) {
nextSettings[`${to}_label`] = nextSettings[`${from}_label`] nextSettings[`${to}_label`] = nextSettings[`${from}_label`]
} }
}) })
const legacyLogin = parseJson<Json>(nextSettings.configured_login_required, {}) ;['configured_labels', 'configured_login_required', 'configured_project_meta', 'configured_mounts'].forEach(
let loginChanged = false (settingKey) => migrateLegacyKeyedJson(nextSettings, settingKey),
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)
} }
async function load() { async function load() {
@@ -682,17 +706,11 @@
migrateLegacySettings(nextSettings) migrateLegacySettings(nextSettings)
settings = nextSettings settings = nextSettings
let nextCentral = parseJson<string[]>(nextSettings.configured_central, []) let nextCentral = parseJson<string[]>(nextSettings.configured_central, []).map(migrateLegacyProjectName)
let nextMain = parseJson<string[]>(nextSettings.configured_main, []) let nextMain = parseJson<string[]>(nextSettings.configured_main, []).map(migrateLegacyProjectName)
if (nextCentral.length === 0 && nextMain.length === 0) { if (nextCentral.length === 0 && nextMain.length === 0) {
const centralBases = CENTRAL_KINDS.map((kind) => kind.base.toLowerCase()) const centralBases = CENTRAL_KINDS.map((kind) => kind.base.toLowerCase())
const legacyProjects = parseJson<string[]>(nextSettings.configured_projects, []).map((project) => const legacyProjects = parseJson<string[]>(nextSettings.configured_projects, []).map(migrateLegacyProjectName)
projectKey(project) === 'mediaconfig'
? 'ProjectConfigurator'
: projectKey(getBaseProject(project)) === 'mediaservant'
? project.replace(/mediaservant/i, 'CarrierNode')
: project,
)
nextCentral = legacyProjects.filter((project) => centralBases.includes(getBaseProject(project).toLowerCase())) nextCentral = legacyProjects.filter((project) => centralBases.includes(getBaseProject(project).toLowerCase()))
nextMain = legacyProjects.filter((project) => !centralBases.includes(getBaseProject(project).toLowerCase())) nextMain = legacyProjects.filter((project) => !centralBases.includes(getBaseProject(project).toLowerCase()))
} }