Files
mealie/mealie/routes/utility_routes.py
Hayden 84c23765cd fix: strict optional errors (#1759)
* fix strict optional errors

* fix typing in repository

* fix backup db files location

* update workspace settings
2022-10-23 13:04:04 -08:00

19 lines
666 B
Python

from pathlib import Path
from fastapi import APIRouter, Depends, HTTPException, status
from starlette.responses import FileResponse
from mealie.core.dependencies import validate_file_token
router = APIRouter(prefix="/api/utils", tags=["Utils"], include_in_schema=True)
@router.get("/download")
async def download_file(file_path: Path = Depends(validate_file_token)):
"""Uses a file token obtained by an active user to retrieve a file from the operating
system."""
if not file_path.is_file():
raise HTTPException(status.HTTP_400_BAD_REQUEST)
return FileResponse(file_path, media_type="application/octet-stream", filename=file_path.name)