Commit graph

24 commits

Author SHA1 Message Date
michael
8289e264eb Remove output token limit from prompt enhancement API
Removes the maxOutputTokens: 1024 limit that was causing enhanced
prompts to be truncated.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-04 15:24:20 -06:00
michael
89850f49db Update Gemini model from 2.0-flash-exp to 3-flash-preview
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-28 10:38:29 -06:00
Simeon.Schecter
a960d4dcf4 Add Edit Mode indicator and Start Fresh button
- Show "Edit Mode" badge when image exists to clarify behavior
- Add prominent "Start Fresh" button to reset and generate new
- Change button text from "Generate Image" to "Edit Image" when editing

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

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-07 16:42:47 -05:00
Simeon.Schecter
17b5e5cdb0 Style consistency: match label styles across UI
Update Creative Freedom, Scene Description, Reference Images, and
Output Resolution labels to use consistent uppercase styling.

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

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-07 16:35:35 -05:00
Simeon.Schecter
00888168f0 Add Prompt Studio React frontend with image generation integration
- Add Prompt Studio React app with cinematic prompt optimization
- Integrate image generation via PHP backend API
- Support multi-reference image uploads (up to 14 images)
- Add resolution selector (1K/2K/4K)
- Make generated prompts editable before image generation
- Fix application lighting styles being passed to Gemini API
- Reorganize UI: inputs on left, outputs on right
- Update api.php to handle multiple reference images
- Add get_current_image.php endpoint for session image retrieval

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

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-07 16:25:20 -05:00
DJP
0621cf10ad Add webhook logging for all user actions
Implemented complete webhook integration following the pattern
from AI-ASSISTANT app. All user actions now logged to Make.com.

NEW FILE:
- webhook_logger.php - Central webhook utility

WEBHOOK FUNCTIONS:
- sendToWebhook($data) - Core webhook sender
- logImageGeneration() - Log image creation/edits
- logPromptEnhancement() - Log prompt enhancements
- logUserAction() - Log general actions

WEBHOOK URL:
https://hook.us1.make.celonis.com/sbhcpk0athbdbxxmgijxc5sbwtjsg33h

DATA SENT:

Image Generation:
- client: 'Internal'
- deliverableNumber: 'NANO-{timestamp}'
- userEmail: from auth or anonymous
- generationType: 'Nano Banana Pro - Imagen 3'
- actionType: 'generate' or 'edit'
- prompt: user's prompt
- settings: {aspectRatio, imageSize, model}
- imageFile: 'data:image/png;base64,{image}'

Prompt Enhancement:
- generationType: 'Nano Banana Pro - Prompt Enhancement'
- actionType: 'prompt_enhancement'
- originalPrompt: scene description
- enhancedPrompt: AI-enhanced result
- settings: {camera, lens, application, creativeFreedom}

INTEGRATION POINTS:
- api.php - Logs every image generation/edit
- enhance_prompt.php - Logs every prompt enhancement
- Auth status included (user email)

ERROR HANDLING:
- Webhook failures don't break the app
- Errors logged to error_log
- 10 second timeout on webhook calls
- Graceful degradation

All user actions now tracked in Make.com! 📊

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

Co-Authored-By: Claude Sonnet 4.5 (1M context) <noreply@anthropic.com>
2025-12-16 11:55:23 -05:00
DJP
747005733c Make API auth checks resilient - always return JSON
CRITICAL FIX: APIs now always return JSON even if auth fails

Problem:
- Auth errors in api.php/enhance_prompt.php returned HTML
- JavaScript expected JSON, got "<br /><b>..." HTML error
- Result: "Unexpected token '<'" parse error

Solution:
- Wrapped auth checks in try-catch blocks
- Always return proper JSON responses
- Auth errors logged but don't break API
- Graceful fallback if auth system unavailable

Changes:
1. api.php - Try-catch around auth check
2. enhance_prompt.php - Try-catch around auth check
3. Both files: Continue without auth if error occurs
4. Errors logged to error_log for debugging

Benefits:
 APIs always return valid JSON
 No more "Unexpected token" errors
 App works during deployment/setup
 Can test without auth system fully configured
 Production-ready with auth when enabled

Image generation and prompt enhancement now work even if
auth system has configuration issues!

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

Co-Authored-By: Claude Sonnet 4.5 (1M context) <noreply@anthropic.com>
2025-12-16 11:29:03 -05:00
DJP
f7ea6006db Fix config to always define SSO constants
Updated config.example.php to match working config structure:

