refactor/fectch actor
This commit is contained in:
parent
e32310da73
commit
3c9bf07566
2 changed files with 14 additions and 12 deletions
10
app/actor.py
10
app/actor.py
|
@ -1,5 +1,6 @@
|
|||
#!/usr/bin/env python3
|
||||
import typing
|
||||
import json
|
||||
from loguru import logger
|
||||
from app.database import AsyncSession
|
||||
from app import models
|
||||
|
@ -49,6 +50,15 @@ async def fetch_actor(
|
|||
ap_object = await ap.fetch(actor_id)
|
||||
exist_actor = await save_actor(ap_object, db_session)
|
||||
return exist_actor
|
||||
else:
|
||||
try:
|
||||
_actor = await ap.fetch(actor_id)
|
||||
exist_actor = await save_actor(_actor, db_session)
|
||||
except json.JSONDecodeError:
|
||||
raise ValueError
|
||||
except KeyError:
|
||||
logger.warning("actor gone? ")
|
||||
raise KeyError
|
||||
|
||||
return exist_actor
|
||||
|
||||
|
|
|
@ -9,6 +9,7 @@ from app.config import AP_CONTENT_TYPE, USER_AGENT
|
|||
|
||||
from app.database import AsyncSession
|
||||
from app.database import get_db_session
|
||||
from app.actor import fetch_actor
|
||||
from sqlalchemy import select
|
||||
|
||||
|
||||
|
@ -56,19 +57,10 @@ async def inbox_prechecker(
|
|||
except Exception:
|
||||
logger.exception("Failed to precheck delete activity")
|
||||
|
||||
actor_url = payload["actor"]
|
||||
async with httpx.AsyncClient() as client:
|
||||
resp = await client.get(
|
||||
actor_url,
|
||||
headers={
|
||||
"User-Agent": USER_AGENT,
|
||||
"Accept": AP_CONTENT_TYPE,
|
||||
},
|
||||
follow_redirects=True,
|
||||
)
|
||||
actor_id = payload["actor"]
|
||||
_actor = await fetch_actor(db_session, actor_id)
|
||||
|
||||
try:
|
||||
_actor = resp.json()
|
||||
pubkey = _actor["publicKey"]["publicKeyPem"]
|
||||
except json.JSONDecodeError:
|
||||
raise ValueError
|
||||
|
|
Loading…
Reference in a new issue