"""Link expiry policy. -1 is a persistent no-expiry sentinel, not a timestamp.""" from fastapi import HTTPException from .config import settings NEVER_EXPIRES = -1 def expiration(expires_in, now): if expires_in == NEVER_EXPIRES: return NEVER_EXPIRES ttl = settings().link_ttl if expires_in is None else expires_in if ttl <= 0 or ttl > settings().link_ttl: raise HTTPException(422, {'code': 'invalid_expiry', 'message': 'expires_in must be -1 (no expiry) or positive seconds within the configured lifetime'}) return now + ttl