Эх сурвалжийг харах

normalize using base32 hash

Daniel Sheffield 1 жил өмнө
parent
commit
8fce91b02a

+ 5 - 5
app/rest/route_decorators.py

@@ -11,12 +11,12 @@ from psycopg.connection import TupleRow
 
 from ..data.filter import get_filter, get_query_param
 from . import BOOLEAN, PARAMS
-from .Cache import Cache
-from .hash_util import hash_to_hex, normalize_hex
+from .Cache import Cache, get_hash
+from .hash_util import base32_to_hash, hash_to_base32, normalize_base32
 
 def normalize_query(query: FormsDict, allow: Iterable[str] = None) -> str:
     if 'hash' in query and query.hash:
-        _hex = normalize_hex(query.hash)
+        _hex = normalize_base32(query.hash)
         return f'hash={_hex}'
     allow = allow or PARAMS
     param = get_filter(query, allow=allow)
@@ -27,7 +27,7 @@ def normalize_query(query: FormsDict, allow: Iterable[str] = None) -> str:
             "organic", BOOLEAN[BOOLEAN.get(query.organic, None)]
         ) for k in sorted(param) if param[k]
     ])
-    return norm if len(norm) < 2000 else f'hash={hash_to_hex(hash(norm))}'
+    return norm if len(norm) < 2000 else f'hash={hash_to_base32(get_hash(norm))}'
 
 def _normalize_decorator(func: Callable, allow=None):
     def wrap(*args, **kwargs):
@@ -37,7 +37,7 @@ def _normalize_decorator(func: Callable, allow=None):
             return redirect(f'{path}?{normalized}', 307)
         
         _hash = request.params.hash
-        key = _hash if _hash else request.query_string
+        key = base32_to_hash(_hash) if _hash else request.query_string
         return func(key, request.forms if _hash else request.query, *args, **kwargs)
     return wrap