Skip to content

v0.3.0 - Media View Count

Choose a tag to compare

@bigfa bigfa released this 08 Feb 05:09
· 6 commits to main since this release
78f6899

What's New

Media View Count

  • New POST/GET /api/media/{id}/view endpoint 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_count with index
  • New service mediaViewServices.ts following albumViewServices pattern
  • 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.sql

Full Changelog: v0.2.1...v0.3.0