feat: WebSub with a built-in hub (v2.10.0)
ADR-071. Topics (/, /feed.atom, /feed.rss, /feed.json, /likes, /tag/<name>) advertise the hub and themselves in Link headers and embedded links. Note changes bump a content version (fresh feeds in every process) and queue deliveries. /websub accepts subscriptions for these topics only; the worker verifies intent, delivers signed content with retries, and prunes expired leases, all through the SSRF-safe pinned fetcher. WEBSUB_HUB_URL switches to an external hub (publish pings). Also: the memory monitor no longer stops after the first request; RSS self link is /feed.rss. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
720a1e6d6f
commit
b520b8b4d3
19 files changed
+1203
-29
No files matched your search
+33
-1
@@ -374,9 +374,28 @@ def create_note(
|
||||
# Reply context fetch failure should not prevent note creation
|
||||
current_app.logger.warning(f"Failed to fetch reply context for {in_reply_to}: {e}")
|
||||
|
||||
_websub_changed(note)
|
||||
return note
|
||||
|
||||
|
||||
def _tag_names(note_id: int) -> list[str]:
|
||||
"""A note's tag names, for WebSub tag topics (best effort)"""
|
||||
try:
|
||||
from starpunk.tags import get_note_tags
|
||||
return [t["name"] for t in get_note_tags(note_id)]
|
||||
except Exception:
|
||||
return []
|
||||
|
||||
|
||||
def _websub_changed(note, was_public: bool = False, old_tags=()) -> None:
|
||||
"""Clear cached feeds and queue WebSub deliveries (v2.10.0, best effort)"""
|
||||
try:
|
||||
from starpunk import websub
|
||||
websub.note_changed(note, was_public=was_public, old_tags=old_tags)
|
||||
except Exception as e:
|
||||
current_app.logger.warning(f"Failed to queue WebSub update for note {note.slug}: {e}")
|
||||
|
||||
|
||||
def get_note(
|
||||
slug: Optional[str] = None, id: Optional[int] = None, load_content: bool = True
|
||||
) -> Optional[Note]:
|
||||
@@ -705,6 +724,7 @@ def update_note(
|
||||
if existing_note is None:
|
||||
identifier = slug if slug is not None else id
|
||||
raise NoteNotFoundError(identifier)
|
||||
old_tag_names = _tag_names(existing_note.id) # for WebSub tag topics (v2.10.0)
|
||||
|
||||
if empty_content and not (existing_note.reacts_to or has_media):
|
||||
raise InvalidNoteDataError(
|
||||
@@ -896,6 +916,8 @@ def update_note(
|
||||
except Exception as e:
|
||||
current_app.logger.warning(f"Failed to queue syndication update: {e}")
|
||||
|
||||
_websub_changed(updated_note, was_public=existing_note.published, old_tags=old_tag_names)
|
||||
|
||||
# 10. RETURN UPDATED NOTE
|
||||
return updated_note
|
||||
|
||||
@@ -995,6 +1017,10 @@ def delete_note(
|
||||
# For idempotency, don't raise error - just return
|
||||
return
|
||||
|
||||
# What feeds showed before, for WebSub (v2.10.0)
|
||||
was_public = bool(existing_note.published) and not getattr(existing_note, "deleted_at", None)
|
||||
deleted_tags = _tag_names(existing_note.id)
|
||||
|
||||
# 4. SETUP
|
||||
data_dir = Path(current_app.config["DATA_PATH"])
|
||||
note_path = data_dir / existing_note.file_path
|
||||
@@ -1081,6 +1107,10 @@ def delete_note(
|
||||
except Exception as e:
|
||||
current_app.logger.warning(f"Failed to queue syndication delete: {e}")
|
||||
|
||||
# Feeds and pages no longer show it (v2.10.0)
|
||||
object.__setattr__(existing_note, "published", False)
|
||||
_websub_changed(existing_note, was_public=was_public, old_tags=deleted_tags)
|
||||
|
||||
# 6. RETURN (no value)
|
||||
return None
|
||||
|
||||
@@ -1137,4 +1167,6 @@ def undelete_note(slug: str) -> Note:
|
||||
except Exception as e:
|
||||
current_app.logger.warning(f"Failed to queue webmentions after undelete: {e}")
|
||||
|
||||
return get_note(slug=slug)
|
||||
restored = get_note(slug=slug)
|
||||
_websub_changed(restored)
|
||||
return restored
|
||||
Reference in new issue
Block a user