31 lines
906 B
Python
31 lines
906 B
Python
"""Support-ticket helpers shared across user and admin routes."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import hashlib
|
|
import json
|
|
import re
|
|
|
|
_SPACE_RE = re.compile(r"\s+")
|
|
|
|
|
|
def _normalize_fingerprint_part(value: str | None) -> str:
|
|
return _SPACE_RE.sub(" ", (value or "").strip().lower())
|
|
|
|
|
|
def support_ticket_fingerprint(
|
|
*,
|
|
category: str,
|
|
subject: str,
|
|
body: str,
|
|
source_path: str,
|
|
) -> str:
|
|
"""Return a stable hash for exact-ish duplicate support-ticket hints."""
|
|
payload = {
|
|
"body": _normalize_fingerprint_part(body),
|
|
"category": _normalize_fingerprint_part(category),
|
|
"source_path": _normalize_fingerprint_part(source_path),
|
|
"subject": _normalize_fingerprint_part(subject),
|
|
}
|
|
encoded = json.dumps(payload, ensure_ascii=False, sort_keys=True, separators=(",", ":")).encode("utf-8")
|
|
return hashlib.sha256(encoded).hexdigest()
|