diff --git a/frontend/src/components/Details/ActionBar.vue b/frontend/src/components/Details/ActionBar.vue index 44945d762..b93a3ee75 100644 --- a/frontend/src/components/Details/ActionBar.vue +++ b/frontend/src/components/Details/ActionBar.vue @@ -29,7 +29,7 @@ const ejsEmulationSupported = computed(() => const ruffleEmulationSupported = computed(() => isRuffleEmulationSupported(props.rom.platform_slug, heartbeatStore.value), ); -const isCIARom = computed(() => { +const is3DSRom = computed(() => { return is3DSCIARom(props.rom); }); @@ -110,7 +110,7 @@ async function copyDownloadLink(rom: DetailedRom) { diff --git a/frontend/src/components/common/Game/Card/ActionBar.vue b/frontend/src/components/common/Game/Card/ActionBar.vue index 291a17dfc..06ef3df5b 100644 --- a/frontend/src/components/common/Game/Card/ActionBar.vue +++ b/frontend/src/components/common/Game/Card/ActionBar.vue @@ -30,7 +30,7 @@ const ruffleEmulationSupported = computed(() => { ); }); -const isCIARom = computed(() => { +const is3DSRom = computed(() => { return is3DSCIARom(props.rom); }); @@ -83,7 +83,7 @@ const isCIARom = computed(() => { variant="text" /> - + { await nextTick(); - const downloadLink = - romToView.file_extension.toLowerCase() === "cia" - ? getDownloadLink({ - rom: romToView, - files: [], - }) - : getDownloadLink({ - rom: romToView, - files: [ - romToView.files.filter((f) => f["filename"].endsWith(".cia"))[0] - .filename, - ], - }); + const is3DSFile = is3DSCIAFile(romToView); + const matchingFiles = get3DSCIAFiles(romToView); + + const downloadLink = getDownloadLink({ + rom: romToView, + files: is3DSFile ? [] : [matchingFiles[0].filename], + }); const qrCode = document.getElementById("qr-code"); qrcode.toCanvas(qrCode, downloadLink, { diff --git a/frontend/src/utils/index.ts b/frontend/src/utils/index.ts index df0356039..fa57771ac 100644 --- a/frontend/src/utils/index.ts +++ b/frontend/src/utils/index.ts @@ -1,7 +1,7 @@ import cronstrue from "cronstrue"; import type { SimpleRom } from "@/stores/roms"; import type { Heartbeat } from "@/stores/heartbeat"; -import type { RomUserStatus } from "@/__generated__"; +import type { RomFile, RomUserStatus } from "@/__generated__"; /** * Views configuration object. @@ -545,13 +545,26 @@ export function getStatusKeyForText(text: string) { return inverseRomStatusMap[text]; } -/** - * Check if a ROM is a 3DS .CIA file - * @param rom The ROM object. - * @returns True if the ROM is a 3DS .CIA file, false otherwise. - */ -export function is3DSCIARom(rom: SimpleRom) { - if (rom.platform_slug !== "3ds") return false; - if (rom.file_extension.toLowerCase() === "cia") return true; - return rom.files.some((f) => f["filename"].toLowerCase().endsWith(".cia")); +export function is3DSCIAFile(rom: SimpleRom): boolean { + return ["cia", "3ds"].includes(rom.file_extension.toLowerCase()); +} + +export function get3DSCIAFiles(rom: SimpleRom): RomFile[] { + return rom.files.filter((file) => + [".cia", ".3ds"].some((ext) => file.filename.toLowerCase().endsWith(ext)), + ); +} + +/** + * Check if a ROM is a valid 3DS game + * @param rom The ROM object. + * @returns True if the ROM is a valid 3DS game, false otherwise. + */ +export function is3DSCIARom(rom: SimpleRom): boolean { + if (rom.platform_slug !== "3ds") return false; + + const hasValidExtension = is3DSCIAFile(rom); + const hasValidFile = get3DSCIAFiles(rom).length > 0; + + return hasValidExtension || hasValidFile; }