28e49b7dd03b074198a39428063e2993d2ee025b
[relay.git/.git] / relay / remote_actor.py
1 import aiohttp
2 from .database import DATABASE
3
4
5 ACTORS = DATABASE.get("actors", {})
6 async def fetch_actor(uri, force=False):
7     if uri in ACTORS and not force:
8         return ACTORS[uri]
9
10     async with aiohttp.ClientSession() as session:
11         async with session.get(uri, headers={'Accept': 'application/activity+json'}) as resp:
12             ACTORS[uri] = (await resp.json(encoding='utf-8', content_type=None))
13             DATABASE["actors"] = ACTORS
14             return ACTORS[uri]