Changes:
- Load env_loader.php with file_exists check
- Always define SSO_ENABLED, SSO_TENANT_ID, SSO_CLIENT_ID
- Use !defined() checks to prevent redefinition errors
- Defaults to false/empty if .env not found
- Added error reporting settings

Server-check.php improvements:
- Shows actual SSO constant values (TRUE/FALSE/EMPTY)
- Better diagnostic output

DEPLOYMENT FIX:
On server, update config.php to match config.example.php structure.
This ensures SSO constants are always defined.

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

Co-Authored-By: Claude Sonnet 4.5 (1M context) <noreply@anthropic.com>
2025-12-16 11:23:47 -05:00
DJP
20f1a16bb0 Add server diagnostic script for debugging 500 errors
Created server-check.php to diagnose deployment issues:

CHECKS:
✓ PHP version and server info
✓ Composer vendor/ directory exists
✓ Firebase JWT library installed
✓ config.php exists
✓ .env file exists
✓ All critical PHP files present
✓ Directory permissions (uploads/)
✓ Test loads env_loader.php
✓ Test loads config.php
✓ Test loads AuthMiddleware.php
✓ Shows specific errors if files fail to load

USAGE:
Visit: https://your-server.com/nano-pro/server-check.php

Shows:
- What's missing or broken
- Exact error messages
- Action items to fix
- Deployment checklist

Perfect for diagnosing 500 errors without SSH 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 11:19:52 -05:00
DJP
3c3523d960 Add graceful fallback if auth system fails
CRITICAL FIX: Page now loads even if auth system has errors

Changes:

1. WRAPPED AUTH IN TRY-CATCH (index.php)
   - Auth errors no longer break the app
   - Falls back to default user if auth fails
   - Logs error but continues loading
   - App functional even with broken auth

2. ADDED COMPOSER AUTOLOAD (JWTValidator.php)
   - Includes vendor/autoload.php for Firebase JWT
   - Checks if file exists before requiring
   - Prevents "Class not found" errors

3. RESILIENT ERROR HANDLING
   - Default user: ['name' => 'User', 'preferred_username' => 'user@localhost']
   - SSO disabled by default if auth fails
   - Error logged to error_log for debugging
   - No blank/broken pages

This ensures:
 App always loads (even with auth issues)
 Can diagnose auth problems without breaking site
 Graceful degradation if Composer not installed yet
 Works during deployment/setup

Perfect for testing and deployment scenarios!

🤖 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:26:22 -05:00
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
eb43f0260a Add comprehensive server installation guide
Created INSTALL.md with complete deployment instructions:

SECTIONS:
- Prerequisites (PHP, Composer, Git, API keys)
- Step-by-step installation (git clone → production)
- Configuration (config.php, .env setup)
- Directory permissions setup
- Web server configuration (Apache/Nginx)
- Cron setup for image cleanup
- Testing checklist
- Troubleshooting guide

DEPLOYMENT STEPS:
1. git clone from Bitbucket
2. composer install (Firebase JWT)
3. Configure config.php (Gemini API key)
4. Configure .env (SSO settings)
5. Set permissions (uploads directory)
6. Configure web server
7. Set up cron for cleanup
8. Test installation

INCLUDES:
- Quick start (TL;DR) section
- Directory structure reference
- Common issues & solutions
- Performance optimization tips
- Backup & restore procedures
- Monitoring commands
- Security best practices
- Uninstallation instructions

Perfect for deploying to production server!

🤖 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:14:01 -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
61aa1931bb Add MSAL/Azure AD authentication with toggle support
Implemented complete Microsoft Authentication Library (MSAL) / Azure AD
Single Sign-On (SSO) system following Ferrero app pattern.

KEY FEATURE: Toggle authentication on/off via environment variable
- SSO_ENABLED=false → Mock user, no login required (local dev)
- SSO_ENABLED=true → Full Azure AD authentication (production)

NEW FILES:
- composer.json - Firebase JWT dependency
- .env.example - Environment variable template
- env_loader.php - Parse .env file
- JWTValidator.php - Validate JWT tokens from Azure AD
- AuthMiddleware.php - Core auth orchestrator with login UI
- auth.php - Authentication API (login/logout/status)
- auth-test.php - Debug authentication status
- AUTH_README.md - Complete setup documentation

UPDATED FILES:
- config.php - Load env vars, add SSO constants
- index.php - Require auth, add logout button, MSAL script
- api.php - Add authentication check
- enhance_prompt.php - Add authentication check
- .gitignore - Exclude .env and vendor/

AUTHENTICATION FLOW:
1. User visits app → Auth check
2. If SSO disabled → Mock "Local Developer" user
3. If SSO enabled → Validate JWT from cookie
4. If no token → Show MSAL login page
5. User signs in → Token validated → Cookie set → App loads

