- 新增 ToastProvider 和 useToast hook,支持全局成功/错误/信息提示 - 资产预览增加左右导航按钮、键盘快捷键(方向键)和计数器显示 - 资产库增加图片/视频类型筛选标签页及计数 - 对话列表增加最近对话展示、搜索优化和删除确认 - 消息增加删除确认对话框 - 优化聊天自动滚动行为,仅在用户未手动滚动时跟随新内容 - 新增删除消息 API 端点 - 优化消息历史清理逻辑,过滤错误消息和孤儿 tool 消息 - 添加自定义滚动条样式 - 优化账户参考图显示逻辑,支持本地文件显示 - 修复对话创建流程,直接导航到新创建的对话
87 lines
2.9 KiB
TypeScript
87 lines
2.9 KiB
TypeScript
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 { search } = req.query;
|
|
let sql = 'SELECT * FROM conversations';
|
|
const params: string[] = [];
|
|
if (search) {
|
|
sql += ' WHERE title LIKE ?';
|
|
params.push(`%${search}%`);
|
|
}
|
|
sql += ' ORDER BY pinned DESC, updated_at DESC LIMIT 100';
|
|
const rows = getDb().prepare(sql).all(...params);
|
|
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 messages WHERE conversation_id = ?').run(req.params.id);
|
|
getDb().prepare('DELETE FROM conversations WHERE id = ?').run(req.params.id);
|
|
res.json({ ok: true });
|
|
});
|
|
|
|
// Delete a single message
|
|
pipelineRouter.delete('/messages/:id', (req, res) => {
|
|
getDb().prepare('DELETE FROM messages WHERE id = ?').run(req.params.id);
|
|
res.json({ ok: true });
|
|
});
|
|
|
|
// Update conversation (rename / toggle pin)
|
|
pipelineRouter.patch('/conversations/:id', (req, res) => {
|
|
const { title, pinned } = req.body;
|
|
if (title !== undefined) {
|
|
getDb().prepare(
|
|
'UPDATE conversations SET title = ?, updated_at = datetime(\'now\') WHERE id = ?'
|
|
).run(title, req.params.id);
|
|
}
|
|
if (pinned !== undefined) {
|
|
getDb().prepare(
|
|
'UPDATE conversations SET pinned = ?, updated_at = datetime(\'now\') WHERE id = ?'
|
|
).run(pinned ? 1 : 0, req.params.id);
|
|
}
|
|
res.json({ ok: true });
|
|
});
|
|
|
|
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 });
|
|
}
|
|
});
|