Files
romm/backend/endpoints/raw.py
2024-05-21 10:18:13 -04:00

28 lines
836 B
Python

from config import ASSETS_BASE_PATH
from decorators.auth import protected_route
from fastapi import APIRouter, Request
from fastapi.responses import FileResponse
router = APIRouter()
@protected_route(router.head, "/raw/assets/{path:path}", ["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}", ["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])