mirror of
https://github.com/rommapp/romm.git
synced 2026-06-28 06:46:00 +00:00
complete resournces handler
This commit is contained in:
@@ -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():
|
||||
|
||||
@@ -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 [
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user