feat(media): Add image variant support - v1.4.0 Phase 2
Implement automatic generation of multiple image sizes for responsive delivery and enhanced feed optimization. Changes: - Add migration 009 for media_variants table with CASCADE delete - Define variant specs: thumb (150x150 crop), small (320px), medium (640px), large (1280px) - Implement generate_variant() with center crop for thumbnails and aspect-preserving resize - Implement generate_all_variants() with try/except cleanup, pass year/month/optimized_bytes explicitly - Update save_media() to generate all variants after saving original - Update get_note_media() to include variants dict (backwards compatible - only when variants exist) - Record original as 'original' variant type Technical details: - Variants use explicit year/month parameters to avoid fragile path traversal - Pass optimized_bytes to avoid redundant file I/O - File cleanup on variant generation failure - Skip generating variants larger than source image - variants key only added to response when variants exist (pre-v1.4.0 compatibility) All existing tests pass. Phase 2 complete. Per design document: /home/phil/Projects/starpunk/docs/design/v1.4.0/media-implementation-design.md Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
21
migrations/009_add_media_variants.sql
Normal file
21
migrations/009_add_media_variants.sql
Normal file
@@ -0,0 +1,21 @@
|
||||
-- Migration 009: Add media variants support
|
||||
-- Version: 1.4.0 Phase 2
|
||||
-- Per ADR-059: Full Feed Media Standardization (Phase A)
|
||||
|
||||
-- Media variants table for multiple image sizes
|
||||
-- Each uploaded image gets thumb, small, medium, large, and original variants
|
||||
CREATE TABLE IF NOT EXISTS media_variants (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
media_id INTEGER NOT NULL,
|
||||
variant_type TEXT NOT NULL CHECK (variant_type IN ('thumb', 'small', 'medium', 'large', 'original')),
|
||||
path TEXT NOT NULL, -- Relative path: YYYY/MM/uuid_variant.ext
|
||||
width INTEGER NOT NULL,
|
||||
height INTEGER NOT NULL,
|
||||
size_bytes INTEGER NOT NULL,
|
||||
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
FOREIGN KEY (media_id) REFERENCES media(id) ON DELETE CASCADE,
|
||||
UNIQUE(media_id, variant_type)
|
||||
);
|
||||
|
||||
-- Index for efficient variant lookup by media ID
|
||||
CREATE INDEX IF NOT EXISTS idx_media_variants_media ON media_variants(media_id);
|
||||
Reference in New Issue
Block a user