mirror of
https://github.com/zoriya/Kyoo.git
synced 2025-05-24 02:02:36 -04:00
Stop trying to use the non-working DI of fastapi
This commit is contained in:
parent
a821b97286
commit
75bc5a7d70
@ -23,6 +23,7 @@ async def init_pool():
|
||||
global pool
|
||||
pool = p
|
||||
yield
|
||||
pool = None # type: ignore
|
||||
|
||||
|
||||
@asynccontextmanager
|
||||
|
@ -1,3 +1,4 @@
|
||||
from contextlib import asynccontextmanager
|
||||
import os
|
||||
import re
|
||||
from logging import getLogger
|
||||
@ -16,6 +17,7 @@ from .requests import Request, RequestCreator
|
||||
logger = getLogger(__name__)
|
||||
|
||||
|
||||
@asynccontextmanager
|
||||
async def create_scanner():
|
||||
async with get_db() as db:
|
||||
yield FsScanner(KyooClient(), RequestCreator(db))
|
||||
|
@ -36,12 +36,12 @@ class RequestCreator:
|
||||
await self._database.executemany(
|
||||
"""
|
||||
insert into scanner.requests(kind, title, year, external_id, videos)
|
||||
values (%(kind)s, %(title) s, %(year)s, %(external_id)s, %(videos)s)
|
||||
values ($1, $2, $3, $4, $5)
|
||||
on conflict (kind, title, year)
|
||||
do update set
|
||||
videos = videos || excluded.videos
|
||||
""",
|
||||
TypeAdapter(list[Request]).dump_python(requests),
|
||||
[[x.kind, x.title, x.year, x.external_id, x.videos] for x in requests],
|
||||
)
|
||||
_ = await self._database.execute("notify scanner.requests")
|
||||
|
||||
|
@ -1,8 +1,8 @@
|
||||
from typing import Annotated
|
||||
|
||||
from fastapi import APIRouter, BackgroundTasks, Depends, Security
|
||||
from fastapi import APIRouter, BackgroundTasks, Security
|
||||
|
||||
from ..fsscan import FsScanner, create_scanner
|
||||
from ..fsscan import create_scanner
|
||||
from ..jwt import validate_bearer
|
||||
|
||||
router = APIRouter()
|
||||
@ -15,10 +15,14 @@ router = APIRouter()
|
||||
)
|
||||
async def trigger_scan(
|
||||
tasks: BackgroundTasks,
|
||||
scanner: Annotated[FsScanner, Depends(create_scanner)],
|
||||
_: Annotated[None, Security(validate_bearer, scopes=["scanner.trigger"])],
|
||||
):
|
||||
"""
|
||||
Trigger a full scan of the filesystem, trying to find new videos & deleting old ones.
|
||||
"""
|
||||
tasks.add_task(scanner.scan)
|
||||
|
||||
async def run():
|
||||
async with create_scanner() as scanner:
|
||||
await scanner.scan()
|
||||
|
||||
tasks.add_task(run)
|
||||
|
Loading…
x
Reference in New Issue
Block a user