feat/fetch actor
This commit is contained in:
parent
0ff423cf9b
commit
2b9d974c80
2 changed files with 37 additions and 10 deletions
|
@ -92,3 +92,19 @@ async def post(
|
|||
)
|
||||
|
||||
return resp
|
||||
|
||||
async def fetch(
|
||||
url: str,
|
||||
) -> dict:
|
||||
logger.info(f"fetch {url}")
|
||||
|
||||
async with httpx.AsyncClient() as client:
|
||||
resp = await client.get(
|
||||
url,
|
||||
headers={
|
||||
"User-Agent": config.USER_AGENT,
|
||||
"Accept": config.AP_CONTENT_TYPE,
|
||||
},
|
||||
)
|
||||
|
||||
return resp.json()
|
||||
|
|
31
app/boxes.py
31
app/boxes.py
|
@ -1,14 +1,22 @@
|
|||
#!/usr/bin/env python3
|
||||
from typing import Any
|
||||
import uuid
|
||||
|
||||
from app import models
|
||||
from app.database import AsyncSession
|
||||
from app.activitypub import ME
|
||||
from loguru import logger
|
||||
from uuid import uuid4
|
||||
from app.config import MANUALLY_APPROVES_FOLLOWERS
|
||||
from app.config import BASE_URL
|
||||
from app.models import Actor
|
||||
from app.actor import fetch_actor
|
||||
|
||||
import app.activitypub as ap
|
||||
import uuid
|
||||
|
||||
|
||||
from sqlalchemy import select
|
||||
from loguru import logger
|
||||
from uuid import uuid4
|
||||
|
||||
|
||||
|
||||
def allocate_outbox_id() -> str:
|
||||
|
@ -49,39 +57,42 @@ async def process_incoming(
|
|||
db_session: AsyncSession,
|
||||
ap_object: dict,
|
||||
) -> bool:
|
||||
actor = await fetch_actor(ap_object["actor"], db_session)
|
||||
|
||||
if "Follow" == ap_object["type"]:
|
||||
await _handle_follow(db_session, ap_object)
|
||||
await _handle_follow(db_session, actor.ap_actor["inbox"], ap_object)
|
||||
return True
|
||||
|
||||
return False
|
||||
|
||||
|
||||
async def _handle_follow(
|
||||
db_session: AsyncSession,
|
||||
ap_object: dict,
|
||||
db_session : AsyncSession,
|
||||
inbox_url : str | Any,
|
||||
ap_object : dict,
|
||||
) -> bool:
|
||||
if ME["id"] != ap_object["object"]:
|
||||
# await db_session.delete(ap_object)
|
||||
logger.warning("no match follow object!" + ap_object["object"])
|
||||
logger.warning("no match follow object!" + ap_object["id"])
|
||||
return False
|
||||
|
||||
if MANUALLY_APPROVES_FOLLOWERS:
|
||||
# TODO
|
||||
return False
|
||||
|
||||
await _send_accept(db_session, ap_object)
|
||||
await _send_accept(db_session, inbox_url, ap_object)
|
||||
return True
|
||||
|
||||
|
||||
async def _send_accept(
|
||||
db_session: AsyncSession,
|
||||
ap_object: dict,
|
||||
inbox_url : str | Any,
|
||||
ap_object : dict,
|
||||
) -> None :
|
||||
|
||||
reply_id = allocate_outbox_id()
|
||||
|
||||
url = ap_object["actor"] + "/inbox"
|
||||
url = inbox_url
|
||||
out = {
|
||||
"@context": ap.AS_CTX,
|
||||
"id": build_object_id(reply_id),
|
||||
|
|
Loading…
Reference in a new issue