feat: Crosspost notes to GoToSocial (v2.1.0)

Published notes are copied to a GoToSocial (Mastodon-API) account and
edits, unpublishing and deletes follow them (ADR-065). On by default for
new notes, untickable in the editor and selectable from Micropub via
mp-syndicate-to. A background worker reconciles each (note, target)
row with atomic claims, an idempotency key and a version so edits during
a send are not lost. Synced copies are linked with u-syndication.

Also fixes the Micropub Location header and search result links, which
pointed at /notes/<slug> (404), and the nested delete form on the edit
page.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
PhilandClaude Opus 5.5 committed 2026-10-31 12:46:26 -06:00
1 parent 94e8c672df
commit 57b02ad6c7
19 files changed
+1049 -25

No files matched your search

+31 -9
View File
@@ -30,6 +30,7 @@ from flask import Request, current_app, jsonify
from starpunk.notes import create_note, get_note, InvalidNoteDataError, NoteNotFoundError
from starpunk.indieauth import check_scope
from starpunk.utils import absolute_url_for
# Custom Exceptions
@@ -398,6 +399,17 @@ def handle_create(data: dict, token_info: dict):
elif isinstance(slug_value, str):
custom_slug = slug_value
# mp-syndicate-to is also a server command, not a property (v2.1.0).
# Absent means "all targets"; present means exactly those.
requested_targets = None
if isinstance(data, dict):
for key in ("mp-syndicate-to", "mp-syndicate-to[]"):
if key in data:
value = data[key]
requested_targets = (requested_targets or []) + (
value if isinstance(value, list) else [value]
)
# Normalize and extract properties
try:
properties = normalize_properties(data)
@@ -427,10 +439,14 @@ def handle_create(data: dict, token_info: dict):
if photos:
_attach_photos_to_note(note.id, photos)
# Build permalink URL
# Note: SITE_URL is normalized to include trailing slash (for IndieAuth spec compliance)
site_url = current_app.config.get("SITE_URL", "http://localhost:5000")
permalink = f"{site_url}notes/{note.slug}"
# Crosspost after photos are attached (v2.1.0)
from starpunk.syndication import get_targets, resolve_targets, select_targets
if requested_targets is None:
select_targets(note.id, list(get_targets()))
else:
select_targets(note.id, resolve_targets(requested_targets))
permalink = absolute_url_for("public.note", slug=note.slug)
# Return 201 Created with Location header
return "", 201, {"Location": permalink}
@@ -444,6 +460,13 @@ def handle_create(data: dict, token_info: dict):
)
def _syndicate_to() -> list:
"""Configured crosspost targets in Micropub syndicate-to form"""
from starpunk.syndication import get_targets
return [{"uid": t.uid, "name": t.name} for t in get_targets().values()]
def handle_query(args: dict, token_info: dict):
"""
Handle Micropub query endpoints
@@ -451,7 +474,7 @@ def handle_query(args: dict, token_info: dict):
Supports:
- q=config: Return server configuration
- q=source: Return post source in Microformats2 JSON
- q=syndicate-to: Return syndication targets (empty for V1)
- q=syndicate-to: Return syndication targets
Args:
args: Query string arguments
@@ -467,7 +490,7 @@ def handle_query(args: dict, token_info: dict):
site_url = current_app.config.get("SITE_URL", "http://localhost:5000").rstrip('/')
config = {
"media-endpoint": f"{site_url}/micropub/media",
"syndicate-to": [], # No syndication targets in V1
"syndicate-to": _syndicate_to(),
"post-types": [
{"type": "note", "name": "Note", "properties": ["content"]},
{"type": "photo", "name": "Photo", "properties": ["photo"]}
@@ -483,7 +506,7 @@ def handle_query(args: dict, token_info: dict):
# Extract slug from URL
try:
# URL format: https://example.com/notes/{slug}
# URL format: https://example.com/note/{slug}
slug = url.rstrip("/").split("/")[-1]
note = get_note(slug)
@@ -520,8 +543,7 @@ def handle_query(args: dict, token_info: dict):
return jsonify(mf2), 200
elif q == "syndicate-to":
# Return syndication targets (none for V1)
return jsonify({"syndicate-to": []}), 200
return jsonify({"syndicate-to": _syndicate_to()}), 200
else:
return error_response("invalid_request", f"Unknown query: {q}")