SECURITY FEATURES:
 httpOnly cookies (XSS prevention)
 SameSite=Lax (CSRF prevention)
 JWT signature validation
 Claims validation (exp, nbf, aud, iss)
 JWKS from Azure AD
 24-hour token expiration
 Secure flag for HTTPS

DEPENDENCIES INSTALLED:
- firebase/php-jwt v6.11.1

TESTING:
- Local: SSO disabled by default in .env
- Server: Set SSO_ENABLED=true with Azure AD credentials
- Cannot test MSAL locally (redirect URI bound to server)

DEPLOYMENT:
1. Install composer dependencies
2. Configure .env with Azure AD credentials
3. Set SSO_ENABLED=true when ready
4. Visit auth-test.php to verify setup

🤖 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:08:07 -05:00
DJP
7f2dd95e73 Add lightbox modal for full-size image inspection
UX Improvements:
- Click main image to view full-size in lightbox modal
- Dark overlay backdrop (95% opacity black)
- Smooth zoom-in animation
- Click outside or close button (×) to close
- ESC key closes lightbox
- Hover effect on main image (subtle scale)
- Prevents background scrolling when open

Modal Features:
- Full-screen overlay (95% viewport)
- Rounded corners and shadow on image
- Animated close button (turns gold on hover)
- Click-to-close on background
- Responsive sizing (max 95% width/height)

Perfect for inspecting generated images in detail!

🤖 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:27:38 -05:00
DJP
c5c28da8af Fix CSS conflict - conversation history now actually compact
Problem: Both conversation history and image gallery used .history-item class
Result: Conversation boxes were forced to square aspect-ratio (1:1)

Solution:
- Renamed image gallery class: .history-item → .history-image-item
- Renamed overlay class: .history-item-overlay → .history-image-overlay
- Conversation history keeps .history-item (now properly compact)

Now Working:
- Conversation history: Single-line compact items
- Image gallery: Square thumbnails as intended
- No CSS conflicts between the two

The conversation history boxes are now actually compact instead of
just having centered text in big square boxes!

🤖 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:16:31 -05:00
DJP
0f8b82aca6 Make conversation history more compact
UI Improvements:
- Reduced padding: 15px → 10px vertical
- Prompt and time on same line (flexbox layout)
- Removed unnecessary vertical spacing
- Time aligned to right, no-wrap
- Smaller font sizes for better density
- Tighter line height (1.3)

Before: Large boxes with lots of empty space
After: Compact single-line items showing more history

Visual Changes:
- History items now ~40% shorter
- Time displays inline on right
- More items visible without scrolling
- Cleaner, more efficient use of space

🤖 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:08:13 -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
baee82606a Fix quick action buttons to populate prompt instead of auto-submit
Quick action buttons now:
- Populate the prompt field with suggested text
- Focus on the prompt field for editing
- Scroll to prompt field for visibility
- User can edit before clicking Generate

Previously: Auto-submitted form immediately
Now: User has control to review/edit before generating

🤖 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:03:32 -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
DJP
bf5fa7fd48 Add all 40+ cinematography application presets
Complete integration of prompt studio with full preset library:

- Added 40+ application/lighting presets across all categories
- Studio & Portrait (2)
- Product & Macro (5)
- Outdoor & Natural (3)
- Action & Motion (1)
- Creative & Artistic (6)
- Auteur Styles (9)
- Professional Production (6)
- Editorial & Fashion (4)
- Documentary & Journalism (3)
- Architectural & Interior (2)

All lighting physics data now matches original React app.

🤖 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:44:06 -05:00
DJP
0271c2bb8f Add Cinematography Prompt Studio integration
- Created enhance_prompt.php API endpoint for AI prompt enhancement
- Integrated cinematography controls into main UI
- Added camera body, lens kit, and lighting application selections
- Implemented creative freedom slider for prompt customization
- Enhanced prompts now auto-fill into image generation form
- Seamless workflow: enhance prompt → generate image

Features:
- Real camera physics (Arri Alexa 35, Sony Venice 2, etc.)
- Professional lens characteristics (Cooke, Panavision, Canon K-35)
- Lighting presets (Golden Hour, Blue Hour, Neon Cyberpunk, etc.)
- Gemini AI integration for prompt optimization

🤖 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:40:35 -05:00
DJP
4deed84ba0 Initial commit: Nano AI Image Generator
- Complete working image generation app using Imagen 3
- PHP backend with Gemini API integration
- Dark themed UI with prompt enhancement
- Session management and logging system

🤖 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:35:02 -05:00