feat(storage): expose a path to access local storage
This commit is contained in:
@@ -4,6 +4,7 @@ from app.signalr import signalr_router as signalr_router
|
||||
|
||||
from .auth import router as auth_router
|
||||
from .fetcher import fetcher_router as fetcher_router
|
||||
from .file import file_router as file_router
|
||||
from .private import private_router as private_router
|
||||
from .v2.router import router as api_v2_router
|
||||
|
||||
@@ -11,6 +12,7 @@ __all__ = [
|
||||
"api_v2_router",
|
||||
"auth_router",
|
||||
"fetcher_router",
|
||||
"file_router",
|
||||
"private_router",
|
||||
"signalr_router",
|
||||
]
|
||||
|
||||
26
app/router/file.py
Normal file
26
app/router/file.py
Normal file
@@ -0,0 +1,26 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from app.dependencies.storage import get_storage_service
|
||||
from app.storage import LocalStorageService, StorageService
|
||||
|
||||
from fastapi import APIRouter, Depends, HTTPException
|
||||
from fastapi.responses import FileResponse
|
||||
|
||||
file_router = APIRouter(prefix="/file")
|
||||
|
||||
|
||||
@file_router.get("/{path:path}")
|
||||
async def get_file(path: str, storage: StorageService = Depends(get_storage_service)):
|
||||
if not isinstance(storage, LocalStorageService):
|
||||
raise HTTPException(404, "Not Found")
|
||||
if not await storage.is_exists(path):
|
||||
raise HTTPException(404, "Not Found")
|
||||
|
||||
try:
|
||||
return FileResponse(
|
||||
path=storage._get_file_path(path),
|
||||
media_type="application/octet-stream",
|
||||
filename=path.split("/")[-1],
|
||||
)
|
||||
except FileNotFoundError:
|
||||
raise HTTPException(404, "Not Found")
|
||||
@@ -1,7 +1,5 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from app.signalr import signalr_router as signalr_router
|
||||
|
||||
from . import ( # pyright: ignore[reportUnusedImport] # noqa: F401
|
||||
beatmap,
|
||||
beatmapset,
|
||||
|
||||
Reference in New Issue
Block a user