This commit is contained in:
2026-02-02 19:49:07 -08:00
parent 8d22ec5a81
commit 1e0000ae19
13 changed files with 297 additions and 988 deletions

View File

@@ -552,6 +552,32 @@ def add_direct_link_to_result(
setattr(result, "original_link", original_link)
def extract_hydrus_hash_from_url(url: str) -> str | None:
"""Extract SHA256 hash from Hydrus API URL.
Handles URLs like:
- http://localhost:45869/get_files/file?hash=abc123...
- URLs with &hash=abc123...
Args:
url: URL string to extract hash from
Returns:
Hash hex string (lowercase, 64 chars) if valid SHA256, None otherwise
"""
try:
import re
match = re.search(r"[?&]hash=([0-9a-fA-F]+)", str(url or ""))
if match:
hash_hex = match.group(1).strip().lower()
# Validate SHA256 (exactly 64 hex chars)
if re.fullmatch(r"[0-9a-f]{64}", hash_hex):
return hash_hex
except Exception:
pass
return None
# ============================================================================
# URL Policy Resolution - Consolidated from url_parser.py
# ============================================================================