Make most of the HTTP requests async
This commit is contained in:
parent
3e17e17e2a
commit
d371e3cd4f
12 changed files with 88 additions and 82 deletions
|
@ -10,13 +10,13 @@ from app.database import AsyncSession
|
|||
|
||||
async def lookup(db_session: AsyncSession, query: str) -> Actor | RemoteObject:
|
||||
if query.startswith("@"):
|
||||
query = webfinger.get_actor_url(query) # type: ignore # None check below
|
||||
query = await webfinger.get_actor_url(query) # type: ignore # None check below
|
||||
|
||||
if not query:
|
||||
raise ap.NotAnObjectError(query)
|
||||
|
||||
try:
|
||||
ap_obj = ap.fetch(query)
|
||||
ap_obj = await ap.fetch(query)
|
||||
except ap.NotAnObjectError as not_an_object_error:
|
||||
resp = not_an_object_error.resp
|
||||
if not resp:
|
||||
|
@ -26,7 +26,7 @@ async def lookup(db_session: AsyncSession, query: str) -> Actor | RemoteObject:
|
|||
if resp.headers.get("content-type", "").startswith("text/html"):
|
||||
for alternate in mf2py.parse(doc=resp.text).get("alternates", []):
|
||||
if alternate.get("type") == "application/activity+json":
|
||||
alternate_obj = ap.fetch(alternate["url"])
|
||||
alternate_obj = await ap.fetch(alternate["url"])
|
||||
|
||||
if alternate_obj:
|
||||
ap_obj = alternate_obj
|
||||
|
@ -37,4 +37,4 @@ async def lookup(db_session: AsyncSession, query: str) -> Actor | RemoteObject:
|
|||
actor = await fetch_actor(db_session, ap_obj["id"])
|
||||
return actor
|
||||
else:
|
||||
return RemoteObject(ap_obj)
|
||||
return await RemoteObject.from_raw_object(ap_obj)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue