from fastapi import APIRouter, HTTPException, status from pydantic import BaseModel from starlette.concurrency import run_in_threadpool from app import f95 from app.deps import CurrentUser, has_perm router = APIRouter(prefix="/api/metadata", tags=["metadata"]) class F95In(BaseModel): url: str class MetaOut(BaseModel): url: str title: str description: str tags: list[str] @router.post("/f95", response_model=MetaOut) async def from_f95(body: F95In, user: CurrentUser) -> dict: if not (has_perm(user, "games.upload") or has_perm(user, "games.edit")): raise HTTPException(status.HTTP_403_FORBIDDEN, "Нет прав") try: return await run_in_threadpool(f95.load, body.url) except f95.F95Error as e: raise HTTPException(status.HTTP_422_UNPROCESSABLE_ENTITY, str(e))