pleroma-relay/relay/remote_actor.py

16 lines
549 B
Python
Raw Normal View History

2018-08-10 21:14:22 +00:00
import aiohttp
from .database import DATABASE
2018-11-18 00:07:36 +00:00
from .http_debug import http_debug
2018-08-10 21:14:22 +00:00
ACTORS = DATABASE.get("actors", {})
async def fetch_actor(uri, force=False):
if uri in ACTORS and not force:
return ACTORS[uri]
2018-11-18 00:07:36 +00:00
async with aiohttp.ClientSession(trace_configs=[http_debug()]) as session:
2018-08-10 21:14:22 +00:00
async with session.get(uri, headers={'Accept': 'application/activity+json'}) as resp:
2018-08-11 15:20:56 +00:00
ACTORS[uri] = (await resp.json(encoding='utf-8', content_type=None))
2018-08-10 21:14:22 +00:00
DATABASE["actors"] = ACTORS
return ACTORS[uri]