From a285fdf29e59c3b957247ea9241943c7202e9a28 Mon Sep 17 00:00:00 2001 From: Dennis Fink Date: Fri, 13 Nov 2026 21:20:40 +0100 Subject: 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. --- webmentions_ssg/tasks/receiver.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'webmentions_ssg/tasks/receiver.py') 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 -- cgit v1.3.1