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,17 +1,21 @@
from __future__ import annotations
from typing import Annotated
from app.config import settings
from app.dependencies.database import get_redis
from app.fetcher import Fetcher
from app.fetcher import Fetcher as OriginFetcher
from app.log import logger
fetcher: Fetcher | None = None
from fastapi import Depends
fetcher: OriginFetcher | None = None
async def get_fetcher() -> Fetcher:
async def get_fetcher() -> OriginFetcher:
global fetcher
if fetcher is None:
fetcher = Fetcher(
fetcher = OriginFetcher(
settings.fetcher_client_id,
settings.fetcher_client_secret,
settings.fetcher_scopes,
@@ -27,3 +31,6 @@ async def get_fetcher() -> Fetcher:
if not fetcher.access_token or not fetcher.refresh_token:
logger.opt(colors=True).info(f"Login to initialize fetcher: <y>{fetcher.authorize_url}</y>")
return fetcher
Fetcher = Annotated[OriginFetcher, Depends(get_fetcher)]