mirror of
https://github.com/rommapp/romm.git
synced 2026-02-19 07:50:57 +01:00
Instead of using just strings, this change converts the scopes to a `StrEnum`, to be compatible with places where a string is expected. This avoids typos when using these scopes, simplifies searching for usages, and improves type hints. An extra change was the fix to the Firmware download endpoint, which wasn't respecting the `DISABLE_DOWNLOAD_ENDPOINT_AUTH` flag.
30 lines
912 B
Python
30 lines
912 B
Python
from config import ASSETS_BASE_PATH
|
|
from decorators.auth import protected_route
|
|
from fastapi import Request
|
|
from fastapi.responses import FileResponse
|
|
from handler.auth.base_handler import Scope
|
|
from utils.router import APIRouter
|
|
|
|
router = APIRouter()
|
|
|
|
|
|
@protected_route(router.head, "/raw/assets/{path:path}", [Scope.ASSETS_READ])
|
|
def head_raw_asset(request: Request, path: str):
|
|
asset_path = f"{ASSETS_BASE_PATH}/{path}"
|
|
return FileResponse(path=asset_path, filename=path.split("/")[-1])
|
|
|
|
|
|
@protected_route(router.get, "/raw/assets/{path:path}", [Scope.ASSETS_READ])
|
|
def get_raw_asset(request: Request, path: str):
|
|
"""Download a single asset file
|
|
|
|
Args:
|
|
request (Request): Fastapi Request object
|
|
|
|
Returns:
|
|
FileResponse: Returns a single asset file
|
|
"""
|
|
|
|
asset_path = f"{ASSETS_BASE_PATH}/{path}"
|
|
return FileResponse(path=asset_path, filename=path.split("/")[-1])
|