add code to convert datetime into localtime into file list and add access quarys
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
from my_modules.app.constens import SECRET_KEY
|
||||
|
||||
import hmac, hashlib, base64, secrets, time
|
||||
from urllib.parse import quote, unquote
|
||||
from datetime import datetime, timezone
|
||||
|
||||
def base64url_encode(data: bytes) -> str:
|
||||
return base64.urlsafe_b64encode(data).decode().rstrip("=")
|
||||
@@ -27,6 +27,15 @@ def verify_signed_url(file_id: str, token: str, file_expiration: int) -> bool:
|
||||
not_expired = file_expiration >= time.time()
|
||||
return valid_sig and not_expired
|
||||
|
||||
def is_expired(expires_at):
|
||||
if not expires_at:
|
||||
return False
|
||||
if expires_at.tzinfo is None:
|
||||
expires_at = expires_at.replace(tzinfo=timezone.utc)
|
||||
else:
|
||||
expires_at = expires_at.astimezone(timezone.utc)
|
||||
return expires_at <= datetime.now(timezone.utc)
|
||||
|
||||
if __name__ == "__main__":
|
||||
file_id = generate_short_id()
|
||||
url = generate_signed_url(file_id)
|
||||
|
||||
Reference in New Issue
Block a user