feat: Microformats2 review fixes (v2.8.0)
- Responses as u-comment/u-like/u-repost/u-bookmark/u-mention h-cites with author h-cards; source's own url and published (migration 014) - dt-* and Micropub published in RFC 3339 UTC - Title only for a real Markdown heading (hashtag notes stay notes) - Ignore webmentions from a note's own syndicated copies - Micropub/IndieAuth links independent of Webmention; rel=me/rel=author - Representative h-card and authorship algorithm (starpunk/mf2_utils.py) - Tag/likes h-feeds get url and author; previews get u-uid Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
c8a7ef309f
commit
438465592c
21 files changed
+789
-273
No files matched your search
@@ -27,6 +27,7 @@ from lxml import html as lxml_html
|
||||
|
||||
from starpunk.webmention_processor import process_webmention, TransientError, ValidationError
|
||||
from starpunk.webmention_sender import note_responses_changed
|
||||
from starpunk.mf2_utils import normalize_url
|
||||
from starpunk.webmention_ssrf import (
|
||||
FetchTooLargeError, SSRFBlockedError, safe_get, safe_post, user_agent,
|
||||
)
|
||||
@@ -263,6 +264,23 @@ class WebmentionWorker(threading.Thread):
|
||||
except Exception as e:
|
||||
logger.warning(f"Failed to re-send webmentions for note {target_note_id}: {e}")
|
||||
|
||||
def _is_own_syndicated_copy(self, note_id: Optional[int], source_url: str,
|
||||
result: Dict[str, Any]) -> bool:
|
||||
"""True if the source is one of the note's own u-syndication copies"""
|
||||
if note_id is None:
|
||||
return False
|
||||
conn = sqlite3.connect(self.db_path)
|
||||
try:
|
||||
copies = {normalize_url(row[0]) for row in conn.execute(
|
||||
"SELECT remote_url FROM syndications WHERE note_id = ? AND remote_url IS NOT NULL",
|
||||
(note_id,),
|
||||
)}
|
||||
finally:
|
||||
conn.close()
|
||||
source = {normalize_url(u) for u in (
|
||||
source_url, result.get('source_post_url'), result.get('source_uid')) if u}
|
||||
return bool(copies & source)
|
||||
|
||||
def _display_state(self, webmention_id: int) -> Optional[tuple]:
|
||||
"""
|
||||
What the note page shows for this webmention, or None if hidden
|
||||
@@ -305,6 +323,11 @@ class WebmentionWorker(threading.Thread):
|
||||
# Process webmention (fetch, validate, extract)
|
||||
result = process_webmention(source_url, target_url, self.site_url)
|
||||
|
||||
# A copy of this very note on a silo (e.g. backfed by Bridgy) is
|
||||
# not a response to it
|
||||
if self._is_own_syndicated_copy(target_note_id, source_url, result):
|
||||
raise ValidationError("Source is this note's own syndicated copy")
|
||||
|
||||
# Update database with successful validation
|
||||
conn = sqlite3.connect(self.db_path)
|
||||
cursor = conn.cursor()
|
||||
@@ -330,6 +353,8 @@ class WebmentionWorker(threading.Thread):
|
||||
author_url = ?,
|
||||
author_photo = ?,
|
||||
content_snippet = ?,
|
||||
source_post_url = ?,
|
||||
source_published = ?,
|
||||
updated_at = CURRENT_TIMESTAMP
|
||||
WHERE id = ?
|
||||
""", (
|
||||
@@ -339,6 +364,8 @@ class WebmentionWorker(threading.Thread):
|
||||
result['author_url'],
|
||||
result['author_photo'],
|
||||
result['content_snippet'],
|
||||
result.get('source_post_url'),
|
||||
result.get('source_published'),
|
||||
webmention_id
|
||||
))
|
||||
|
||||
@@ -395,7 +422,7 @@ class WebmentionWorker(threading.Thread):
|
||||
# All other errors are 'error' status
|
||||
if transient:
|
||||
status = 'error'
|
||||
elif any(x in error.lower() for x in ['does not link', 'returned 4']):
|
||||
elif any(x in error.lower() for x in ['does not link', 'returned 4', 'own syndicated copy']):
|
||||
status = 'invalid'
|
||||
else:
|
||||
status = 'error'
|
||||
|
||||
Reference in new issue
Block a user