mirror of
https://git.sr.ht/~tsileo/microblog.pub
synced 2024-12-22 05:04:27 +00:00
Support creating note via C2S
This commit is contained in:
parent
ed214cf0e7
commit
0b86df413a
3 changed files with 35 additions and 5 deletions
|
@ -1182,7 +1182,7 @@ async def admin_actions_new(
|
||||||
elif name:
|
elif name:
|
||||||
ap_type = "Article"
|
ap_type = "Article"
|
||||||
|
|
||||||
public_id = await boxes.send_create(
|
public_id, _ = await boxes.send_create(
|
||||||
db_session,
|
db_session,
|
||||||
ap_type=ap_type,
|
ap_type=ap_type,
|
||||||
source=content,
|
source=content,
|
||||||
|
|
|
@ -592,7 +592,7 @@ async def send_create(
|
||||||
poll_answers: list[str] | None = None,
|
poll_answers: list[str] | None = None,
|
||||||
poll_duration_in_minutes: int | None = None,
|
poll_duration_in_minutes: int | None = None,
|
||||||
name: str | None = None,
|
name: str | None = None,
|
||||||
) -> str:
|
) -> tuple[str, models.OutboxObject]:
|
||||||
note_id = allocate_outbox_id()
|
note_id = allocate_outbox_id()
|
||||||
published = now().replace(microsecond=0).isoformat().replace("+00:00", "Z")
|
published = now().replace(microsecond=0).isoformat().replace("+00:00", "Z")
|
||||||
context = f"{ID}/contexts/" + uuid.uuid4().hex
|
context = f"{ID}/contexts/" + uuid.uuid4().hex
|
||||||
|
@ -767,7 +767,7 @@ async def send_create(
|
||||||
|
|
||||||
await db_session.commit()
|
await db_session.commit()
|
||||||
|
|
||||||
return note_id
|
return note_id, outbox_object
|
||||||
|
|
||||||
|
|
||||||
async def send_vote(
|
async def send_vote(
|
||||||
|
|
32
app/main.py
32
app/main.py
|
@ -632,7 +632,7 @@ async def outbox(
|
||||||
|
|
||||||
|
|
||||||
@app.post("/outbox")
|
@app.post("/outbox")
|
||||||
async def post_inbox(
|
async def post_outbox(
|
||||||
request: Request,
|
request: Request,
|
||||||
db_session: AsyncSession = Depends(get_db_session),
|
db_session: AsyncSession = Depends(get_db_session),
|
||||||
access_token_info: indieauth.AccessTokenInfo = Depends(
|
access_token_info: indieauth.AccessTokenInfo = Depends(
|
||||||
|
@ -641,8 +641,38 @@ async def post_inbox(
|
||||||
) -> ActivityPubResponse:
|
) -> ActivityPubResponse:
|
||||||
payload = await request.json()
|
payload = await request.json()
|
||||||
logger.info(f"{payload=}")
|
logger.info(f"{payload=}")
|
||||||
|
|
||||||
|
if payload.get("type") == "Create":
|
||||||
|
assert payload["actor"] == ID
|
||||||
|
obj = payload["object"]
|
||||||
|
|
||||||
|
to_and_cc = obj.get("to", []) + obj.get("cc", [])
|
||||||
|
if ap.AS_PUBLIC in obj.get("to", []) and ID + "/followers" in to_and_cc:
|
||||||
|
visibility = ap.VisibilityEnum.PUBLIC
|
||||||
|
elif ap.AS_PUBLIC in to_and_cc and ID + "/followers" in to_and_cc:
|
||||||
|
visibility = ap.VisibilityEnum.UNLISTED
|
||||||
|
else:
|
||||||
|
visibility = ap.VisibilityEnum.DIRECT
|
||||||
|
|
||||||
|
object_id, outbox_object = await boxes.send_create(
|
||||||
|
db_session,
|
||||||
|
ap_type=obj["type"],
|
||||||
|
source=obj["content"],
|
||||||
|
uploads=[],
|
||||||
|
in_reply_to=obj.get("inReplyTo"),
|
||||||
|
visibility=visibility,
|
||||||
|
content_warning=obj.get("summary"),
|
||||||
|
is_sensitive=obj.get("sensitive", False),
|
||||||
|
)
|
||||||
|
else:
|
||||||
raise ValueError("TODO")
|
raise ValueError("TODO")
|
||||||
|
|
||||||
|
return ActivityPubResponse(
|
||||||
|
outbox_object.ap_object,
|
||||||
|
status_code=201,
|
||||||
|
headers={"Location": boxes.outbox_object_id(object_id)},
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
@app.get("/featured")
|
@app.get("/featured")
|
||||||
async def featured(
|
async def featured(
|
||||||
|
|
Loading…
Reference in a new issue