Commit graph

5 commits

Author SHA1 Message Date
DJP
dacc351113 Remove cron requirement - add automatic cleanup on launch
Changes:

1. AUTOMATIC IMAGE CLEANUP (No Cron Needed)
   - Cleanup runs automatically when app launches
   - Triggers randomly ~10% of sessions to avoid performance hit
   - Finds and deletes images older than 24 hours
   - Logs cleanup activity to error_log
   - Replaces need for cron job

2. RELAXED .htaccess SECURITY
   - Was: Deny all access (too strict)
   - Now: Allow image files (.jpg, .png, .webp, .gif)
   - Still blocks: Directory listing, .meta files
   - Images can be accessed if needed
   - Maintains security without breaking functionality

3. DOCUMENTATION UPDATES
   - Removed cron setup from INSTALL.md
   - Added "Automatic Image Cleanup" section
   - Updated Quick Start (removed cron step)
   - Simplified deployment process

Benefits:
 No cron configuration needed
 Works perfectly on shared hosting / MAMP
 Automatic maintenance without admin intervention
 Performance impact minimal (10% probability)
 Images still expire after 24 hours
 Cleanup happens organically as users use the app

Technical Details:
- autoCleanupExpiredImages() method added to SessionManager
- Calls cleanupExpiredImages() silently on init
- rand(1, 10) === 1 gives ~10% trigger rate
- Failures logged but don't break app

Perfect for deployment without shell access!

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 (1M context) <noreply@anthropic.com>
2025-12-16 10:23:43 -05:00
DJP
57c2791852 Add automatic cleanup of invalid image history entries
Problem: Old session data had wrong format, showing count but no images

Solution:
- Added cleanupImageHistory() method
- Runs on SessionManager initialization
- Removes history items without 'filename' key
- Removes items where file doesn't exist
- Validates file paths (not directories)

Result:
- "Recent Images (4/10)" now correctly shows only valid entries
- Old/invalid history entries automatically removed
- Gallery only displays images that actually exist
- No more empty gallery with non-zero count

Backwards Compatibility:
- Handles migration from old session format
- Gracefully removes corrupted history data
- Fresh sessions start with clean history

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 (1M context) <noreply@anthropic.com>
2025-12-16 10:12:02 -05:00
DJP
e114b7e430 Fix PHP warnings in image history display
Fixed two errors in Recent Images gallery:

1. Undefined array key "filename" (index.php:1053)
   - Added check: isset($historyItem['filename'])
   - Skip history items without filename key
   - Prevents warning on legacy session data

2. file_get_contents() reading directory (session_manager.php:123)
   - Added is_file() check before file_exists()
   - Ensures path is a file, not directory
   - Returns null for invalid paths
   - Also added is_file() check for metadata file

Additional Improvements:
- Added isset() check for expires_at in metadata
- More robust error handling in getImage()
- Graceful degradation for corrupted history data

Result: No more PHP warnings in Recent Images section

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 (1M context) <noreply@anthropic.com>
2025-12-16 10:10:18 -05:00
DJP
24132234d6 Add image history gallery (last 10 images)
New Features:
- Track last 10 generated images per session
- Display thumbnail gallery below main image
- Click any thumbnail to download that image
- Timestamps show when each image was created
- Hover effects highlight thumbnails

UI Components:
- Responsive grid layout (auto-fill 120px thumbnails)
- Hover overlay with timestamp
- Golden border on hover
- Shows count: "Recent Images (X/10)"

SessionManager Updates:
- addToImageHistory() - Track images (max 10)
- getImageHistory() - Retrieve history array
- restoreImageFromHistory() - Restore previous image
- Auto-adds to history when setCurrentImage() called

User Experience:
- Easy access to recent generations
- Quick downloads without re-generating
- Visual timeline of session work
- 24-hour persistence (with images)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 (1M context) <noreply@anthropic.com>
2025-12-16 09:06:34 -05:00
DJP
7d1cd03a32 Add multi-user support with 24-hour image expiration
Implemented complete session management system for multiple users:

**New Features:**
- Isolated user sessions with unique session IDs
- File-based image storage (not in PHP session)
- Automatic 24-hour image expiration
- Session directories: uploads/sessions/{session_id}/
- Images stored with metadata (creation time, expiry, MIME type)

**New Files:**
- session_manager.php - Complete session management class
- cleanup.php - Cron script to delete expired images
- uploads/.htaccess - Security: prevent direct file access

**Updated Files:**
- api.php - Uses SessionManager for file-based storage
- index.php - Loads images from disk via SessionManager
- .gitignore - Exclude user uploads from repository

**Usage:**
- Each user gets isolated session automatically
- Images auto-delete after 24 hours
- Run cleanup.php via cron: `0 * * * * php cleanup.php`

**Security:**
- Session IDs regenerated on first access
- Upload directory protected by .htaccess
- User images isolated by session

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 (1M context) <noreply@anthropic.com>
2025-12-16 08:56:26 -05:00