Commit Graph

101 Commits

Author SHA1 Message Date
1bdf0a9424 Implement AVIF decoding support
- Add github.com/gen2brain/avif dependency (CGO-free, WASM-based)
- Update decode() to try AVIF after WebP
- Add AVIF to SupportedInputFormats()
2026-01-08 13:10:34 -08:00
615586fcea Add failing test for AVIF decoding
Test verifies that AVIF images can be decoded and processed.
Currently fails because AVIF decoding is not implemented.
2026-01-08 13:09:40 -08:00
9bfae69ccf Fix logging: add response_bytes to middleware, cache_key to handler
- Middleware now tracks and logs bytes written via response_bytes
- Handler logs cache_key for cache hit debugging
- Changed "served encrypted image" to "image served" (only URL is encrypted)
2026-01-08 13:05:10 -08:00
e5135b3697 Add 1-minute expiration option and quality presets to URL generator
Quality is now a dropdown with named presets:
- Potato (25), Low (50), Medium (70), High (85), Ultra (100)

Added 1-minute TTL option for testing short-lived URLs.
2026-01-08 12:52:14 -08:00
77c6744383 Add upstream connection info and download metrics to logging
- Capture TLS version, cipher suite, HTTP version, and remote addr
- Add download bitrate using go-humanize SI formatting
- Use consistent WxH format for dimensions (not struct notation)
- Rename input/output to src/dst for consistency
- Add separate "upstream fetched" log with connection details
2026-01-08 12:47:31 -08:00
7d0ac0a139 Remove Buildarch from ldflags, use runtime.GOARCH instead
The architecture is available at runtime via stdlib, no need to bake
it in at build time.
2026-01-08 12:38:24 -08:00
15d9439e3d Add fetch/conversion metrics and improve logging
FetchResult now includes:
- StatusCode: HTTP status from upstream
- FetchDurationMs: time to fetch from upstream
- RemoteAddr: upstream server address

SourceMetadata now stores:
- ContentLength: size from upstream
- FetchDurationMs: fetch timing
- RemoteAddr: for debugging

Image conversion log now includes:
- host: source hostname (was missing)
- path: source path (renamed from file)
- convert_ms: image processing time
- quality: requested quality setting
- fit: requested fit mode
2026-01-08 12:34:26 -08:00
4426387d1c Fix hot cache to include ContentType and SizeBytes
Hot cache entries now store all data needed to serve a cache hit
without any database access:
- OutputHash (for file lookup)
- ContentType (for Content-Type header)
- SizeBytes (for Content-Length header)

Previously hot cache only stored OutputHash, causing empty
Content-Type headers on cached WebP responses.
2026-01-08 12:28:17 -08:00
51a1ae4a13 Add failing test for hot cache ContentType
Hot cache lookups must return ContentType to serve correct
Content-Type headers. Currently returns empty string.
2026-01-08 12:25:01 -08:00
10b5cc7063 Fix proportional scaling when single dimension is 0
When only width or height is specified (the other being 0), scale the
image proportionally to maintain aspect ratio. Previously, 0 was passed
directly to the resize function which produced a 0x0 image.
2026-01-08 12:20:58 -08:00
817d760b4d Add failing tests for proportional scaling
When only one dimension is provided (e.g., width=400, height=0),
the image should scale proportionally. Currently returns 0x0.
2026-01-08 12:20:19 -08:00
70d55977c0 Add WebP encoding support
Uses github.com/gen2brain/webp - a CGO-free library that uses WASM via
wazero runtime for encoding. WebP decoding was already supported.

