[refactor] rewrite post in hylang
All checks were successful
/ run-pytest (push) Successful in 2m29s
All checks were successful
/ run-pytest (push) Successful in 2m29s
This commit is contained in:
parent
ce4ab247e7
commit
fee55145d9
2 changed files with 16 additions and 3 deletions
|
@ -17,6 +17,7 @@ from app.actor import fetch_actor
|
||||||
from app.httpsig import k
|
from app.httpsig import k
|
||||||
|
|
||||||
import app.activitypub as ap
|
import app.activitypub as ap
|
||||||
|
from app.hyap import post # type: ignore
|
||||||
|
|
||||||
from urllib.parse import urlparse
|
from urllib.parse import urlparse
|
||||||
from sqlalchemy import select
|
from sqlalchemy import select
|
||||||
|
@ -306,7 +307,7 @@ async def _send_accept(
|
||||||
relates_to_actor_id=actor.id, # type: ignore
|
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:
|
except Exception as e:
|
||||||
logger.error(e)
|
logger.error(e)
|
||||||
|
|
||||||
|
@ -411,7 +412,7 @@ async def _send_follow(
|
||||||
activity_object_ap_id=actor.ap_id
|
activity_object_ap_id=actor.ap_id
|
||||||
)
|
)
|
||||||
|
|
||||||
await ap.post(
|
await post(
|
||||||
actor.inbox_url,
|
actor.inbox_url,
|
||||||
out,
|
out,
|
||||||
)
|
)
|
||||||
|
@ -470,7 +471,7 @@ async def _send_create(
|
||||||
ldsig.generate_signature(ap_object, k)
|
ldsig.generate_signature(ap_object, k)
|
||||||
|
|
||||||
for r in recipients:
|
for r in recipients:
|
||||||
await ap.post(
|
await post(
|
||||||
r,
|
r,
|
||||||
ap_object,
|
ap_object,
|
||||||
)
|
)
|
||||||
|
|
12
app/hyap.hy
12
app/hyap.hy
|
@ -2,6 +2,8 @@
|
||||||
(import httpx)
|
(import httpx)
|
||||||
(import loguru [logger])
|
(import loguru [logger])
|
||||||
(import app [config])
|
(import app [config])
|
||||||
|
(import app.httpsig [auth])
|
||||||
|
|
||||||
|
|
||||||
(defn/a fetch
|
(defn/a fetch
|
||||||
[url]
|
[url]
|
||||||
|
@ -11,3 +13,13 @@
|
||||||
(let [headers {"User-Agent" config.USER_AGENT
|
(let [headers {"User-Agent" config.USER_AGENT
|
||||||
"Accept" config.AP_CONTENT_TYPE}]
|
"Accept" config.AP_CONTENT_TYPE}]
|
||||||
(await (.get client url :headers headers)))))))
|
(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))))
|
||||||
|
|
Loading…
Reference in a new issue