mirror of
https://github.com/simonw/datasette.git
synced 2026-09-03 07:04:16 +02:00
* ruff>=0.16.0 See https://astral.sh/blog/ruff-v0.16.0 * uv run ruff check . --fix --unsafe-fixes * Ruff fixes by Claude Code Opus 5
25 lines
734 B
Python
25 lines
734 B
Python
import time
|
|
|
|
from itsdangerous import BadSignature
|
|
|
|
from datasette import hookimpl
|
|
from datasette.utils import baseconv
|
|
|
|
|
|
@hookimpl
|
|
def actor_from_request(datasette, request):
|
|
if "ds_actor" not in request.cookies:
|
|
return None
|
|
try:
|
|
decoded = datasette.unsign(request.cookies["ds_actor"], "actor")
|
|
# If it has "e" and "a" keys process the "e" expiry
|
|
if not isinstance(decoded, dict) or "a" not in decoded:
|
|
return None
|
|
expires_at = decoded.get("e")
|
|
if expires_at:
|
|
timestamp = int(baseconv.base62.decode(expires_at))
|
|
if time.time() > timestamp:
|
|
return None
|
|
return decoded["a"]
|
|
except BadSignature:
|
|
return None
|