- Add gen2brain/webp dependency for encoding
- Implement WebP encoding in processor.go
- Add FormatWebP to SupportedOutputFormats
- Re-enable WebP option in generator form dropdown
- Mark WebP encoding as complete in TODO.md
2026-01-08 11:55:45 -08:00
0c9eb35bd2 Add failing test for WebP encoding support
TDD: This test expects WebP encoding to succeed. It currently fails
because WebP encoding is not implemented (returns ErrUnsupportedOutputFormat).
The test will pass once we add the gen2brain/webp library.
2026-01-08 11:54:03 -08:00
aab43db44a Add WebP and AVIF encoding support to P0 TODO 2026-01-08 11:12:59 -08:00
064ab10607 Add no-silent-fallback rule to CLAUDE.md
Never silently fall back to a different setting when a user's parameter
explicitly specifies a value. Return an error for invalid explicit values;
only apply defaults for omitted parameters.
2026-01-08 11:08:33 -08:00
37af10cc2b Update generator form for supported formats and Never expiry
- Remove WebP and AVIF options (encoding not supported)
- Add GIF option (encoding is supported)
- Add 'Never' TTL option as default
2026-01-08 11:08:28 -08:00
b55b75cbe7 Fix silent fallbacks for unsupported formats and fit modes
- Return ErrUnsupportedOutputFormat for WebP/AVIF encoding
- Return ErrInvalidFitMode for unknown fit mode values
- Add ValidateFitMode() for input validation
- Validate fit mode at handler level before processing

Silent fallbacks violate the principle of least surprise and mask bugs.
When a user explicitly specifies a value, we should either honor it or
return an error - never silently substitute a different value.
2026-01-08 11:08:22 -08:00
df6d347e68 Add tests for unsupported output format errors
Tests verify that WebP and AVIF encoding requests return
ErrUnsupportedOutputFormat instead of silently falling back
to a different format.
2026-01-08 11:08:16 -08:00
014c144d73 Add 'Never' expiry option for encrypted URLs
- Make ExpiresAt optional in CBOR (omitempty) for smaller tokens
- Treat ExpiresAt=0 as 'never expires' in parser
- URL-encode token with url.PathEscape() for safety
- Add 'Never' as default TTL option in generator form
2026-01-08 11:08:11 -08:00
d9f4e2038e Add manual test script for auth and encrypted URLs
scripts/manual-test.sh tests:
1. Healthcheck endpoint
2. Login page displays
3. Wrong password shows error
4. Correct password shows generator
5. Generate encrypted URL
6. Fetch image via encrypted URL
7. Fetch image via direct proxy (whitelisted)
8. Logout redirects to login
9. Expired URL returns 410
2026-01-08 10:53:02 -08:00
b233871241 Add detailed logging for image conversions on cache miss
Log includes:
- file path
- input/output format
- input/output size in bytes
- input/output dimensions
- size ratio (percentage)

