From 86d8aea09c78795d82100a1ba2f3e4ae97429bec Mon Sep 17 00:00:00 2001 From: Matt Van Horn <455140+mvanhorn@users.noreply.github.com> Date: Sat, 22 Aug 2026 21:16:35 -0700 Subject: [PATCH] fix: Preserve nested arcade ROM filenames Fixes #1893 --- frontend/src/utils/index.test.ts | 34 ++++++++++++++++++++++++++++++-- frontend/src/utils/index.ts | 11 +++++++++-- 2 files changed, 41 insertions(+), 4 deletions(-) diff --git a/frontend/src/utils/index.test.ts b/frontend/src/utils/index.test.ts index 840c68f15..46aa5ad2f 100644 --- a/frontend/src/utils/index.test.ts +++ b/frontend/src/utils/index.test.ts @@ -12,13 +12,43 @@ function makeRom(overrides: Partial): SimpleRom { } describe("getDownloadPath", () => { - it("uses fs_name when no file is selected", () => { - const rom = makeRom({ id: 14, fs_name: "Maniac Mansion (1989).adf" }); + it("uses fs_name for a flat single-file rom", () => { + const rom = makeRom({ + id: 14, + fs_name: "Maniac Mansion (1989).adf", + has_nested_single_file: false, + files: [ + { id: 19, file_name: "Maniac Mansion (1989).adf" }, + ] as SimpleRom["files"], + }); expect(getDownloadPath({ rom })).toBe( "/api/roms/14/content/Maniac Mansion (1989).adf", ); }); + it("uses the file name for a nested single-file rom", () => { + const rom = makeRom({ + id: 21, + fs_name: "Art Of Fighting", + has_nested_single_file: true, + files: [{ id: 26, file_name: "aof.zip" }] as SimpleRom["files"], + }); + expect(getDownloadPath({ rom })).toBe("/api/roms/21/content/aof.zip"); + }); + + it("uses fs_name for an unselected multi-file rom", () => { + const rom = makeRom({ + id: 24, + fs_name: "B.A.T.", + has_nested_single_file: false, + files: [ + { id: 29, file_name: "B.A.T. Disk1.adf" }, + { id: 30, file_name: "B.A.T. Disk2.adf" }, + ] as SimpleRom["files"], + }); + expect(getDownloadPath({ rom })).toBe("/api/roms/24/content/B.A.T."); + }); + it("uses the selected file name (with extension) for a single file", () => { // Multi-file rom: fs_name is the folder name with no extension. The URL // path segment must carry the selected file's real name so the emulator diff --git a/frontend/src/utils/index.ts b/frontend/src/utils/index.ts index 44b106b4a..77ff79de8 100644 --- a/frontend/src/utils/index.ts +++ b/frontend/src/utils/index.ts @@ -132,8 +132,15 @@ export function getDownloadPath({ fileIDs.length === 1 ? rom.files?.find((f) => f.id === fileIDs[0]) : undefined; - const contentName = selectedFile - ? encodeURIComponent(selectedFile.file_name) + const nestedFile = + fileIDs.length === 0 && + rom.has_nested_single_file && + rom.files?.length === 1 + ? rom.files[0] + : undefined; + const contentFile = selectedFile ?? nestedFile; + const contentName = contentFile + ? encodeURIComponent(contentFile.file_name) : rom.fs_name; return `/api/roms/${rom.id}/content/${contentName}${