diff --git a/app/boxes.py b/app/boxes.py index 5467d10..efa2e5b 100644 --- a/app/boxes.py +++ b/app/boxes.py @@ -17,6 +17,7 @@ from app.actor import fetch_actor from app.httpsig import k import app.activitypub as ap +from app.hyap import post # type: ignore from urllib.parse import urlparse from sqlalchemy import select @@ -306,7 +307,7 @@ async def _send_accept( relates_to_actor_id=actor.id, # type: ignore ) - await ap.post(url, out) # type: ignore + await post(url, out) # type: ignore except Exception as e: logger.error(e) @@ -411,7 +412,7 @@ async def _send_follow( activity_object_ap_id=actor.ap_id ) - await ap.post( + await post( actor.inbox_url, out, ) @@ -470,7 +471,7 @@ async def _send_create( ldsig.generate_signature(ap_object, k) for r in recipients: - await ap.post( + await post( r, ap_object, ) diff --git a/app/hyap.hy b/app/hyap.hy index 5f4781c..d25b221 100644 --- a/app/hyap.hy +++ b/app/hyap.hy @@ -2,6 +2,8 @@ (import httpx) (import loguru [logger]) (import app [config]) +(import app.httpsig [auth]) + (defn/a fetch [url] @@ -11,3 +13,13 @@ (let [headers {"User-Agent" config.USER_AGENT "Accept" config.AP_CONTENT_TYPE}] (await (.get client url :headers headers))))))) + +(defn/a post + [url payload] + (with/a [client (.AsyncClient httpx)] + (let [headers {"User-Agent" config.USER_AGENT + "Accept" config.AP_CONTENT_TYPE}] + (setv resp + (await (.post client url :headers headers :json payload :auth auth))) + (.raise_for_status resp) + (return resp))))