From 43ef2ddfeb56302f04223ddeffd63086adf3091e Mon Sep 17 00:00:00 2001 From: Georges-Antoine Assi Date: Fri, 8 Mar 2024 11:52:41 -0500 Subject: [PATCH] support file picking in download --- backend/endpoints/rom.py | 10 +++++++--- frontend/src/services/api/rom.ts | 2 +- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/backend/endpoints/rom.py b/backend/endpoints/rom.py index a8019a854..925732bd0 100644 --- a/backend/endpoints/rom.py +++ b/backend/endpoints/rom.py @@ -181,9 +181,13 @@ def get_rom_content( rom = db_rom_handler.get_roms(id) rom_path = f"{LIBRARY_BASE_PATH}/{rom.full_path}" + files_to_download = files or rom.files if not rom.multi: - return FileResponse(path=rom_path, filename=file_name) + return FileResponse(path=rom_path, filename=rom.file_name) + + if len(files_to_download) == 1: + return FileResponse(path=f"{rom_path}/{files_to_download[0]}", filename=files_to_download[0]) # Builds a generator of tuples for each member file def local_files(): @@ -195,7 +199,7 @@ def get_rom_content( except FileNotFoundError: log.error(f"File {rom_path}/{f} not found!") - m3u_file = [str.encode(f"{rom.files[i]}\n") for i in range(len(rom.files))] + m3u_file = [str.encode(f"{files_to_download[i]}\n") for i in range(len(files_to_download))] return [ ( f, @@ -204,7 +208,7 @@ def get_rom_content( ZIP_AUTO(os.path.getsize(f"{rom_path}/{f}")), contents(f), ) - for f in rom.files + for f in files_to_download ] + [ ( f"{file_name}.m3u", diff --git a/frontend/src/services/api/rom.ts b/frontend/src/services/api/rom.ts index 3a69d3269..9be06ddb0 100644 --- a/frontend/src/services/api/rom.ts +++ b/frontend/src/services/api/rom.ts @@ -130,7 +130,7 @@ async function downloadRom({ a.click(); // Only connect socket if multi-file download - if (rom.multi) { + if (rom.multi && files.length > 1) { if (!socket.connected) socket.connect(); storeDownload().add(rom.id);