From 9f466c9d76a98a3b4ee92a8a73d8435aca9af34a Mon Sep 17 00:00:00 2001 From: yiannias Date: Wed, 23 Sep 2026 11:58:53 -0500 Subject: [PATCH 1/5] fix(player): load Amiga firmware into PUAE system directory --- frontend/src/utils/emulatorjsFirmware.test.ts | 32 +++++++++++++++++++ frontend/src/utils/emulatorjsFirmware.ts | 29 +++++++++++++++++ frontend/src/v2/views/Player/EmulatorJS.vue | 1 + frontend/src/views/Player/EmulatorJS/Base.vue | 1 + .../src/views/Player/EmulatorJS/Player.vue | 3 ++ 5 files changed, 66 insertions(+) create mode 100644 frontend/src/utils/emulatorjsFirmware.test.ts create mode 100644 frontend/src/utils/emulatorjsFirmware.ts diff --git a/frontend/src/utils/emulatorjsFirmware.test.ts b/frontend/src/utils/emulatorjsFirmware.test.ts new file mode 100644 index 000000000..74cb47fd0 --- /dev/null +++ b/frontend/src/utils/emulatorjsFirmware.test.ts @@ -0,0 +1,32 @@ +import { describe, expect, it } from "vitest"; +import { puaeFirmwareFiles } from "./emulatorjsFirmware"; + +const firmware = [ + { id: 1, file_name: "kick34005.A500", missing_from_fs: false }, + { id: 2, file_name: "kick40068.A1200", missing_from_fs: false }, + { id: 3, file_name: "gone.rom", missing_from_fs: true }, +]; + +describe("puaeFirmwareFiles", () => { + it("places every available Kickstart at its own name in the system directory", () => { + expect(puaeFirmwareFiles("puae", firmware)).toEqual({ + "/home/web_user/retroarch/userdata/system/kick34005.A500": + "/api/firmware/1/content/kick34005.A500", + "/home/web_user/retroarch/userdata/system/kick40068.A1200": + "/api/firmware/2/content/kick40068.A1200", + }); + }); + + it("does not change firmware loading for another core", () => { + expect(puaeFirmwareFiles("pcsx_rearmed", firmware)).toEqual({}); + }); + + it("ignores unsafe filenames", () => { + expect( + puaeFirmwareFiles("puae", [ + { id: 1, file_name: "../other.rom", missing_from_fs: false }, + { id: 2, file_name: "folder\\file.rom", missing_from_fs: false }, + ]), + ).toEqual({}); + }); +}); diff --git a/frontend/src/utils/emulatorjsFirmware.ts b/frontend/src/utils/emulatorjsFirmware.ts new file mode 100644 index 000000000..9ef3855d4 --- /dev/null +++ b/frontend/src/utils/emulatorjsFirmware.ts @@ -0,0 +1,29 @@ +interface FirmwareFile { + id: number; + file_name: string; + missing_from_fs: boolean; +} + +const SYSTEM_DIRECTORY = "/home/web_user/retroarch/userdata/system"; + +export function puaeFirmwareFiles( + core: string, + firmware: readonly FirmwareFile[], +): Record { + if (core !== "puae") return {}; + + return Object.fromEntries( + firmware + .filter( + ({ file_name, missing_from_fs }) => + !missing_from_fs && + file_name !== "." && + file_name !== ".." && + !/[\\/]/.test(file_name), + ) + .map(({ id, file_name }) => [ + `${SYSTEM_DIRECTORY}/${file_name}`, + `/api/firmware/${id}/content/${encodeURIComponent(file_name)}`, + ]), + ); +} diff --git a/frontend/src/v2/views/Player/EmulatorJS.vue b/frontend/src/v2/views/Player/EmulatorJS.vue index 7171c269d..c6f1022a5 100644 --- a/frontend/src/v2/views/Player/EmulatorJS.vue +++ b/frontend/src/v2/views/Player/EmulatorJS.vue @@ -1084,6 +1084,7 @@ const saveSlot = computed(() => chosenSlot(slotChoice.value, customSlot.value)); :save-slot="saveSlot" :load-state-label="t('rom.load-save-or-state')" :bios="selectedFirmware" + :firmware="firmwareOptions" :core="selectedCore" :disc="bootDiscId(selectedDisc)" /> diff --git a/frontend/src/views/Player/EmulatorJS/Base.vue b/frontend/src/views/Player/EmulatorJS/Base.vue index ca17dd785..0423af5dd 100644 --- a/frontend/src/views/Player/EmulatorJS/Base.vue +++ b/frontend/src/views/Player/EmulatorJS/Base.vue @@ -629,6 +629,7 @@ function openCacheDialog() { :state="selectedState" :save="selectedSave" :bios="selectedFirmware" + :firmware="firmwareOptions" :core="selectedCore" :disc="selectedDisc" /> diff --git a/frontend/src/views/Player/EmulatorJS/Player.vue b/frontend/src/views/Player/EmulatorJS/Player.vue index ccf2eb643..20bf1de04 100644 --- a/frontend/src/views/Player/EmulatorJS/Player.vue +++ b/frontend/src/views/Player/EmulatorJS/Player.vue @@ -37,6 +37,7 @@ import { getControlSchemeForPlatform, getDownloadPath, } from "@/utils"; +import { puaeFirmwareFiles } from "@/utils/emulatorjsFirmware"; import { useSnackbar, type SnackbarTone } from "@/v2/composables/useSnackbar"; import { saveSave, @@ -78,6 +79,7 @@ const props = defineProps<{ save: SaveSchema | null; state: StateSchema | null; bios: FirmwareSchema | null; + firmware: FirmwareSchema[]; core: string | null; disc: number | null; /** Slot for new saves when the loaded save has none; defaults to autosave. */ @@ -334,6 +336,7 @@ window.EJS_gameUrl = getDownloadPath({ window.EJS_biosUrl = props.bios ? `/api/firmware/${props.bios.id}/content/${props.bios.file_name}` : ""; +window.EJS_externalFiles = puaeFirmwareFiles(window.EJS_core, props.firmware); window.EJS_player = "#game"; window.EJS_color = "#A453FF"; window.EJS_alignStartButton = "center"; From 401b732e3db89320da7668c7fdb1508abb7d67f1 Mon Sep 17 00:00:00 2001 From: Georges-Antoine Assi Date: Sat, 26 Sep 2026 08:05:38 -0400 Subject: [PATCH 2/5] fix(player): pass all firmware to EmulatorJS when none is selected Generalize the PUAE helper to any core. Filename-selecting cores (PUAE) still receive every firmware file in the system directory, minus the one already loaded through EJS_biosUrl. Every other core now receives all firmware next to the game when no file is selected, the case where EJS_biosUrl previously loaded nothing. Archives are skipped because EJS_externalFiles writes them unextracted; they keep loading through the picker. Co-Authored-By: Claude Opus 5.5 (1M context) --- frontend/src/utils/emulatorjsFirmware.test.ts | 48 +++++++++++++------ frontend/src/utils/emulatorjsFirmware.ts | 34 +++++++++---- .../src/views/Player/EmulatorJS/Player.vue | 8 +++- 3 files changed, 63 insertions(+), 27 deletions(-) diff --git a/frontend/src/utils/emulatorjsFirmware.test.ts b/frontend/src/utils/emulatorjsFirmware.test.ts index 74cb47fd0..dff52f85b 100644 --- a/frontend/src/utils/emulatorjsFirmware.test.ts +++ b/frontend/src/utils/emulatorjsFirmware.test.ts @@ -1,15 +1,15 @@ import { describe, expect, it } from "vitest"; -import { puaeFirmwareFiles } from "./emulatorjsFirmware"; +import { firmwareExternalFiles } from "./emulatorjsFirmware"; -const firmware = [ - { id: 1, file_name: "kick34005.A500", missing_from_fs: false }, - { id: 2, file_name: "kick40068.A1200", missing_from_fs: false }, - { id: 3, file_name: "gone.rom", missing_from_fs: true }, -]; +const kick13 = { id: 1, file_name: "kick34005.A500", missing_from_fs: false }; +const kick31 = { id: 2, file_name: "kick40068.A1200", missing_from_fs: false }; +const missing = { id: 3, file_name: "gone.rom", missing_from_fs: true }; +const bundle = { id: 4, file_name: "bios.zip", missing_from_fs: false }; +const firmware = [kick13, kick31, missing, bundle]; -describe("puaeFirmwareFiles", () => { - it("places every available Kickstart at its own name in the system directory", () => { - expect(puaeFirmwareFiles("puae", firmware)).toEqual({ +describe("firmwareExternalFiles", () => { + it("places every available Kickstart in the PUAE system directory", () => { + expect(firmwareExternalFiles("puae", firmware, null)).toEqual({ "/home/web_user/retroarch/userdata/system/kick34005.A500": "/api/firmware/1/content/kick34005.A500", "/home/web_user/retroarch/userdata/system/kick40068.A1200": @@ -17,16 +17,34 @@ describe("puaeFirmwareFiles", () => { }); }); - it("does not change firmware loading for another core", () => { - expect(puaeFirmwareFiles("pcsx_rearmed", firmware)).toEqual({}); + it("leaves the selected file to EJS_biosUrl for PUAE", () => { + expect(firmwareExternalFiles("puae", firmware, kick13)).toEqual({ + "/home/web_user/retroarch/userdata/system/kick40068.A1200": + "/api/firmware/2/content/kick40068.A1200", + }); + }); + + it("passes every file next to the game for other cores when none is selected", () => { + expect(firmwareExternalFiles("melonds", firmware, null)).toEqual({ + "/kick34005.A500": "/api/firmware/1/content/kick34005.A500", + "/kick40068.A1200": "/api/firmware/2/content/kick40068.A1200", + }); + }); + + it("passes nothing extra for other cores once a file is selected", () => { + expect(firmwareExternalFiles("pcsx_rearmed", firmware, kick13)).toEqual({}); }); it("ignores unsafe filenames", () => { expect( - puaeFirmwareFiles("puae", [ - { id: 1, file_name: "../other.rom", missing_from_fs: false }, - { id: 2, file_name: "folder\\file.rom", missing_from_fs: false }, - ]), + firmwareExternalFiles( + "puae", + [ + { id: 1, file_name: "../other.rom", missing_from_fs: false }, + { id: 2, file_name: "folder\\file.rom", missing_from_fs: false }, + ], + null, + ), ).toEqual({}); }); }); diff --git a/frontend/src/utils/emulatorjsFirmware.ts b/frontend/src/utils/emulatorjsFirmware.ts index 9ef3855d4..fc6f2ff28 100644 --- a/frontend/src/utils/emulatorjsFirmware.ts +++ b/frontend/src/utils/emulatorjsFirmware.ts @@ -1,28 +1,42 @@ -interface FirmwareFile { - id: number; - file_name: string; - missing_from_fs: boolean; -} +import type { FirmwareSchema } from "@/__generated__"; + +type FirmwareFile = Pick< + FirmwareSchema, + "id" | "file_name" | "missing_from_fs" +>; const SYSTEM_DIRECTORY = "/home/web_user/retroarch/userdata/system"; +// Where EmulatorJS writes EJS_biosUrl, next to the game. +const CONTENT_DIRECTORY = ""; +// Cores that pick among several firmware files by name for each game. +const FILENAME_SELECTING_CORES = new Set(["puae"]); +// EJS_externalFiles writes archives unextracted; they still load through EJS_biosUrl. +const ARCHIVE_EXTENSION = /\.(zip|7z|rar)$/i; -export function puaeFirmwareFiles( +/** Firmware to load beside EJS_biosUrl: always all for filename-selecting cores, otherwise all only when none is selected. */ +export function firmwareExternalFiles( core: string, firmware: readonly FirmwareFile[], + selected: FirmwareFile | null, ): Record { - if (core !== "puae") return {}; + let directory: string; + if (FILENAME_SELECTING_CORES.has(core)) directory = SYSTEM_DIRECTORY; + else if (!selected) directory = CONTENT_DIRECTORY; + else return {}; return Object.fromEntries( firmware .filter( - ({ file_name, missing_from_fs }) => + ({ id, file_name, missing_from_fs }) => + id !== selected?.id && !missing_from_fs && file_name !== "." && file_name !== ".." && - !/[\\/]/.test(file_name), + !/[\\/]/.test(file_name) && + !ARCHIVE_EXTENSION.test(file_name), ) .map(({ id, file_name }) => [ - `${SYSTEM_DIRECTORY}/${file_name}`, + `${directory}/${file_name}`, `/api/firmware/${id}/content/${encodeURIComponent(file_name)}`, ]), ); diff --git a/frontend/src/views/Player/EmulatorJS/Player.vue b/frontend/src/views/Player/EmulatorJS/Player.vue index 20bf1de04..3b247158a 100644 --- a/frontend/src/views/Player/EmulatorJS/Player.vue +++ b/frontend/src/views/Player/EmulatorJS/Player.vue @@ -37,7 +37,7 @@ import { getControlSchemeForPlatform, getDownloadPath, } from "@/utils"; -import { puaeFirmwareFiles } from "@/utils/emulatorjsFirmware"; +import { firmwareExternalFiles } from "@/utils/emulatorjsFirmware"; import { useSnackbar, type SnackbarTone } from "@/v2/composables/useSnackbar"; import { saveSave, @@ -336,7 +336,11 @@ window.EJS_gameUrl = getDownloadPath({ window.EJS_biosUrl = props.bios ? `/api/firmware/${props.bios.id}/content/${props.bios.file_name}` : ""; -window.EJS_externalFiles = puaeFirmwareFiles(window.EJS_core, props.firmware); +window.EJS_externalFiles = firmwareExternalFiles( + window.EJS_core, + props.firmware, + props.bios, +); window.EJS_player = "#game"; window.EJS_color = "#A453FF"; window.EJS_alignStartButton = "center"; From 0d817a51e942a4c9fb503bc0a4c669fe945f1fc0 Mon Sep 17 00:00:00 2001 From: Georges-Antoine Assi Date: Sat, 26 Sep 2026 09:54:39 -0400 Subject: [PATCH 3/5] chore(frontend): apply code-review fixes to firmware helper Reuse FirmwareLike instead of a duplicate type, correct the archive comment for the nightly EmulatorJS build, and cover the dot-name filter and URL encoding in tests. Co-Authored-By: Claude Opus 5.5 (1M context) --- frontend/src/utils/emulatorjsFirmware.test.ts | 15 +++++++++++++++ frontend/src/utils/emulatorjsFirmware.ts | 14 +++++--------- frontend/src/v2/utils/playerFirmware.ts | 2 +- 3 files changed, 21 insertions(+), 10 deletions(-) diff --git a/frontend/src/utils/emulatorjsFirmware.test.ts b/frontend/src/utils/emulatorjsFirmware.test.ts index dff52f85b..518cf3610 100644 --- a/frontend/src/utils/emulatorjsFirmware.test.ts +++ b/frontend/src/utils/emulatorjsFirmware.test.ts @@ -42,9 +42,24 @@ describe("firmwareExternalFiles", () => { [ { id: 1, file_name: "../other.rom", missing_from_fs: false }, { id: 2, file_name: "folder\\file.rom", missing_from_fs: false }, + { id: 3, file_name: "..", missing_from_fs: false }, + { id: 4, file_name: ".", missing_from_fs: false }, ], null, ), ).toEqual({}); }); + + it("encodes the name in the URL but keeps it verbatim in the path", () => { + expect( + firmwareExternalFiles( + "puae", + [{ id: 5, file_name: "kick #1?.rom", missing_from_fs: false }], + null, + ), + ).toEqual({ + "/home/web_user/retroarch/userdata/system/kick #1?.rom": + "/api/firmware/5/content/kick%20%231%3F.rom", + }); + }); }); diff --git a/frontend/src/utils/emulatorjsFirmware.ts b/frontend/src/utils/emulatorjsFirmware.ts index fc6f2ff28..8b558cb90 100644 --- a/frontend/src/utils/emulatorjsFirmware.ts +++ b/frontend/src/utils/emulatorjsFirmware.ts @@ -1,23 +1,19 @@ -import type { FirmwareSchema } from "@/__generated__"; - -type FirmwareFile = Pick< - FirmwareSchema, - "id" | "file_name" | "missing_from_fs" ->; +import type { FirmwareLike } from "@/v2/utils/playerFirmware"; const SYSTEM_DIRECTORY = "/home/web_user/retroarch/userdata/system"; // Where EmulatorJS writes EJS_biosUrl, next to the game. const CONTENT_DIRECTORY = ""; // Cores that pick among several firmware files by name for each game. const FILENAME_SELECTING_CORES = new Set(["puae"]); -// EJS_externalFiles writes archives unextracted; they still load through EJS_biosUrl. +// EJS_externalFiles writes an archive to a file key raw (4.2.3) or as its first +// entry (nightly), so archives keep loading through EJS_biosUrl. const ARCHIVE_EXTENSION = /\.(zip|7z|rar)$/i; /** Firmware to load beside EJS_biosUrl: always all for filename-selecting cores, otherwise all only when none is selected. */ export function firmwareExternalFiles( core: string, - firmware: readonly FirmwareFile[], - selected: FirmwareFile | null, + firmware: readonly FirmwareLike[], + selected: FirmwareLike | null, ): Record { let directory: string; if (FILENAME_SELECTING_CORES.has(core)) directory = SYSTEM_DIRECTORY; diff --git a/frontend/src/v2/utils/playerFirmware.ts b/frontend/src/v2/utils/playerFirmware.ts index 71aac028e..ae51bedbf 100644 --- a/frontend/src/v2/utils/playerFirmware.ts +++ b/frontend/src/v2/utils/playerFirmware.ts @@ -2,7 +2,7 @@ // never selectable, so a platform whose only BIOS is gone boots with none. // Only these fields are read, so both `FirmwareSchema` and lighter shapes fit. -interface FirmwareLike { +export interface FirmwareLike { id: number; file_name: string; missing_from_fs: boolean; From 2484d8f30fc213f30af50eb6294b7535c16e7267 Mon Sep 17 00:00:00 2001 From: Georges-Antoine Assi Date: Sat, 26 Sep 2026 09:56:19 -0400 Subject: [PATCH 4/5] fix(player): limit firmware externalFiles to PUAE and cover console mode Code review follow-up. Drop the all-firmware fallback for other cores: a cleared picker there means "no BIOS" on purpose, and the fallback refetched every platform file uncached on each launch. PUAE again gets every Kickstart, including the selected one, as originally tested. Console mode's player now sets EJS_externalFiles too, so #4733 is fixed there as well. Co-Authored-By: Claude Opus 5.5 (1M context) --- frontend/src/console/views/Play.vue | 3 + frontend/src/utils/emulatorjsFirmware.test.ts | 55 ++++++------------- frontend/src/utils/emulatorjsFirmware.ts | 15 ++--- .../src/views/Player/EmulatorJS/Player.vue | 1 - 4 files changed, 25 insertions(+), 49 deletions(-) diff --git a/frontend/src/console/views/Play.vue b/frontend/src/console/views/Play.vue index d0329c22a..1c935994d 100644 --- a/frontend/src/console/views/Play.vue +++ b/frontend/src/console/views/Play.vue @@ -32,6 +32,7 @@ import { areThreadsRequiredForEJSCore, getDownloadPath, } from "@/utils"; +import { firmwareExternalFiles } from "@/utils/emulatorjsFirmware"; import { buildStateFormData, resolveScreenshot, @@ -470,8 +471,10 @@ async function boot() { window.EJS_biosUrl = bios ? `/api/firmware/${bios.id}/content/${bios.file_name}` : ""; + window.EJS_externalFiles = firmwareExternalFiles(core, firmware); } catch { window.EJS_biosUrl = ""; + window.EJS_externalFiles = {}; } window.EJS_player = "#game"; diff --git a/frontend/src/utils/emulatorjsFirmware.test.ts b/frontend/src/utils/emulatorjsFirmware.test.ts index 518cf3610..44f8c4d98 100644 --- a/frontend/src/utils/emulatorjsFirmware.test.ts +++ b/frontend/src/utils/emulatorjsFirmware.test.ts @@ -1,15 +1,16 @@ import { describe, expect, it } from "vitest"; import { firmwareExternalFiles } from "./emulatorjsFirmware"; -const kick13 = { id: 1, file_name: "kick34005.A500", missing_from_fs: false }; -const kick31 = { id: 2, file_name: "kick40068.A1200", missing_from_fs: false }; -const missing = { id: 3, file_name: "gone.rom", missing_from_fs: true }; -const bundle = { id: 4, file_name: "bios.zip", missing_from_fs: false }; -const firmware = [kick13, kick31, missing, bundle]; +const firmware = [ + { id: 1, file_name: "kick34005.A500", missing_from_fs: false }, + { id: 2, file_name: "kick40068.A1200", missing_from_fs: false }, + { id: 3, file_name: "gone.rom", missing_from_fs: true }, + { id: 4, file_name: "bios.zip", missing_from_fs: false }, +]; describe("firmwareExternalFiles", () => { it("places every available Kickstart in the PUAE system directory", () => { - expect(firmwareExternalFiles("puae", firmware, null)).toEqual({ + expect(firmwareExternalFiles("puae", firmware)).toEqual({ "/home/web_user/retroarch/userdata/system/kick34005.A500": "/api/firmware/1/content/kick34005.A500", "/home/web_user/retroarch/userdata/system/kick40068.A1200": @@ -17,46 +18,26 @@ describe("firmwareExternalFiles", () => { }); }); - it("leaves the selected file to EJS_biosUrl for PUAE", () => { - expect(firmwareExternalFiles("puae", firmware, kick13)).toEqual({ - "/home/web_user/retroarch/userdata/system/kick40068.A1200": - "/api/firmware/2/content/kick40068.A1200", - }); - }); - - it("passes every file next to the game for other cores when none is selected", () => { - expect(firmwareExternalFiles("melonds", firmware, null)).toEqual({ - "/kick34005.A500": "/api/firmware/1/content/kick34005.A500", - "/kick40068.A1200": "/api/firmware/2/content/kick40068.A1200", - }); - }); - - it("passes nothing extra for other cores once a file is selected", () => { - expect(firmwareExternalFiles("pcsx_rearmed", firmware, kick13)).toEqual({}); + it("does not change firmware loading for another core", () => { + expect(firmwareExternalFiles("pcsx_rearmed", firmware)).toEqual({}); }); it("ignores unsafe filenames", () => { expect( - firmwareExternalFiles( - "puae", - [ - { id: 1, file_name: "../other.rom", missing_from_fs: false }, - { id: 2, file_name: "folder\\file.rom", missing_from_fs: false }, - { id: 3, file_name: "..", missing_from_fs: false }, - { id: 4, file_name: ".", missing_from_fs: false }, - ], - null, - ), + firmwareExternalFiles("puae", [ + { id: 1, file_name: "../other.rom", missing_from_fs: false }, + { id: 2, file_name: "folder\\file.rom", missing_from_fs: false }, + { id: 3, file_name: "..", missing_from_fs: false }, + { id: 4, file_name: ".", missing_from_fs: false }, + ]), ).toEqual({}); }); it("encodes the name in the URL but keeps it verbatim in the path", () => { expect( - firmwareExternalFiles( - "puae", - [{ id: 5, file_name: "kick #1?.rom", missing_from_fs: false }], - null, - ), + firmwareExternalFiles("puae", [ + { id: 5, file_name: "kick #1?.rom", missing_from_fs: false }, + ]), ).toEqual({ "/home/web_user/retroarch/userdata/system/kick #1?.rom": "/api/firmware/5/content/kick%20%231%3F.rom", diff --git a/frontend/src/utils/emulatorjsFirmware.ts b/frontend/src/utils/emulatorjsFirmware.ts index 8b558cb90..5804ab619 100644 --- a/frontend/src/utils/emulatorjsFirmware.ts +++ b/frontend/src/utils/emulatorjsFirmware.ts @@ -1,30 +1,23 @@ import type { FirmwareLike } from "@/v2/utils/playerFirmware"; const SYSTEM_DIRECTORY = "/home/web_user/retroarch/userdata/system"; -// Where EmulatorJS writes EJS_biosUrl, next to the game. -const CONTENT_DIRECTORY = ""; // Cores that pick among several firmware files by name for each game. const FILENAME_SELECTING_CORES = new Set(["puae"]); // EJS_externalFiles writes an archive to a file key raw (4.2.3) or as its first // entry (nightly), so archives keep loading through EJS_biosUrl. const ARCHIVE_EXTENSION = /\.(zip|7z|rar)$/i; -/** Firmware to load beside EJS_biosUrl: always all for filename-selecting cores, otherwise all only when none is selected. */ +/** Every platform firmware file for a filename-selecting core, as EJS_externalFiles entries. */ export function firmwareExternalFiles( core: string, firmware: readonly FirmwareLike[], - selected: FirmwareLike | null, ): Record { - let directory: string; - if (FILENAME_SELECTING_CORES.has(core)) directory = SYSTEM_DIRECTORY; - else if (!selected) directory = CONTENT_DIRECTORY; - else return {}; + if (!FILENAME_SELECTING_CORES.has(core)) return {}; return Object.fromEntries( firmware .filter( - ({ id, file_name, missing_from_fs }) => - id !== selected?.id && + ({ file_name, missing_from_fs }) => !missing_from_fs && file_name !== "." && file_name !== ".." && @@ -32,7 +25,7 @@ export function firmwareExternalFiles( !ARCHIVE_EXTENSION.test(file_name), ) .map(({ id, file_name }) => [ - `${directory}/${file_name}`, + `${SYSTEM_DIRECTORY}/${file_name}`, `/api/firmware/${id}/content/${encodeURIComponent(file_name)}`, ]), ); diff --git a/frontend/src/views/Player/EmulatorJS/Player.vue b/frontend/src/views/Player/EmulatorJS/Player.vue index 3b247158a..b1faeee9f 100644 --- a/frontend/src/views/Player/EmulatorJS/Player.vue +++ b/frontend/src/views/Player/EmulatorJS/Player.vue @@ -339,7 +339,6 @@ window.EJS_biosUrl = props.bios window.EJS_externalFiles = firmwareExternalFiles( window.EJS_core, props.firmware, - props.bios, ); window.EJS_player = "#game"; window.EJS_color = "#A453FF"; From 93f1107db2b6fd3bc0b1a19eab3b269525a5ff90 Mon Sep 17 00:00:00 2001 From: Georges-Antoine Assi Date: Sat, 26 Sep 2026 09:59:49 -0400 Subject: [PATCH 5/5] refactor(frontend): simplify firmware externalFiles helper Simplify pass. Move firmwareExternalFiles into v2/utils/playerFirmware next to resolveInitialFirmware so one module owns the player's firmware logic and FirmwareLike stays private, replace the single-member core set with a direct check, and fold the filename guards into one regex. Co-Authored-By: Claude Opus 5.5 (1M context) --- frontend/src/console/views/Play.vue | 2 +- frontend/src/utils/emulatorjsFirmware.test.ts | 46 ------------------- frontend/src/utils/emulatorjsFirmware.ts | 32 ------------- frontend/src/v2/utils/playerFirmware.test.ts | 45 +++++++++++++++++- frontend/src/v2/utils/playerFirmware.ts | 31 ++++++++++++- .../src/views/Player/EmulatorJS/Player.vue | 2 +- 6 files changed, 76 insertions(+), 82 deletions(-) delete mode 100644 frontend/src/utils/emulatorjsFirmware.test.ts delete mode 100644 frontend/src/utils/emulatorjsFirmware.ts diff --git a/frontend/src/console/views/Play.vue b/frontend/src/console/views/Play.vue index 1c935994d..92b7105a0 100644 --- a/frontend/src/console/views/Play.vue +++ b/frontend/src/console/views/Play.vue @@ -32,7 +32,7 @@ import { areThreadsRequiredForEJSCore, getDownloadPath, } from "@/utils"; -import { firmwareExternalFiles } from "@/utils/emulatorjsFirmware"; +import { firmwareExternalFiles } from "@/v2/utils/playerFirmware"; import { buildStateFormData, resolveScreenshot, diff --git a/frontend/src/utils/emulatorjsFirmware.test.ts b/frontend/src/utils/emulatorjsFirmware.test.ts deleted file mode 100644 index 44f8c4d98..000000000 --- a/frontend/src/utils/emulatorjsFirmware.test.ts +++ /dev/null @@ -1,46 +0,0 @@ -import { describe, expect, it } from "vitest"; -import { firmwareExternalFiles } from "./emulatorjsFirmware"; - -const firmware = [ - { id: 1, file_name: "kick34005.A500", missing_from_fs: false }, - { id: 2, file_name: "kick40068.A1200", missing_from_fs: false }, - { id: 3, file_name: "gone.rom", missing_from_fs: true }, - { id: 4, file_name: "bios.zip", missing_from_fs: false }, -]; - -describe("firmwareExternalFiles", () => { - it("places every available Kickstart in the PUAE system directory", () => { - expect(firmwareExternalFiles("puae", firmware)).toEqual({ - "/home/web_user/retroarch/userdata/system/kick34005.A500": - "/api/firmware/1/content/kick34005.A500", - "/home/web_user/retroarch/userdata/system/kick40068.A1200": - "/api/firmware/2/content/kick40068.A1200", - }); - }); - - it("does not change firmware loading for another core", () => { - expect(firmwareExternalFiles("pcsx_rearmed", firmware)).toEqual({}); - }); - - it("ignores unsafe filenames", () => { - expect( - firmwareExternalFiles("puae", [ - { id: 1, file_name: "../other.rom", missing_from_fs: false }, - { id: 2, file_name: "folder\\file.rom", missing_from_fs: false }, - { id: 3, file_name: "..", missing_from_fs: false }, - { id: 4, file_name: ".", missing_from_fs: false }, - ]), - ).toEqual({}); - }); - - it("encodes the name in the URL but keeps it verbatim in the path", () => { - expect( - firmwareExternalFiles("puae", [ - { id: 5, file_name: "kick #1?.rom", missing_from_fs: false }, - ]), - ).toEqual({ - "/home/web_user/retroarch/userdata/system/kick #1?.rom": - "/api/firmware/5/content/kick%20%231%3F.rom", - }); - }); -}); diff --git a/frontend/src/utils/emulatorjsFirmware.ts b/frontend/src/utils/emulatorjsFirmware.ts deleted file mode 100644 index 5804ab619..000000000 --- a/frontend/src/utils/emulatorjsFirmware.ts +++ /dev/null @@ -1,32 +0,0 @@ -import type { FirmwareLike } from "@/v2/utils/playerFirmware"; - -const SYSTEM_DIRECTORY = "/home/web_user/retroarch/userdata/system"; -// Cores that pick among several firmware files by name for each game. -const FILENAME_SELECTING_CORES = new Set(["puae"]); -// EJS_externalFiles writes an archive to a file key raw (4.2.3) or as its first -// entry (nightly), so archives keep loading through EJS_biosUrl. -const ARCHIVE_EXTENSION = /\.(zip|7z|rar)$/i; - -/** Every platform firmware file for a filename-selecting core, as EJS_externalFiles entries. */ -export function firmwareExternalFiles( - core: string, - firmware: readonly FirmwareLike[], -): Record { - if (!FILENAME_SELECTING_CORES.has(core)) return {}; - - return Object.fromEntries( - firmware - .filter( - ({ file_name, missing_from_fs }) => - !missing_from_fs && - file_name !== "." && - file_name !== ".." && - !/[\\/]/.test(file_name) && - !ARCHIVE_EXTENSION.test(file_name), - ) - .map(({ id, file_name }) => [ - `${SYSTEM_DIRECTORY}/${file_name}`, - `/api/firmware/${id}/content/${encodeURIComponent(file_name)}`, - ]), - ); -} diff --git a/frontend/src/v2/utils/playerFirmware.test.ts b/frontend/src/v2/utils/playerFirmware.test.ts index c70ed6d2c..708b50737 100644 --- a/frontend/src/v2/utils/playerFirmware.test.ts +++ b/frontend/src/v2/utils/playerFirmware.test.ts @@ -1,5 +1,8 @@ import { describe, expect, it } from "vitest"; -import { resolveInitialFirmware } from "./playerFirmware"; +import { + firmwareExternalFiles, + resolveInitialFirmware, +} from "./playerFirmware"; // Only these three fields are read; minimal stubs stand in for FirmwareSchema. const fw = (id: number, file_name: string, missing_from_fs = false) => ({ @@ -96,3 +99,43 @@ describe("resolveInitialFirmware", () => { ).toBeNull(); }); }); + +const firmware = [ + fw(1, "kick34005.A500"), + fw(2, "kick40068.A1200"), + fw(3, "gone.rom", true), + fw(4, "bios.zip"), +]; + +describe("firmwareExternalFiles", () => { + it("places every available Kickstart in the PUAE system directory", () => { + expect(firmwareExternalFiles("puae", firmware)).toEqual({ + "/home/web_user/retroarch/userdata/system/kick34005.A500": + "/api/firmware/1/content/kick34005.A500", + "/home/web_user/retroarch/userdata/system/kick40068.A1200": + "/api/firmware/2/content/kick40068.A1200", + }); + }); + + it("does not change firmware loading for another core", () => { + expect(firmwareExternalFiles("pcsx_rearmed", firmware)).toEqual({}); + }); + + it("ignores unsafe filenames", () => { + expect( + firmwareExternalFiles("puae", [ + fw(1, "../other.rom"), + fw(2, "folder\\file.rom"), + fw(3, ".."), + fw(4, "."), + ]), + ).toEqual({}); + }); + + it("encodes the name in the URL but keeps it verbatim in the path", () => { + expect(firmwareExternalFiles("puae", [fw(5, "kick #1?.rom")])).toEqual({ + "/home/web_user/retroarch/userdata/system/kick #1?.rom": + "/api/firmware/5/content/kick%20%231%3F.rom", + }); + }); +}); diff --git a/frontend/src/v2/utils/playerFirmware.ts b/frontend/src/v2/utils/playerFirmware.ts index ae51bedbf..3cda6e5c9 100644 --- a/frontend/src/v2/utils/playerFirmware.ts +++ b/frontend/src/v2/utils/playerFirmware.ts @@ -2,7 +2,7 @@ // never selectable, so a platform whose only BIOS is gone boots with none. // Only these fields are read, so both `FirmwareSchema` and lighter shapes fit. -export interface FirmwareLike { +interface FirmwareLike { id: number; file_name: string; missing_from_fs: boolean; @@ -34,3 +34,32 @@ export function resolveInitialFirmware({ return fromStorage ?? fromConfig ?? fromSingleOption ?? null; } + +const SYSTEM_DIRECTORY = "/home/web_user/retroarch/userdata/system"; +const UNSAFE_FILE_NAME = /^\.{1,2}$|[\\/]/; +// EJS_externalFiles writes an archive to a file key raw (4.2.3) or as its first +// entry (nightly), so archives keep loading through EJS_biosUrl. +const ARCHIVE_EXTENSION = /\.(zip|7z|rar)$/i; + +/** Every platform firmware file for PUAE, as EJS_externalFiles entries. */ +export function firmwareExternalFiles( + core: string, + firmware: readonly FirmwareLike[], +): Record { + // PUAE picks among several Kickstarts by name for each game. + if (core !== "puae") return {}; + + return Object.fromEntries( + firmware + .filter( + ({ file_name, missing_from_fs }) => + !missing_from_fs && + !UNSAFE_FILE_NAME.test(file_name) && + !ARCHIVE_EXTENSION.test(file_name), + ) + .map(({ id, file_name }) => [ + `${SYSTEM_DIRECTORY}/${file_name}`, + `/api/firmware/${id}/content/${encodeURIComponent(file_name)}`, + ]), + ); +} diff --git a/frontend/src/views/Player/EmulatorJS/Player.vue b/frontend/src/views/Player/EmulatorJS/Player.vue index b1faeee9f..5f7f0b39a 100644 --- a/frontend/src/views/Player/EmulatorJS/Player.vue +++ b/frontend/src/views/Player/EmulatorJS/Player.vue @@ -37,8 +37,8 @@ import { getControlSchemeForPlatform, getDownloadPath, } from "@/utils"; -import { firmwareExternalFiles } from "@/utils/emulatorjsFirmware"; import { useSnackbar, type SnackbarTone } from "@/v2/composables/useSnackbar"; +import { firmwareExternalFiles } from "@/v2/utils/playerFirmware"; import { saveSave, captureScreenshot,