Short IDs become the canonical identifier in URLs (/i/:short_id), MinIO/R2 storage keys, and all API responses. Hash-based deduplication is preserved. Includes two-phase Alembic migration (003 adds nullable column, 004 enforces NOT NULL) with a backfill script to copy storage objects and populate short_id for existing images. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
14 lines
292 B
Python
14 lines
292 B
Python
import hashlib
|
|
import secrets
|
|
import string
|
|
|
|
BASE62 = string.ascii_letters + string.digits
|
|
|
|
|
|
def compute_sha256(data: bytes) -> str:
|
|
return hashlib.sha256(data).hexdigest()
|
|
|
|
|
|
def generate_short_id(length: int = 8) -> str:
|
|
return "".join(secrets.choice(BASE62) for _ in range(length))
|