complete resournces handler

This commit is contained in:
Georges-Antoine Assi
2025-07-17 12:38:40 -04:00
parent aaf6741e93
commit 8098d7199f
3 changed files with 12 additions and 8 deletions

View File

@@ -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():

View File

@@ -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 [

View File

@@ -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