refactor(api): use Annotated-style dependency injection

This commit is contained in:
MingxuanGame
2025-10-03 05:41:31 +00:00
parent 37b4eadf79
commit 346c2557cf
45 changed files with 623 additions and 577 deletions

View File

@@ -1,16 +1,16 @@
from __future__ import annotations
from app.dependencies.storage import get_storage_service
from app.storage import LocalStorageService, StorageService
from app.dependencies.storage import StorageService as StorageServiceDep
from app.storage import LocalStorageService
from fastapi import APIRouter, Depends, HTTPException
from fastapi import APIRouter, HTTPException
from fastapi.responses import FileResponse
file_router = APIRouter(prefix="/file", include_in_schema=False)
@file_router.get("/{path:path}")
async def get_file(path: str, storage: StorageService = Depends(get_storage_service)):
async def get_file(path: str, storage: StorageServiceDep):
if not isinstance(storage, LocalStorageService):
raise HTTPException(404, "Not Found")
if not await storage.is_exists(path):