feat(watcher,api,frontend): watched bots become accounts and drain the update backlog
This commit is contained in:
1 parent
4bd031f21e
commit
b0ed041c2e
21 files changed
+414
-1155
No files matched your search
@@ -1,12 +1,10 @@
|
||||
from typing import Annotated
|
||||
|
||||
import asyncpg
|
||||
from dishka.integrations.fastapi import DishkaRoute, FromDishka
|
||||
from fastapi import APIRouter, HTTPException, Query
|
||||
from fastapi import APIRouter, HTTPException
|
||||
from pydantic import BaseModel
|
||||
|
||||
from utils.read import bots
|
||||
from utils.read.models import DEFAULT_LIMIT, BotStats, BotUpdateView, BotView, Page
|
||||
from utils.read.models import BotView
|
||||
from watcher import tokens
|
||||
|
||||
router = APIRouter(prefix="/api/bots", tags=["bots"], route_class=DishkaRoute)
|
||||
@@ -42,38 +40,3 @@ async def remove_bot(pool: FromDishka[asyncpg.Pool], bot_id: int) -> None:
|
||||
if not await bots.remove_bot(pool, bot_id):
|
||||
raise HTTPException(status_code=404, detail="unknown bot")
|
||||
await bots.notify_bots_changed(pool)
|
||||
|
||||
|
||||
@router.get("/{bot_id}/stats")
|
||||
async def stats(
|
||||
pool: FromDishka[asyncpg.Pool],
|
||||
bot_id: int,
|
||||
days: Annotated[int, Query()] = 90,
|
||||
senders: Annotated[int, Query()] = 20,
|
||||
) -> BotStats:
|
||||
result = await bots.stats(pool, bot_id, days=days, senders=senders)
|
||||
if result is None:
|
||||
raise HTTPException(status_code=404, detail="unknown bot")
|
||||
return result
|
||||
|
||||
|
||||
@router.get("/{bot_id}/updates")
|
||||
async def list_updates(
|
||||
pool: FromDishka[asyncpg.Pool],
|
||||
bot_id: int,
|
||||
sender_id: Annotated[int | None, Query()] = None,
|
||||
chat_id: Annotated[int | None, Query()] = None,
|
||||
incoming_only: Annotated[bool, Query()] = True,
|
||||
limit: Annotated[int, Query()] = DEFAULT_LIMIT,
|
||||
offset: Annotated[int, Query()] = 0,
|
||||
) -> list[BotUpdateView]:
|
||||
page = Page(limit=limit, offset=offset)
|
||||
return await bots.list_updates(
|
||||
pool,
|
||||
bot_id,
|
||||
sender_id=sender_id,
|
||||
chat_id=chat_id,
|
||||
incoming_only=incoming_only,
|
||||
limit=page.capped_limit,
|
||||
offset=page.offset,
|
||||
)
|
||||
Reference in new issue
Block a user