- Add Pillow dependency and thumbnail.py with generate_thumbnail() — produces
WebP ≤400px, preserves aspect ratio, never upscales, handles GIF frame 0
- Alembic migration 002 adds nullable thumbnail_key column to images table
- Upload route generates thumbnail via asyncio.to_thread (non-blocking),
stores at {hash}-thumb; failure is tolerated and upload succeeds with null key
- New GET /api/v1/images/{id}/thumbnail endpoint: serves WebP thumbnail or
falls back to original for pre-feature images; ETag + immutable cache headers
- Delete route cleans up thumbnail storage object alongside original
- Library grid switches from /file to /thumbnail for all image src bindings
- 59 tests passing (46 existing + 13 new across unit, upload, serving, delete)
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
24 lines
532 B
Python
24 lines
532 B
Python
"""add thumbnail_key column to images
|
|
|
|
Revision ID: 002
|
|
Revises: 001
|
|
Create Date: 2026-05-03
|
|
|
|
"""
|
|
from typing import Sequence, Union
|
|
import sqlalchemy as sa
|
|
from alembic import op
|
|
|
|
revision: str = "002"
|
|
down_revision: Union[str, None] = "001"
|
|
branch_labels: Union[str, Sequence[str], None] = None
|
|
depends_on: Union[str, Sequence[str], None] = None
|
|
|
|
|
|
def upgrade() -> None:
|
|
op.add_column("images", sa.Column("thumbnail_key", sa.String(70), nullable=True))
|
|
|
|
|
|
def downgrade() -> None:
|
|
op.drop_column("images", "thumbnail_key")
|