aboutsummaryrefslogtreecommitdiff
path: root/webmentions_ssg/tasks/receiver.py
diff options
context:
space:
mode:
authorDennis Fink2026-11-13 21:20:40 +0100
committerDennis Fink2026-11-13 21:20:40 +0100
commita285fdf29e59c3b957247ea9241943c7202e9a28 (patch)
tree17ceeb703de23af1e67081d99a8864bbe353fb46 /webmentions_ssg/tasks/receiver.py
parent78ecd8bc227bdcbbd0e45eea025f7223252ed0da (diff)
downloadwebmentions-ssg-a285fdf29e59c3b957247ea9241943c7202e9a28.tar.gz
webmentions-ssg-a285fdf29e59c3b957247ea9241943c7202e9a28.zip
refactor(core): consolidate repeated helper logic
Centralize SQL row counts, hostname parsing, and content-type normalization so tasks, forms, and scanners share consistent implementations. Simplify periodic task registration and admin lookups with table-driven setup and Flask-SQLAlchemy's built-in 404 helper.
Diffstat (limited to '')
-rw-r--r--webmentions_ssg/tasks/receiver.py11
1 files changed, 5 insertions, 6 deletions
diff --git a/webmentions_ssg/tasks/receiver.py b/webmentions_ssg/tasks/receiver.py
index 78089af..1df363f 100644
--- a/webmentions_ssg/tasks/receiver.py
+++ b/webmentions_ssg/tasks/receiver.py
@@ -7,12 +7,12 @@
import uuid
from datetime import UTC, datetime, timedelta
from http import HTTPStatus
-from typing import Any, cast
import httpx
import sqlalchemy as sa
from flask import current_app
+from ..db_helpers import rows_affected
from ..extensions import db, huey
from ..models import ReceivedStatus, ReceivedWebmention
from ..net import (
@@ -20,6 +20,7 @@ from ..net import (
ResponseTooLargeError,
UnsafeAddressError,
build_client,
+ content_type_of,
is_temporary_status,
read_limited_body,
)
@@ -103,9 +104,7 @@ def source_mentions_target(source_url: str, target_url: str) -> bool:
"""
response, body = fetch_source(source_url)
- media_type = (
- response.headers.get("Content-Type", "").partition(";")[0].strip().lower()
- )
+ media_type = content_type_of(response.headers)
match media_type:
case "text/html" | "application/xhtml+xml":
@@ -172,7 +171,7 @@ def verify_webmention(webmention_uuid: uuid.UUID) -> None:
)
)
- if cast(sa.CursorResult[Any], claimed).rowcount != 1:
+ if rows_affected(claimed) != 1:
db.session.rollback()
return
@@ -285,7 +284,7 @@ def recover_stale_webmentions() -> int:
)
)
- if cast(sa.CursorResult[Any], changed).rowcount != 1:
+ if rows_affected(changed) != 1:
db.session.rollback()
continue