generate longer file_ids and retry if they is a collison in the database
Build and Push Docker Container / build-and-push (push) Successful in 1m31s

This commit is contained in:
2025-10-25 15:45:13 +02:00
parent 85407ad86f
commit fe4526bfe0
4 changed files with 41 additions and 32 deletions
+7 -4
View File
@@ -1,6 +1,6 @@
from my_modules.app.constens import SECRET_KEY
import hmac, hashlib, base64, secrets, time
import hmac, hashlib, base64, secrets, string, time
from datetime import datetime, timezone
def base64url_encode(data: bytes) -> str:
@@ -10,9 +10,12 @@ def base64url_decode(data: str) -> bytes:
padding = '=' * (-len(data) % 4)
return base64.urlsafe_b64decode(data + padding)
def generate_short_id(length=8):
token = base64.urlsafe_b64encode(secrets.token_bytes(length)).decode('utf-8')
return token.replace('=', '').replace('-', '').replace('_', '')[:length]
def generate_short_id(length=11):
alphabet = string.ascii_letters + string.digits + '_-'
while True:
token = ''.join(secrets.choice(alphabet) for _ in range(length))
if not token.startswith('-'):
return token
def generate_signed_url(file_id: str) -> str:
# signature based only on the file_id