Fix stale disc file_id causing 404 when playing ROMs after rescan

When a ROM is rescanned and its file IDs change, disc IDs stored in
localStorage become stale. This caused file_ids query params with invalid
IDs to be sent to /api/roms/{id}/content/{name}, resulting in 404 errors.

Validate the stored disc ID against the actual ROM files before use. If
stale, clear localStorage and fall back to the first available file.

Agent-Logs-Url: https://github.com/rommapp/romm/sessions/3579d577-13ff-4288-9a9c-909b6f891c9e

Co-authored-by: gantoine <3247106+gantoine@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot]
2026-05-14 18:38:23 +00:00
committed by GitHub
parent df32c8a2d3
commit d1696cd047
2 changed files with 14 additions and 4 deletions

View File

@@ -419,12 +419,20 @@ async function boot() {
}
// Disc selection persistence
const discId = playerStorage.disc.value
const storedDiscId = playerStorage.disc.value
? parseInt(playerStorage.disc.value)
: null;
const validDiscId =
storedDiscId && rom.files.some((f) => f.id === storedDiscId)
? storedDiscId
: null;
// Clear stale disc selection from localStorage
if (storedDiscId && !validDiscId) {
playerStorage.disc.value = null;
}
window.EJS_gameUrl = getDownloadPath({
rom: rom,
fileIDs: discId ? [discId] : [],
fileIDs: validDiscId ? [validDiscId] : [],
});
// BIOS selection persistence

View File

@@ -217,9 +217,11 @@ onMounted(async () => {
}
const storedDisc = localStorage.getItem(`player:${rom.value.id}:disc`);
if (storedDisc) {
selectedDisc.value = parseInt(storedDisc);
const storedDiscId = storedDisc ? parseInt(storedDisc) : null;
if (storedDiscId && rom.value.files.some((f) => f.id === storedDiscId)) {
selectedDisc.value = storedDiscId;
} else {
if (storedDisc) localStorage.removeItem(`player:${rom.value.id}:disc`);
selectedDisc.value = rom.value.files[0]?.id ?? null;
}