cinema-studio-pro/setup.sh
Simeon.Schecter 836e6f9c06 Add custom presets, identity protection, video negative prompts, and UX improvements
Features:
- Custom user presets: Create, edit, delete, export/import lighting presets
  stored in IndexedDB (useCustomPresets.js hook, DB schema v3→v4)
- Identity protection: LLM-mediated name-to-style translation prevents
  generating recognizable real people while preserving style references.
  Active divergence breaks likeness convergence. Defense-in-depth across
  both prompt paths + generateImage() fallback
- Video negative prompts: AI auto-generates suggested negative prompts
  during Veo 3.1 prompt optimization. Collapsible editable textarea
  teaches creatives what to exclude. Sent as negativePrompt parameter
- Generate Video from Library: Image preview modal now has a gold
  "Generate Video" button that loads the image as a first frame reference
- Expanded preview overlays: Maximize button on generated images and
  videos opens a large centered overlay (90vw, not fullscreen)
- Move items between projects: ArrowRightLeft button in Library list
  and preview modal
- Preset display in Library: Shows which preset was used per generation

Backend improvements:
- video_api.php: negativePrompt passthrough to Veo 3.1 parameters,
  lastFrame interpolation works with fast model (8s required)
- api.php: Exponential backoff retry (3 attempts), increased memory/
  POST limits for 4K images, user-friendly 500 error messages
- enhance_prompt.php: User lighting intent now respected over preset
  defaults (critical fix for night/sunset scene descriptions)
- session_manager.php: Fix images subdirectory creation race condition

Infrastructure:
- SSO made conditional via VITE_SSO_ENABLED env variable — hooks only
  called when SSO is active, local dev bypasses auth cleanly
- .gitignore updated for root-level generated_videos/, uploads/,
  config.php, backend/php.ini, Prompt_Studio/
- Wire up dead getNegativeConstraints() code in both prompt paths

No env files or secrets included. Production deploys via deploy.sh
using .env.production templates (SSO_ENABLED configurable per env).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-16 20:58:23 -05:00

422 lines
13 KiB
Bash
Executable file

