Repository navigation
v0.3.0 - Media View Count
What's New
Media View Count
- New
POST/GET /api/media/{id}/viewendpoint for recording and retrieving view counts - Lightbox automatically records and displays view count with eye icon
- Home page gallery supports sorting by views (new "Views" tab alongside "Latest" and "Popular")
- Admin media list shows view count column with sort support
- IP-based deduplication via KV (5-minute window) prevents spam
- Bot User-Agent filtering (Googlebot, Bingbot, curl, etc.)
Technical Details
- New DB field
media.view_countwith index - New service
mediaViewServices.tsfollowingalbumViewServicespattern - KV keys:
media:view:{id}(count),media:view:dedup:{id}:{ipHash}(dedup with 300s TTL) - COALESCE-based NULL-safe sorting for both public and admin APIs
Upgrade Guide
Run the database migration:
# Cloudflare D1
npx wrangler d1 execute <DB_NAME> --remote --file=drizzle/0004_add_media_view_count.sql
# Docker (SQLite)
sqlite3 /data/photos.db < drizzle/0004_add_media_view_count.sql
# Supabase (PostgreSQL)
psql -h <host> -U postgres -d postgres -f drizzle/0004_add_media_view_count.sqlFull Changelog: v0.2.1...v0.3.0