import { Router, type Request, type Response } from 'express'; import { MockDataService } from '../services/mock-data-service'; const router = Router(); // POST /v2/lipsync - Create lipsync request router.post('/', (req: Request, res: Response) => { try { const { replica_id, audio_url, title, description, quality, metadata } = req.body; // Validate required fields if (!replica_id) { return res.status(400).json({ error: 'validation_error', message: 'replica_id is required', status_code: 400 }); } if (!audio_url) { return res.status(400).json({ error: 'validation_error', message: 'audio_url is required', status_code: 400 }); } if (!title) { return res.status(400).json({ error: 'validation_error', message: 'title is required', status_code: 400 }); } // Create lipsync const lipsync = MockDataService.createLipsync({ replica_id, audio_url, title, description, quality: quality || 'high', metadata }); const response = { lipsync_id: lipsync.lipsync_id, replica_id: lipsync.replica_id, audio_url: lipsync.audio_url, title: lipsync.title, description: lipsync.description, quality: lipsync.quality, status: lipsync.status, progress: lipsync.progress, estimated_completion: lipsync.estimated_completion, metadata: lipsync.metadata, created_at: lipsync.created_at, updated_at: lipsync.updated_at }; res.status(201).json(response); } catch (_error) { res.status(500).json({ error: 'internal_server_error', message: 'An unexpected error occurred', status_code: 500 }); } }); // GET /v2/lipsync - List all lipsync requests router.get('/', (req: Request, res: Response) => { try { const { limit = 10, offset = 0 } = req.query; const lipsyncs = MockDataService.getLipsyncs(); // Apply pagination const total = lipsyncs.length; const paginatedLipsyncs = lipsyncs.slice( parseInt(offset as string), parseInt(offset as string) + parseInt(limit as string) ); const response = { lipsync: paginatedLipsyncs.map(l => ({ lipsync_id: l.lipsync_id, replica_id: l.replica_id, title: l.title, status: l.status, progress: l.progress, created_at: l.created_at, updated_at: l.updated_at })), pagination: { total, limit: parseInt(limit as string), offset: parseInt(offset as string), has_more: parseInt(offset as string) + parseInt(limit as string) < total } }; res.json(response); } catch (_error) { res.status(500).json({ error: 'internal_server_error', message: 'An unexpected error occurred', status_code: 500 }); } }); // GET /v2/lipsync/:id - Get lipsync details router.get('/:id', (req: Request, res: Response) => { try { const { id } = req.params; const lipsync = MockDataService.getLipsync(id); if (!lipsync) { return res.status(404).json({ error: 'lipsync_not_found', message: `Lipsync with ID ${id} not found`, status_code: 404 }); } const response = { lipsync_id: lipsync.lipsync_id, replica_id: lipsync.replica_id, audio_url: lipsync.audio_url, title: lipsync.title, description: lipsync.description, quality: lipsync.quality, status: lipsync.status, progress: lipsync.progress, video_url: lipsync.video_url, thumbnail_url: lipsync.thumbnail_url, duration_seconds: lipsync.duration_seconds, file_size_bytes: lipsync.file_size_bytes, metadata: lipsync.metadata, created_at: lipsync.created_at, updated_at: lipsync.updated_at, completed_at: lipsync.completed_at }; res.json(response); } catch (_error) { res.status(500).json({ error: 'internal_server_error', message: 'An unexpected error occurred', status_code: 500 }); } }); // DELETE /v2/lipsync/:id - Delete lipsync router.delete('/:id', (req: Request, res: Response) => { try { const { id } = req.params; const lipsync = MockDataService.getLipsync(id); if (!lipsync) { return res.status(404).json({ error: 'lipsync_not_found', message: `Lipsync with ID ${id} not found`, status_code: 404 }); } const deleted = MockDataService.deleteLipsync(id); const response = { lipsync_id: id, message: 'Lipsync deleted successfully' }; res.json(response); } catch (_error) { res.status(500).json({ error: 'internal_server_error', message: 'An unexpected error occurred', status_code: 500 }); } }); export default router;