mirror of
https://github.com/rommapp/romm.git
synced 2026-11-29 18:11:16 +01:00
@@ -12,13 +12,43 @@ function makeRom(overrides: Partial<SimpleRom>): 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
|
||||
|
||||
@@ -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}${
|
||||
|
||||
Reference in New Issue
Block a user