import { Router } from 'express'; import { getDb } from '../db'; import { execSync } from 'child_process'; import path from 'path'; import { fileURLToPath } from 'url'; const __filename = fileURLToPath(import.meta.url); const __dirname = path.dirname(__filename); const PROJECT_ROOT = path.resolve(__dirname, '..', '..', '..'); const PIPELINE_SCRIPT = path.join(PROJECT_ROOT, '.claude', 'skills', 'video-from-script', 'scripts', 'pipeline.js'); export const pipelineRouter = Router(); pipelineRouter.get('/conversations', (_req, res) => { const rows = getDb().prepare('SELECT * FROM conversations ORDER BY updated_at DESC').all(); res.json(rows); }); pipelineRouter.get('/conversations/:id/messages', (req, res) => { const rows = getDb().prepare( 'SELECT * FROM messages WHERE conversation_id = ? ORDER BY created_at' ).all(req.params.id); res.json(rows); }); pipelineRouter.delete('/conversations/:id', (req, res) => { getDb().prepare('DELETE FROM conversations WHERE id = ?').run(req.params.id); res.status(204).send(); }); pipelineRouter.get('/status', (req, res) => { const { manifest } = req.query; if (!manifest) return res.status(400).json({ error: 'manifest path required' }); try { const result = execSync(`node "${PIPELINE_SCRIPT}" status --manifest "${manifest}"`, { cwd: PROJECT_ROOT, encoding: 'utf-8', }); res.json({ output: result }); } catch (e) { res.status(500).json({ error: (e as Error).message }); } }); pipelineRouter.post('/resume', (req, res) => { const { manifest } = req.body; if (!manifest) return res.status(400).json({ error: 'manifest path required' }); try { const result = execSync(`node "${PIPELINE_SCRIPT}" run --manifest "${manifest}" --resume`, { cwd: PROJECT_ROOT, encoding: 'utf-8', }); res.json({ output: result }); } catch (e) { res.status(500).json({ error: (e as Error).message }); } });