feat: Micropub review fixes (v2.9.0)
- mp-syndicate-to/mp-slug read from JSON properties; absent means no
crossposting
- Sanitize rendered HTML (nh3 allowlist)
- q=source/q=category need a posting scope; draft scope creates drafts;
private/unlisted visibility saved as drafts
- Photos that can't be fetched or found fail the request; remote photos
via the SSRF-checked, pinned fetcher
- JSON scalars wrapped, update delete values must be arrays
- bookmark-of stored; HTML content returned as {html} (migration 015)
- published stored as UTC, bad dates 400; malformed JSON 400
- Auth: case-insensitive Bearer, header+body 400, WWW-Authenticate
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
57682165a4
commit
ab6ff60f5c
19 files changed
+610
-122
No files matched your search
+28
-10
@@ -133,6 +133,10 @@ def _get_existing_slugs(db) -> set[str]:
|
||||
# Core CRUD Functions
|
||||
|
||||
|
||||
# update_note: leave a field as it is
|
||||
UNCHANGED = object()
|
||||
|
||||
|
||||
def create_note(
|
||||
content: str,
|
||||
published: bool = False,
|
||||
@@ -143,6 +147,8 @@ def create_note(
|
||||
like_of: Optional[str] = None,
|
||||
repost_of: Optional[str] = None,
|
||||
has_media: bool = False,
|
||||
bookmark_of: Optional[str] = None,
|
||||
content_format: Optional[str] = None,
|
||||
) -> Note:
|
||||
"""
|
||||
Create a new note
|
||||
@@ -207,10 +213,13 @@ def create_note(
|
||||
"""
|
||||
# 1. VALIDATION (before any changes)
|
||||
# Likes and reposts may have no comment (v2.5.0), photo posts no text (v2.6.5)
|
||||
if like_of and repost_of:
|
||||
raise InvalidNoteDataError("like_of", like_of, "A note can't be both a like and a repost")
|
||||
# Bookmarks too (v2.9.0)
|
||||
if sum(bool(u) for u in (like_of, repost_of, bookmark_of)) > 1:
|
||||
raise InvalidNoteDataError(
|
||||
"like_of", like_of, "A note can only be one of a like, repost or bookmark"
|
||||
)
|
||||
content = content or ""
|
||||
if not content.strip() and not (like_of or repost_of or has_media):
|
||||
if not content.strip() and not (like_of or repost_of or bookmark_of or has_media):
|
||||
raise InvalidNoteDataError(
|
||||
"content", content, "Content cannot be empty or whitespace-only"
|
||||
)
|
||||
@@ -271,10 +280,12 @@ def create_note(
|
||||
try:
|
||||
db.execute(
|
||||
"""
|
||||
INSERT INTO notes (slug, file_path, published, created_at, updated_at, content_hash, in_reply_to, like_of, repost_of)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)
|
||||
INSERT INTO notes (slug, file_path, published, created_at, updated_at, content_hash,
|
||||
in_reply_to, like_of, repost_of, bookmark_of, content_format)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
||||
""",
|
||||
(slug, file_path_rel, published, created_at, updated_at, content_hash, in_reply_to, like_of, repost_of),
|
||||
(slug, file_path_rel, published, created_at, updated_at, content_hash,
|
||||
in_reply_to, like_of, repost_of, bookmark_of, content_format),
|
||||
)
|
||||
db.commit()
|
||||
except Exception as e:
|
||||
@@ -342,7 +353,7 @@ def create_note(
|
||||
note_id=note_id,
|
||||
note_url=note_url,
|
||||
content_html=html_content,
|
||||
in_reply_to=in_reply_to or like_of or repost_of
|
||||
in_reply_to=in_reply_to or like_of or repost_of or bookmark_of
|
||||
)
|
||||
except Exception as e:
|
||||
# Webmention queueing failure should not prevent note creation
|
||||
@@ -350,7 +361,7 @@ def create_note(
|
||||
|
||||
# 12. FETCH REPLY CONTEXT (v1.6.0 Phase 3)
|
||||
# Fetch context for the post being replied to, liked or reposted
|
||||
context_url = in_reply_to or like_of or repost_of
|
||||
context_url = in_reply_to or like_of or repost_of or bookmark_of
|
||||
if context_url:
|
||||
try:
|
||||
from starpunk.reply_context import fetch_reply_context
|
||||
@@ -607,10 +618,13 @@ def update_note(
|
||||
tags: Optional[list[str]] = None,
|
||||
in_reply_to: Optional[str] = None,
|
||||
has_media: bool = False,
|
||||
content_format=UNCHANGED,
|
||||
) -> Note:
|
||||
"""
|
||||
Update a note's content and/or published status
|
||||
|
||||
content_format (v2.9.0): 'html' or None (Markdown); left alone unless given
|
||||
|
||||
Updates note content and/or metadata, maintaining atomic synchronization
|
||||
between file and database. At least one of content or published must
|
||||
be provided.
|
||||
@@ -692,7 +706,7 @@ def update_note(
|
||||
identifier = slug if slug is not None else id
|
||||
raise NoteNotFoundError(identifier)
|
||||
|
||||
if empty_content and not (existing_note.like_of or existing_note.repost_of or has_media):
|
||||
if empty_content and not (existing_note.reacts_to or has_media):
|
||||
raise InvalidNoteDataError(
|
||||
"content", content, "Content cannot be empty or whitespace-only"
|
||||
)
|
||||
@@ -756,6 +770,10 @@ def update_note(
|
||||
update_fields.append("in_reply_to = ?")
|
||||
params.append(in_reply_to)
|
||||
|
||||
if content_format is not UNCHANGED:
|
||||
update_fields.append("content_format = ?")
|
||||
params.append(content_format)
|
||||
|
||||
# Add WHERE clause parameter
|
||||
if slug is not None:
|
||||
where_clause = "slug = ?"
|
||||
@@ -841,7 +859,7 @@ def update_note(
|
||||
html_content = updated_note.html if updated_note.published else None
|
||||
|
||||
# Determine in_reply_to (use new value if provided, otherwise existing)
|
||||
reply_to = (in_reply_to if in_reply_to is not None else updated_note.in_reply_to) or updated_note.like_of or updated_note.repost_of
|
||||
reply_to = (in_reply_to if in_reply_to is not None else updated_note.in_reply_to) or updated_note.reacts_to
|
||||
|
||||
# Queue webmentions (best-effort)
|
||||
# Pass old_html for URL diffing (Phase 6)
|
||||
|
||||
Reference in new issue
Block a user