refactor(api): use Annotated-style dependency injection
This commit is contained in:
@@ -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)]
|
||||
|
||||
Reference in New Issue
Block a user