From 1ec40fdb29633c3f08fb081eb4f8ff8ef7563a16 Mon Sep 17 00:00:00 2001 From: Georges-Antoine Assi Date: Sun, 19 Jul 2026 21:55:59 -0400 Subject: [PATCH 1/4] fix: load selected file with correct extension for multi-file roms Multi-file roms (e.g. multi-disk Amiga games) failed to launch in the EmulatorJS player with "Unsupported file format: ''", while single-file roms on the same platform worked. EmulatorJS derives the on-disk filename it writes to the emulator FS from the last path segment of the game URL, and the core determines the disk format from that filename's extension. getDownloadPath used the ROM-level fs_name for that segment. For multi-file roms the rom is a folder, so fs_name has no extension, and the core received an extension-less file. When a single file is selected, use that file's real name (extension included) as the content path segment instead of fs_name. The backend already serves the correct file for a single file_ids value and only uses the path segment for zip/m3u naming, so multi-file and no-selection cases are unchanged. Fixes #3746 Co-Authored-By: Claude Opus 4.8 (1M context) --- frontend/src/utils/index.test.ts | 59 ++++++++++++++++++++++++++++++++ frontend/src/utils/index.ts | 12 ++++++- 2 files changed, 70 insertions(+), 1 deletion(-) create mode 100644 frontend/src/utils/index.test.ts diff --git a/frontend/src/utils/index.test.ts b/frontend/src/utils/index.test.ts new file mode 100644 index 000000000..8acfb8f74 --- /dev/null +++ b/frontend/src/utils/index.test.ts @@ -0,0 +1,59 @@ +import { describe, expect, it } from "vitest"; +import type { SimpleRom } from "@/stores/roms"; +import { getDownloadPath } from "./index"; + +function makeRom(overrides: Partial): SimpleRom { + return { + id: 1, + fs_name: "Game", + files: [], + ...overrides, + } as SimpleRom; +} + +describe("getDownloadPath", () => { + it("uses fs_name when no file is selected", () => { + const rom = makeRom({ id: 14, fs_name: "Maniac Mansion (1989).adf" }); + expect(getDownloadPath({ rom })).toBe( + "/api/roms/14/content/Maniac Mansion (1989).adf", + ); + }); + + 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 + // receives a file with the correct extension. + const rom = makeRom({ + id: 24, + fs_name: "B.A.T.", + 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, fileIDs: [29] })).toBe( + "/api/roms/24/content/B.A.T. Disk1.adf?file_ids=29", + ); + }); + + it("falls back to fs_name when multiple files are selected (zip)", () => { + const rom = makeRom({ + id: 24, + fs_name: "B.A.T.", + 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, fileIDs: [29, 30] })).toBe( + "/api/roms/24/content/B.A.T.?file_ids=29%2C30", + ); + }); + + it("falls back to fs_name when the selected file id is unknown", () => { + const rom = makeRom({ id: 24, fs_name: "B.A.T." }); + expect(getDownloadPath({ rom, fileIDs: [999] })).toBe( + "/api/roms/24/content/B.A.T.?file_ids=999", + ); + }); +}); diff --git a/frontend/src/utils/index.ts b/frontend/src/utils/index.ts index ffd02ca9d..917dab41c 100644 --- a/frontend/src/utils/index.ts +++ b/frontend/src/utils/index.ts @@ -126,7 +126,17 @@ export function getDownloadPath({ queryParams.append("file_ids", fileIDs.join(",")); } const queryString = queryParams.toString(); - return `/api/roms/${rom.id}/content/${rom.fs_name}${ + // When a single file is selected, use its real name (extension included) as + // the path segment. EmulatorJS derives the on-disk filename, and therefore + // the file format handed to the core, from the URL. Multi-file roms have no + // root extension (`fs_name` is the folder name), so falling back to it would + // give the core an extension-less file and fail with "Unsupported file format". + const selectedFile = + fileIDs.length === 1 + ? rom.files?.find((f) => f.id === fileIDs[0]) + : undefined; + const contentName = selectedFile?.file_name ?? rom.fs_name; + return `/api/roms/${rom.id}/content/${contentName}${ queryString ? `?${queryString}` : "" }`; } From 2ac81fa84172476760bf70bf48eb1bab0f4e5af5 Mon Sep 17 00:00:00 2001 From: Georges-Antoine Assi <3247106+gantoine@users.noreply.github.com> Date: Sun, 19 Jul 2026 22:07:27 -0400 Subject: [PATCH 2/4] Apply suggestion from @greptile-apps[bot] Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com> --- frontend/src/utils/index.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/frontend/src/utils/index.ts b/frontend/src/utils/index.ts index 917dab41c..38f603eac 100644 --- a/frontend/src/utils/index.ts +++ b/frontend/src/utils/index.ts @@ -135,7 +135,9 @@ export function getDownloadPath({ fileIDs.length === 1 ? rom.files?.find((f) => f.id === fileIDs[0]) : undefined; - const contentName = selectedFile?.file_name ?? rom.fs_name; + const contentName = selectedFile + ? encodeURIComponent(selectedFile.file_name) + : rom.fs_name; return `/api/roms/${rom.id}/content/${contentName}${ queryString ? `?${queryString}` : "" }`; From 05857c014827dd1e5d59dbb1d57f9100abf28afe Mon Sep 17 00:00:00 2001 From: Georges-Antoine Assi Date: Sun, 19 Jul 2026 22:12:18 -0400 Subject: [PATCH 3/4] cleanup --- frontend/src/utils/index.ts | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/frontend/src/utils/index.ts b/frontend/src/utils/index.ts index 38f603eac..4144daa7a 100644 --- a/frontend/src/utils/index.ts +++ b/frontend/src/utils/index.ts @@ -126,11 +126,8 @@ export function getDownloadPath({ queryParams.append("file_ids", fileIDs.join(",")); } const queryString = queryParams.toString(); - // When a single file is selected, use its real name (extension included) as - // the path segment. EmulatorJS derives the on-disk filename, and therefore - // the file format handed to the core, from the URL. Multi-file roms have no - // root extension (`fs_name` is the folder name), so falling back to it would - // give the core an extension-less file and fail with "Unsupported file format". + + // If a single file is selected, use its name for the download path const selectedFile = fileIDs.length === 1 ? rom.files?.find((f) => f.id === fileIDs[0]) @@ -138,6 +135,7 @@ export function getDownloadPath({ const contentName = selectedFile ? encodeURIComponent(selectedFile.file_name) : rom.fs_name; + return `/api/roms/${rom.id}/content/${contentName}${ queryString ? `?${queryString}` : "" }`; From edd36d83f42675f762f24efc4aa96b80778f5a64 Mon Sep 17 00:00:00 2001 From: Georges-Antoine Assi Date: Sun, 19 Jul 2026 22:21:16 -0400 Subject: [PATCH 4/4] test: expect URL-encoded path segment for selected file The greptile suggestion added encodeURIComponent to the selected file name in getDownloadPath, but the test still expected a literal space. Co-Authored-By: Claude Opus 4.8 (1M context) --- frontend/src/utils/index.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/src/utils/index.test.ts b/frontend/src/utils/index.test.ts index 8acfb8f74..840c68f15 100644 --- a/frontend/src/utils/index.test.ts +++ b/frontend/src/utils/index.test.ts @@ -32,7 +32,7 @@ describe("getDownloadPath", () => { ] as SimpleRom["files"], }); expect(getDownloadPath({ rom, fileIDs: [29] })).toBe( - "/api/roms/24/content/B.A.T. Disk1.adf?file_ids=29", + "/api/roms/24/content/B.A.T.%20Disk1.adf?file_ids=29", ); });