Also adds InputWidth, InputHeight, InputFormat to ProcessResult
2026-01-08 10:44:34 -08:00
02de534cc2 Reorganize TODO.md: remove completed, prioritize for 1.0
P0 Critical: Manual testing, cache eviction, config validation
P1 Production: Blocked networks, rate limiting, EXIF stripping
P2 Nice to have: Everything else
2026-01-08 10:41:00 -08:00
d8bb374f73 Merge feature/http-response-handling: ETag, HEAD, conditional requests 2026-01-08 10:09:14 -08:00
774ee97ba1 Update TODO.md: mark HTTP response handling items complete
Completed:
- ETag generation and validation
- Conditional requests (If-None-Match)
- HEAD request support
- Metrics endpoint with auth (already implemented)
2026-01-08 10:09:10 -08:00
1f809a6fc9 Implement ETag, HEAD requests, and conditional requests
- Add ETag generation based on output content hash (first 16 chars)
- Add ContentLength to ImageResponse from cache
- Add LoadWithSize method to ContentStorage
- Add GetOutputWithSize method to Cache
- Handle HEAD requests returning headers only
- Handle If-None-Match conditional requests returning 304
- Register HEAD route for image proxy endpoint
2026-01-08 10:08:38 -08:00
4df3e44eff Add failing tests for ETag, HEAD requests, and conditional requests
TDD: Write tests first before implementation for:
- ETag generation and consistency in service layer
- HEAD request support (headers only, no body)
- Conditional requests with If-None-Match header (304 responses)
2026-01-08 10:06:18 -08:00
aed9dd6e8d Merge feature/graceful-shutdown-and-sanitization: Add security headers middleware 2026-01-08 10:02:34 -08:00
6f423af65d Update TODO.md: mark graceful shutdown and sanitization as complete 2026-01-08 10:02:29 -08:00
2e349a8b83 Implement security headers middleware
Adds X-Content-Type-Options, X-Frame-Options, Referrer-Policy,
and X-XSS-Protection headers to all responses.
2026-01-08 10:02:17 -08:00
5de7a26735 Add failing tests for security headers middleware
Tests for X-Content-Type-Options, X-Frame-Options, Referrer-Policy,
X-XSS-Protection headers on responses.
2026-01-08 10:01:36 -08:00
9592175238 Merge feature/security-validations: Add input dimension and path traversal validation 2026-01-08 08:50:43 -08:00
90be4e7763 Update TODO.md: mark security validations as complete 2026-01-08 08:50:37 -08:00
95408e68d4 Implement max input dimensions and path traversal validation
- Reject input images exceeding MaxInputDimension (8192px) to prevent DoS
- Detect path traversal: ../, encoded variants, backslashes, null bytes
2026-01-08 08:50:18 -08:00
c964feac7e Add failing tests for input dimension and path traversal validation
Tests for:
- ErrInputTooLarge when input image exceeds MaxInputDimension
- ErrPathTraversal for ../, encoded traversal, backslashes, null bytes
2026-01-08 08:48:11 -08:00
857be30e82 Update TODO.md: mark auth/encrypted URLs feature as complete 2026-01-08 08:43:23 -08:00
06c99b6f4e Merge feature/auth-and-encrypted-urls: Add login, sessions, and encrypted URLs 2026-01-08 07:41:28 -08:00
f601e17812 Add implementation plan for auth and encrypted URLs feature 2026-01-08 07:39:31 -08:00
6355886dba Add vendoring and repo size guidelines to CLAUDE.md 2026-01-08 07:39:27 -08:00
2cbafe374c Add mock fetcher and service tests for imgcache
Introduces Fetcher interface, mock implementation for testing,
and ApplyMigrations helper for test database setup.
2026-01-08 07:39:18 -08:00
1f0ec59eb5 Wire up auth routes and encrypted URL endpoint
Add session manager and encurl generator to handlers.
Register /, /logout, /generate, /v1/e/{token}, /static/* routes.
2026-01-08 07:38:44 -08:00
08d6e264ed Add auth and encrypted image handlers
Login page, logout, URL generator form, and /v1/e/{token}
endpoint for serving images from encrypted URLs.
2026-01-08 07:38:15 -08:00
aad5e59d23 Add static files and HTML templates for web UI
Embedded Tailwind CSS and login/generator templates.
Self-contained with no external dependencies.
2026-01-08 07:38:09 -08:00
c033e918f0 Add encurl package for encrypted URL tokens
CBOR-encoded payloads with NaCl secretbox encryption.
Supports expiration, image parameters with omitempty defaults.
2026-01-08 07:38:05 -08:00
041b18f651 Add session package for encrypted cookie management
Uses gorilla/securecookie with keys derived via HKDF.
30-day TTL, HttpOnly, Secure, SameSiteStrict cookies.
2026-01-08 07:37:58 -08:00
3f4f345d1c Add seal package for authenticated encryption
Provides HKDF-SHA256 key derivation and NaCl secretbox
(XSalsa20-Poly1305) encryption/decryption utilities.
2026-01-08 07:37:53 -08:00
1e890ffbcc Fix spelling, punctuation, and capitalization in CLAUDE.md 2026-01-08 05:29:08 -08:00
f244d9c7e0 Add per-host connection limits for upstream fetching
- Add upstream_connections_per_host config option (default: 20)
- Implement per-host semaphores to limit concurrent connections
- Semaphore released when response body is closed
- Prevents overwhelming origin servers with parallel requests
2026-01-08 05:19:20 -08:00
49ff72dfa8 Add bin/ to gitignore 2026-01-08 05:14:11 -08:00
6304556837 Refactor to serve all responses from cached files on disk
- StoreOutput now returns output hash for immediate retrieval
- Cache misses now serve from disk file after storing (same as hits)
- Log served_bytes from actual io.Copy result (avoids stat calls)
- Remove ContentLength field usage for cache hits (stream from file)
- Fix tests to properly check all return values
2026-01-08 05:11:55 -08:00
1a97f42cd8 Add detailed logging for image requests with cache status and timing 2026-01-08 05:04:08 -08:00