refactor/send post
This commit is contained in:
parent
b97e79b61b
commit
8c6329b06d
3 changed files with 28 additions and 19 deletions
|
@ -1,6 +1,10 @@
|
|||
#!/usr/bin/env python3
|
||||
import httpx
|
||||
|
||||
from app import config
|
||||
from app.key import get_pubkey_as_pem
|
||||
from app.httpsig import auth
|
||||
from loguru import logger
|
||||
|
||||
|
||||
RawObject = dict
|
||||
|
@ -69,3 +73,22 @@ ME = {
|
|||
},
|
||||
"tag": [] # TODO
|
||||
}
|
||||
|
||||
async def post(
|
||||
url: str,
|
||||
payload : dict,
|
||||
) -> httpx.Response :
|
||||
logger.info(f"send post, {payload=}")
|
||||
|
||||
async with httpx.AsyncClient() as client:
|
||||
resp = await client.post(
|
||||
url,
|
||||
headers={
|
||||
"User-Agent": config.USER_AGENT,
|
||||
"Content-Type": config.AP_CONTENT_TYPE,
|
||||
},
|
||||
json=payload,
|
||||
auth=auth,
|
||||
)
|
||||
|
||||
return resp
|
||||
|
|
22
app/boxes.py
22
app/boxes.py
|
@ -5,14 +5,10 @@ from app.activitypub import ME
|
|||
from loguru import logger
|
||||
from uuid import uuid4
|
||||
from app.config import MANUALLY_APPROVES_FOLLOWERS
|
||||
from app.config import AP_CONTENT_TYPE
|
||||
from app.config import BASE_URL
|
||||
from app.config import USER_AGENT
|
||||
from app.httpsig import auth
|
||||
|
||||
import app.activitypub as ap
|
||||
import uuid
|
||||
import httpx
|
||||
|
||||
|
||||
def allocate_outbox_id() -> str:
|
||||
|
@ -79,6 +75,8 @@ async def _send_accept(
|
|||
) -> None :
|
||||
|
||||
reply_id = allocate_outbox_id()
|
||||
|
||||
url = ap_object["actor"] + "/inbox"
|
||||
out = {
|
||||
"@context": ap.AS_CTX,
|
||||
"id": build_object_id(reply_id),
|
||||
|
@ -86,17 +84,5 @@ async def _send_accept(
|
|||
"actor": ME["id"],
|
||||
"object": ap_object["id"],
|
||||
}
|
||||
|
||||
async with httpx.AsyncClient() as client:
|
||||
resp = await client.post(
|
||||
ap_object["actor"] + "/inbox",
|
||||
headers={
|
||||
"User-Agent": USER_AGENT,
|
||||
"Content-Type": AP_CONTENT_TYPE,
|
||||
},
|
||||
json=out,
|
||||
auth=auth,
|
||||
)
|
||||
|
||||
resp.raise_for_status()
|
||||
logger.info(resp)
|
||||
#TODO outcoming
|
||||
await ap.post(url, out)
|
||||
|
|
|
@ -149,7 +149,7 @@ class HTTPXSigAuth(httpx.Auth):
|
|||
bh.update(r.content)
|
||||
bodydigest = "SHA-256=" + base64.b64encode(bh.digest()).decode("utf-8")
|
||||
|
||||
date = datetime.utcnow().strftime("%Y %m %d %H:%M:%S GMT")
|
||||
date = datetime.utcnow().strftime("%Y-%m-%d %H:%M:%S GMT")
|
||||
r.headers["Date"] = date
|
||||
sigheaders = {}
|
||||
if bodydigest:
|
||||
|
|
Loading…
Reference in a new issue