#!/bin/bash
# ============================================================================
# Lux Studio - Local Development Setup & Start Script
# ============================================================================
# This script sets up AND starts both frontend and backend for LOCAL development
# For production deployment, use deploy.sh instead
# ============================================================================
set -e # Exit on any error
echo "🎬 Setting up Lux Studio for Local Development..."
echo ""
# Colors for output
GREEN='\033[0;32m'
BLUE='\033[0;34m'
YELLOW='\033[1;33m'
RED='\033[0;31m'
NC='\033[0m' # No Color
# Get the absolute path of the project root
PROJECT_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# ============================================================================
# 1. CHECK PREREQUISITES
# ============================================================================
echo "${BLUE}Step 1: Checking prerequisites...${NC}"
if ! command -v node &> /dev/null; then
echo "${RED}✗ Node.js not found. Please install Node.js 18+ first.${NC}"
exit 1
fi
if ! command -v npm &> /dev/null; then
echo "${RED}✗ npm not found. Please install npm first.${NC}"
exit 1
fi
if ! command -v php &> /dev/null; then
echo "${RED}✗ PHP not found. Please install PHP 7.4+ first.${NC}"
exit 1
fi
if ! command -v composer &> /dev/null; then
echo "${RED}✗ Composer not found. Please install Composer first.${NC}"
exit 1
fi
echo "${GREEN}✓ All prerequisites installed${NC}"
echo " Node.js: $(node --version)"
echo " npm: $(npm --version)"
echo " PHP: $(php --version | head -n 1)"
echo " Composer: $(composer --version | head -n 1)"
echo ""
# ============================================================================
# 2. SETUP BACKEND
# ============================================================================
echo "${BLUE}Step 2: Setting up backend...${NC}"
cd backend
# Create .env from .env.local
if [ ! -f ".env" ]; then
if [ -f ".env.local" ]; then
echo " → Creating backend/.env from .env.local..."
cp .env.local .env
echo "${GREEN} ✓ backend/.env created with local development settings${NC}"
else
echo "${RED} ✗ Error: .env.local not found${NC}"
echo " Please ensure backend/.env.local exists"
exit 1
fi
else
echo "${GREEN} ✓ backend/.env already exists${NC}"
fi
# Install PHP dependencies
echo " → Installing PHP dependencies via Composer..."
composer install --quiet
if [ $? -eq 0 ]; then
echo "${GREEN}✓ Backend setup complete${NC}"
else
echo "${RED}✗ Backend setup failed${NC}"
exit 1
fi
cd ..
echo ""
# ============================================================================
# 3. SETUP FRONTEND
# ============================================================================
echo "${BLUE}Step 3: Setting up frontend...${NC}"
cd frontend
# Create .env from .env.local
if [ ! -f ".env" ]; then
if [ -f ".env.local" ]; then
echo " → Creating frontend/.env from .env.local..."
cp .env.local .env
echo "${GREEN} ✓ frontend/.env created with local development settings${NC}"
else
echo "${RED} ✗ Error: .env.local not found${NC}"
echo " Please ensure frontend/.env.local exists"
exit 1
fi
else
echo "${GREEN} ✓ frontend/.env already exists${NC}"
fi
# Install npm dependencies
echo " → Installing npm dependencies (this may take a few minutes)..."
npm install --silent
if [ $? -eq 0 ]; then
echo "${GREEN}✓ Frontend setup complete${NC}"
else
echo "${RED}✗ Frontend setup failed${NC}"
exit 1
fi
cd ..
echo ""
# ============================================================================
# 4. CREATE REQUIRED DIRECTORIES
# ============================================================================
echo "${BLUE}Step 4: Creating required directories...${NC}"
# Create backend upload directory with proper permissions
mkdir -p backend/uploads/sessions
chmod -R 755 backend/uploads 2>/dev/null || true
echo "${GREEN}✓ Required directories created${NC}"
echo ""
# ============================================================================
# 5. READ PORT CONFIGURATION
# ============================================================================
# Read ports from .env files
BACKEND_PORT=5015 # Default
FRONTEND_PORT=3000 # Default
if [ -f "backend/.env" ]; then
BACKEND_PORT=$(grep -E "^BACKEND_PORT=" backend/.env | cut -d'=' -f2 | tr -d ' ')
fi
if [ -f "frontend/.env" ]; then
FRONTEND_PORT=$(grep -E "^FRONTEND_PORT=" frontend/.env | cut -d'=' -f2 | tr -d ' ')
fi
# Use defaults if not found
BACKEND_PORT=${BACKEND_PORT:-5015}
FRONTEND_PORT=${FRONTEND_PORT:-3000}
# ============================================================================
# 6. CHECK FOR PORT CONFLICTS
# ============================================================================
echo "${BLUE}Step 5: Checking for port conflicts...${NC}"
# Function to check if a port is in use
check_port() {
local port=$1
if lsof -Pi :$port -sTCP:LISTEN -t >/dev/null 2>&1 ; then
return 0 # Port is in use
else
return 1 # Port is free
fi
}
# Function to kill process on port
kill_port() {
local port=$1
local pid=$(lsof -ti:$port)
if [ ! -z "$pid" ]; then
echo " → Killing process $pid on port $port..."
kill -9 $pid 2>/dev/null || true
sleep 1
fi
}
# Check backend port
if check_port $BACKEND_PORT; then
echo "${YELLOW} ⚠ Port $BACKEND_PORT is already in use${NC}"
read -p " Kill the process and continue? (y/n) " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
kill_port $BACKEND_PORT
echo "${GREEN} ✓ Port $BACKEND_PORT is now free${NC}"
else
echo "${RED} ✗ Cannot start backend - port in use${NC}"
exit 1
fi
else
echo "${GREEN} ✓ Port $BACKEND_PORT is available${NC}"
fi
# Check frontend port
if check_port $FRONTEND_PORT; then
echo "${YELLOW} ⚠ Port $FRONTEND_PORT is already in use${NC}"
read -p " Kill the process and continue? (y/n) " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
kill_port $FRONTEND_PORT
echo "${GREEN} ✓ Port $FRONTEND_PORT is now free${NC}"
else
echo "${RED} ✗ Cannot start frontend - port in use${NC}"
exit 1
fi
else
echo "${GREEN} ✓ Port $FRONTEND_PORT is available${NC}"
fi
echo ""
# ============================================================================
# 7. START BACKEND SERVER
# ============================================================================
echo "${BLUE}Step 6: Starting backend server...${NC}"
cd "$PROJECT_ROOT/backend"
# Start PHP server in background
nohup php -S localhost:${BACKEND_PORT} > "${PROJECT_ROOT}/backend-server.log" 2>&1 &
BACKEND_PID=$!
# Wait a moment and check if server started
sleep 2
if ps -p $BACKEND_PID > /dev/null; then
echo "${GREEN}✓ Backend server started on port ${BACKEND_PORT}${NC}"
echo " PID: $BACKEND_PID"
echo " Logs: ${PROJECT_ROOT}/backend-server.log"
# Save PID for later shutdown
echo $BACKEND_PID > "${PROJECT_ROOT}/.backend.pid"
else
echo "${RED}✗ Failed to start backend server${NC}"
echo " Check ${PROJECT_ROOT}/backend-server.log for errors"
exit 1
fi
cd "$PROJECT_ROOT"
echo ""
# ============================================================================
# 8. START FRONTEND SERVER
# ============================================================================
echo "${BLUE}Step 7: Starting frontend dev server...${NC}"
cd "$PROJECT_ROOT/frontend"
# Start Vite dev server in background
nohup npm run dev > "${PROJECT_ROOT}/frontend-server.log" 2>&1 &
FRONTEND_PID=$!
# Wait for Vite to start (it takes a bit longer)
echo " → Waiting for Vite dev server to start..."
sleep 5
if ps -p $FRONTEND_PID > /dev/null; then
echo "${GREEN}✓ Frontend server started on port ${FRONTEND_PORT}${NC}"
echo " PID: $FRONTEND_PID"
echo " Logs: ${PROJECT_ROOT}/frontend-server.log"
# Save PID for later shutdown
echo $FRONTEND_PID > "${PROJECT_ROOT}/.frontend.pid"
else
echo "${RED}✗ Failed to start frontend server${NC}"
echo " Check ${PROJECT_ROOT}/frontend-server.log for errors"
# Clean up backend server
kill $BACKEND_PID 2>/dev/null || true
exit 1
fi
cd "$PROJECT_ROOT"
echo ""
# ============================================================================
# 9. VERIFY SERVERS ARE RUNNING
# ============================================================================
echo "${BLUE}Step 8: Verifying servers...${NC}"
# Wait a moment for servers to fully initialize
sleep 3
# Check if backend responds
if curl -s http://localhost:${BACKEND_PORT}/server-check.php > /dev/null 2>&1; then
echo "${GREEN} ✓ Backend is responding${NC}"
else
echo "${YELLOW} ⚠ Backend may not be fully ready yet${NC}"
fi
# Check if frontend responds
if curl -s http://localhost:${FRONTEND_PORT} > /dev/null 2>&1; then
echo "${GREEN} ✓ Frontend is responding${NC}"
else
echo "${YELLOW} ⚠ Frontend may not be fully ready yet${NC}"
fi
echo ""
# ============================================================================
# 10. CREATE STOP SCRIPT
# ============================================================================
# Create a stop script for easy shutdown
cat > "${PROJECT_ROOT}/stop.sh" << 'EOF'
#!/bin/bash
# Colors
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m'
echo -e "${YELLOW}🛑 Stopping Lux Studio servers...${NC}"
PROJECT_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# Stop backend
if [ -f "${PROJECT_ROOT}/.backend.pid" ]; then
BACKEND_PID=$(cat "${PROJECT_ROOT}/.backend.pid")
if ps -p $BACKEND_PID > /dev/null 2>&1; then
kill $BACKEND_PID 2>/dev/null
echo -e "${GREEN}✓ Backend server stopped (PID: $BACKEND_PID)${NC}"
else
echo -e "${YELLOW}⚠ Backend server not running${NC}"
fi
rm "${PROJECT_ROOT}/.backend.pid"
fi
# Stop frontend
if [ -f "${PROJECT_ROOT}/.frontend.pid" ]; then
FRONTEND_PID=$(cat "${PROJECT_ROOT}/.frontend.pid")
if ps -p $FRONTEND_PID > /dev/null 2>&1; then
kill $FRONTEND_PID 2>/dev/null
echo -e "${GREEN}✓ Frontend server stopped (PID: $FRONTEND_PID)${NC}"
else
echo -e "${YELLOW}⚠ Frontend server not running${NC}"
fi
rm "${PROJECT_ROOT}/.frontend.pid"
fi
# Also kill any remaining processes on the ports (cleanup)
BACKEND_PORT=$(grep -E "^BACKEND_PORT=" backend/.env 2>/dev/null | cut -d'=' -f2 | tr -d ' ')
FRONTEND_PORT=$(grep -E "^FRONTEND_PORT=" frontend/.env 2>/dev/null | cut -d'=' -f2 | tr -d ' ')
BACKEND_PORT=${BACKEND_PORT:-5015}
FRONTEND_PORT=${FRONTEND_PORT:-3000}
# Kill any remaining processes on ports
for port in $BACKEND_PORT $FRONTEND_PORT; do
pid=$(lsof -ti:$port 2>/dev/null)
if [ ! -z "$pid" ]; then
kill -9 $pid 2>/dev/null || true
echo -e "${GREEN}✓ Cleaned up process on port $port${NC}"
fi
done
echo -e "${GREEN}✅ All servers stopped${NC}"
EOF
chmod +x "${PROJECT_ROOT}/stop.sh"
# ============================================================================
# 11. SUCCESS MESSAGE
# ============================================================================
echo "${GREEN}════════════════════════════════════════════════════════════${NC}"
echo "${GREEN}🎉 Lux Studio is Running!${NC}"
echo "${GREEN}════════════════════════════════════════════════════════════${NC}"
echo ""
echo "${BLUE}🌐 Application URLs:${NC}"
echo " • Frontend: ${GREEN}http://localhost:${FRONTEND_PORT}${NC}"
echo " • Backend API: ${GREEN}http://localhost:${BACKEND_PORT}${NC}"
echo ""
echo "${BLUE}📊 Server Status:${NC}"
echo " • Backend PID: $BACKEND_PID (port $BACKEND_PORT)"
echo " • Frontend PID: $FRONTEND_PID (port $FRONTEND_PORT)"
echo ""
echo "${BLUE}📝 Log Files:${NC}"
echo " • Backend: ${PROJECT_ROOT}/backend-server.log"
echo " • Frontend: ${PROJECT_ROOT}/frontend-server.log"
echo " • View backend: ${GREEN}tail -f ${PROJECT_ROOT}/backend-server.log${NC}"
echo " • View frontend: ${GREEN}tail -f ${PROJECT_ROOT}/frontend-server.log${NC}"
echo ""
echo "${BLUE}🛑 Stop Servers:${NC}"
echo " ${GREEN}./stop.sh${NC}"
echo ""
echo "${BLUE}⚙️ Configuration:${NC}"
echo " • SSO: Enabled with LOCAL credentials"
echo " • SSO Client ID: 15c0c4e2-bac0-4564-a3a6-c2717f00a6d9 (local dev)"
echo " • API Key: Configured in .env files"
echo ""
echo "${BLUE}📚 Documentation:${NC}"
echo " • CLAUDE.md - Developer guide"
echo " • MDFiles/README.md - User guide"
echo " • MDFiles/AUTH_README.md - SSO guide"
echo ""
echo "${YELLOW}💡 Tip: Open http://localhost:${FRONTEND_PORT} in your browser!${NC}"
echo ""
echo "Happy coding! 🚀"