ff
This commit is contained in:
26
SYS/utils.py
26
SYS/utils.py
@@ -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
|
||||
# ============================================================================
|
||||
|
||||
Reference in New Issue
Block a user