From 8098d7199f3a93e76f4d1fac9eda7f042ef83592 Mon Sep 17 00:00:00 2001 From: Georges-Antoine Assi Date: Thu, 17 Jul 2025 12:38:40 -0400 Subject: [PATCH] complete resournces handler --- backend/endpoints/rom.py | 14 +++++++------- backend/handler/filesystem/platforms_handler.py | 3 ++- backend/handler/filesystem/resources_handler.py | 3 +++ 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/backend/endpoints/rom.py b/backend/endpoints/rom.py index f272ddaab..d4c57cca2 100644 --- a/backend/endpoints/rom.py +++ b/backend/endpoints/rom.py @@ -112,18 +112,19 @@ async def add_rom( ) platform_fs_slug = db_platform.fs_slug - roms_path = fs_rom_handler.build_upload_fs_path(platform_fs_slug) + roms_path = fs_rom_handler.get_roms_fs_structure(platform_fs_slug) log.info( f"Uploading file to {hl(db_platform.custom_name or db_platform.name, color=BLUE)}[{hl(platform_fs_slug)}]" ) - file_location = Path(f"{roms_path}/{filename}") + file_location = fs_rom_handler._validate_path(f"{roms_path}/{filename}") + parser = StreamingFormDataParser(headers=request.headers) parser.register("x-upload-platform", NullTarget()) parser.register(filename, FileTarget(str(file_location))) # Check if the file already exists - if await file_location.exists(): + if fs_rom_handler.file_exists(str(file_location)): log.warning(f" - Skipping {hl(filename)} since the file already exists") raise HTTPException( status_code=status.HTTP_400_BAD_REQUEST, @@ -131,12 +132,11 @@ async def add_rom( ) # Create the directory if it doesn't exist - if not await file_location.parent.exists(): - await file_location.parent.mkdir(parents=True, exist_ok=True) + fs_rom_handler.make_directory(roms_path) async def cleanup_partial_file(): - if await file_location.exists(): - await file_location.unlink() + if file_location.exists(): + file_location.unlink() try: async for chunk in request.stream(): diff --git a/backend/handler/filesystem/platforms_handler.py b/backend/handler/filesystem/platforms_handler.py index 226722ed5..7166c392d 100644 --- a/backend/handler/filesystem/platforms_handler.py +++ b/backend/handler/filesystem/platforms_handler.py @@ -1,5 +1,6 @@ import os +from config import LIBRARY_BASE_PATH from config.config_manager import Config from config.config_manager import config_manager as cm @@ -13,7 +14,7 @@ from .base_handler import FSHandler class FSPlatformsHandler(FSHandler): def __init__(self) -> None: - pass + super().__init__(base_path=LIBRARY_BASE_PATH) def _exclude_platforms(self, config: Config, platforms: list): return [ diff --git a/backend/handler/filesystem/resources_handler.py b/backend/handler/filesystem/resources_handler.py index cec140db1..41e374157 100644 --- a/backend/handler/filesystem/resources_handler.py +++ b/backend/handler/filesystem/resources_handler.py @@ -16,6 +16,9 @@ from .base_handler import CoverSize, FSHandler class FSResourcesHandler(FSHandler): + def __init__(self) -> None: + super().__init__(base_path=RESOURCES_BASE_PATH) + @staticmethod async def cover_exists(entity: Rom | Collection, size: CoverSize) -> bool: """Check if rom cover exists in filesystem