mirror of
				https://github.com/Wan-Video/Wan2.1.git
				synced 2025-11-04 06:15:17 +00:00 
			
		
		
		
	This commit implements Phase 3 of the Wan2.1 PWA, closing all critical integration gaps between frontend, backend, database, and Replicate API. ## Backend Integration ✅ ### Database Writes - Create generation records BEFORE calling Replicate - Store job_id for tracking Replicate predictions - Track progress, status, and completion timestamps - Save video URLs and error messages ### Credit System - Atomic credit deduction using database function deduct_credits() - Automatic refunds on generation failures via refund_credits() - Complete audit trail in credit_transactions table - Transaction logging for all credit operations ### Webhook Handler - Created /api/webhooks/replicate endpoint - HMAC signature verification for security - Automatic status updates from Replicate push notifications - Maps Replicate statuses to application statuses - Triggers refunds for failed generations ### Updated Generation Flow 1. Check user credits before starting 2. Create generation record (status: queued) 3. Start Replicate job and get job_id 4. Update record with job_id (status: processing) 5. Deduct credits atomically 6. Webhook updates status when complete 7. Polling fallback if webhook fails ## Frontend Enhancements ✅ ### Error Handling - Added sonner for beautiful toast notifications - Success/error/loading states with retry actions - User-friendly error messages - Providers component wraps app with Toaster ### Form Validation - Zod schemas for T2V and I2V inputs - Prompt length validation (10-500 chars) - Model and resolution validation - Credit cost calculator ### Credit Management - useCredits hook for real-time credit fetching - Optimistic updates on generation start - Credit refresh functionality - Loading and error states ### Image Upload - Drag-and-drop ImageUpload component - Client-side validation (file type, size) - Image preview functionality - Max 10MB size limit with user feedback - Ready for I2V integration ### Settings Page - Basic settings page structure - Placeholders for Profile, Billing, API Keys - Ready for Phase 4 enhancements ## Database Changes ✅ ### New Migration: 002_credit_system.sql - credit_transactions table with audit trail - deduct_credits() function for atomic operations - add_credits() function for purchases/bonuses - refund_credits() function for failed generations - Added job_id, progress, error_message columns to generations ## Documentation ✅ ### PHASE_3_IMPLEMENTATION.md - Complete implementation guide - Testing checklist (backend, frontend, E2E) - Deployment steps with webhook registration - Known issues and limitations - Metrics to monitor - Phase 4 roadmap ## Files Changed ### Backend (4 files) - apps/api/main.py - Added webhooks router - apps/api/routes/generation.py - Complete rewrite with DB integration - apps/api/routes/webhooks.py - NEW webhook handler - packages/db/migrations/002_credit_system.sql - NEW credit system ### Frontend (7 files) - apps/web/package.json - Added sonner - apps/web/src/app/layout.tsx - Added Providers wrapper - apps/web/src/app/dashboard/settings/page.tsx - NEW settings page - apps/web/src/components/providers.tsx - NEW toast provider - apps/web/src/components/generation/image-upload.tsx - NEW upload component - apps/web/src/lib/hooks/use-credits.ts - NEW credit management hook - apps/web/src/lib/validation/generation.ts - NEW Zod schemas ### Documentation (1 file) - PHASE_3_IMPLEMENTATION.md - NEW comprehensive guide ## Testing Required ### Backend - [ ] Database writes on generation start - [ ] Credit deduction accuracy - [ ] Webhook updates from Replicate - [ ] Refunds on failures ### Frontend - [ ] Toast notifications - [ ] Form validation - [ ] Credit display and warnings - [ ] Image upload ### Integration - [ ] End-to-end generation flow - [ ] Credit deduction → generation → completion - [ ] Webhook vs polling updates ## Next Steps (Phase 4) 1. Payment integration with Stripe 2. Retry logic for failed generations 3. Cancel in-progress generations 4. In-app video player 5. Batch operations 6. Admin panel ## Environment Variables ### New Required Variables - REPLICATE_WEBHOOK_SECRET - For webhook signature verification See PHASE_3_IMPLEMENTATION.md for complete setup instructions. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
		
			
				
	
	
		
			50 lines
		
	
	
		
			1.3 KiB
		
	
	
	
		
			JSON
		
	
	
	
	
	
			
		
		
	
	
			50 lines
		
	
	
		
			1.3 KiB
		
	
	
	
		
			JSON
		
	
	
	
	
	
{
 | 
						|
  "name": "@wan-pwa/web",
 | 
						|
  "version": "1.0.0",
 | 
						|
  "private": true,
 | 
						|
  "scripts": {
 | 
						|
    "dev": "next dev",
 | 
						|
    "build": "next build",
 | 
						|
    "start": "next start",
 | 
						|
    "lint": "next lint",
 | 
						|
    "clean": "rm -rf .next node_modules"
 | 
						|
  },
 | 
						|
  "dependencies": {
 | 
						|
    "@hookform/resolvers": "^3.9.1",
 | 
						|
    "@radix-ui/react-avatar": "^1.1.1",
 | 
						|
    "@radix-ui/react-dialog": "^1.1.2",
 | 
						|
    "@radix-ui/react-dropdown-menu": "^2.1.2",
 | 
						|
    "@radix-ui/react-label": "^2.1.0",
 | 
						|
    "@radix-ui/react-select": "^2.1.2",
 | 
						|
    "@radix-ui/react-slot": "^1.1.0",
 | 
						|
    "@radix-ui/react-tabs": "^1.1.1",
 | 
						|
    "@radix-ui/react-toast": "^1.2.2",
 | 
						|
    "@supabase/ssr": "^0.5.2",
 | 
						|
    "@supabase/supabase-js": "^2.46.1",
 | 
						|
    "class-variance-authority": "^0.7.0",
 | 
						|
    "clsx": "^2.1.1",
 | 
						|
    "lucide-react": "^0.454.0",
 | 
						|
    "next": "15.0.3",
 | 
						|
    "next-pwa": "^5.6.0",
 | 
						|
    "react": "^19.0.0-rc.0",
 | 
						|
    "react-dom": "^19.0.0-rc.0",
 | 
						|
    "react-hook-form": "^7.53.2",
 | 
						|
    "sonner": "^1.7.1",
 | 
						|
    "tailwind-merge": "^2.5.4",
 | 
						|
    "tailwindcss-animate": "^1.0.7",
 | 
						|
    "zod": "^3.23.8",
 | 
						|
    "zustand": "^5.0.1"
 | 
						|
  },
 | 
						|
  "devDependencies": {
 | 
						|
    "@types/node": "^20",
 | 
						|
    "@types/react": "^18",
 | 
						|
    "@types/react-dom": "^18",
 | 
						|
    "autoprefixer": "^10.4.20",
 | 
						|
    "eslint": "^8",
 | 
						|
    "eslint-config-next": "15.0.3",
 | 
						|
    "postcss": "^8",
 | 
						|
    "tailwindcss": "^3.4.1",
 | 
						|
    "typescript": "^5"
 | 
						|
  }
 | 
						|
}
 |