18 lines
510 B
Python
18 lines
510 B
Python
from fastapi import APIRouter, HTTPException
|
|
from fastapi.responses import FileResponse
|
|
|
|
from app.integrations.storage_client import StorageClient
|
|
|
|
router = APIRouter()
|
|
|
|
|
|
@router.get("/{key:path}")
|
|
def get_file(key: str) -> FileResponse:
|
|
try:
|
|
path = StorageClient().resolve(key)
|
|
except ValueError:
|
|
raise HTTPException(status_code=400, detail="非法路径")
|
|
if not path.is_file():
|
|
raise HTTPException(status_code=404, detail="文件不存在")
|
|
return FileResponse(path)
|