Admin/uploader pastes a thread link and presses "Подтянуть" on the new game and edit forms; the backend reads the public first post (no login). Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
30 lines
829 B
Python
30 lines
829 B
Python
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))
|