feat(web): 重构前端UI并支持OpenAI协议
- 添加账号管理详情页(基本信息、提示词、CapCut、参考图标签页) - 重构资产页面,按项目组分开展示图片/视频 - 聊天界面支持深度思考内容折叠展示、复制、删除消息 - 设置页面支持Agent配置(Anthropic/OpenAI协议)和工具配置 - 后端支持OpenAI兼容协议流式输出和DeepSeek思考模式 - 添加对话置顶/删除功能、数据库迁移、资产清单API - 添加账号参考图上传/删除、技能配置持久化、连接测试API
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
import { Router } from 'express';
|
||||
import { getDb } from '../db';
|
||||
import { randomUUID } from 'crypto';
|
||||
import fs from 'fs';
|
||||
import fs from 'fs/promises';
|
||||
import fss from 'fs';
|
||||
import path from 'path';
|
||||
import { fileURLToPath } from 'url';
|
||||
|
||||
@@ -25,8 +26,23 @@ assetsRouter.get('/', (req, res) => {
|
||||
res.json(rows);
|
||||
});
|
||||
|
||||
// List manifests with metadata
|
||||
assetsRouter.get('/manifests', async (_req, res) => {
|
||||
const rows = getDb().prepare(`
|
||||
SELECT manifest_path, account_id,
|
||||
COUNT(*) as asset_count,
|
||||
SUM(CASE WHEN type = 'image' THEN 1 ELSE 0 END) as image_count,
|
||||
SUM(CASE WHEN type = 'video' THEN 1 ELSE 0 END) as video_count,
|
||||
MAX(created_at) as latest_at
|
||||
FROM assets
|
||||
GROUP BY manifest_path
|
||||
ORDER BY latest_at DESC
|
||||
`).all();
|
||||
res.json(rows);
|
||||
});
|
||||
|
||||
// Delete asset and its file
|
||||
assetsRouter.delete('/:id', (req, res) => {
|
||||
assetsRouter.delete('/:id', async (req, res) => {
|
||||
const asset = getDb().prepare('SELECT * FROM assets WHERE id = ?').get(req.params.id) as {
|
||||
file_path: string;
|
||||
} | undefined;
|
||||
@@ -34,36 +50,38 @@ assetsRouter.delete('/:id', (req, res) => {
|
||||
if (!asset) return res.status(404).json({ error: 'Asset not found' });
|
||||
|
||||
const filePath = path.join(PROJECT_ROOT, asset.file_path);
|
||||
if (fs.existsSync(filePath)) fs.unlinkSync(filePath);
|
||||
try { await fs.unlink(filePath); } catch { /* ignore */ }
|
||||
|
||||
getDb().prepare('DELETE FROM assets WHERE id = ?').run(req.params.id);
|
||||
res.status(204).send();
|
||||
});
|
||||
|
||||
// Scan output directories and index assets
|
||||
assetsRouter.post('/scan', (_req, res) => {
|
||||
assetsRouter.post('/scan', async (_req, res) => {
|
||||
const outputDir = path.join(PROJECT_ROOT, 'output');
|
||||
if (!fs.existsSync(outputDir)) return res.json({ indexed: 0 });
|
||||
try {
|
||||
await fs.access(outputDir);
|
||||
} catch {
|
||||
return res.json({ indexed: 0 });
|
||||
}
|
||||
|
||||
const dirs = fs.readdirSync(outputDir, { withFileTypes: true })
|
||||
.filter((d) => d.isDirectory());
|
||||
const dirs = await fs.readdir(outputDir, { withFileTypes: true });
|
||||
const dirEntries = dirs.filter((d) => d.isDirectory());
|
||||
|
||||
let indexed = 0;
|
||||
for (const dir of dirs) {
|
||||
for (const dir of dirEntries) {
|
||||
const manifestPath = path.join(outputDir, dir.name, 'manifest.json');
|
||||
if (!fs.existsSync(manifestPath)) continue;
|
||||
|
||||
let manifest;
|
||||
try {
|
||||
manifest = JSON.parse(fs.readFileSync(manifestPath, 'utf-8'));
|
||||
manifest = JSON.parse(await fs.readFile(manifestPath, 'utf-8'));
|
||||
} catch { continue; }
|
||||
|
||||
const accountId = manifest.account?.id || '';
|
||||
|
||||
// Scan images
|
||||
const imagesDir = path.join(outputDir, dir.name, 'images');
|
||||
if (fs.existsSync(imagesDir)) {
|
||||
const files = fs.readdirSync(imagesDir);
|
||||
try {
|
||||
const files = await fs.readdir(imagesDir);
|
||||
for (const file of files) {
|
||||
if (!/\.(jpe?g|png|webp)$/i.test(file)) continue;
|
||||
const id = randomUUID();
|
||||
@@ -79,12 +97,12 @@ assetsRouter.post('/scan', (_req, res) => {
|
||||
).run(id, accountId, path.relative(PROJECT_ROOT, manifestPath), 'image', relPath, shotIndex);
|
||||
indexed++;
|
||||
}
|
||||
}
|
||||
} catch { /* images dir may not exist */ }
|
||||
|
||||
// Scan videos
|
||||
const videosDir = path.join(outputDir, dir.name, 'videos');
|
||||
if (fs.existsSync(videosDir)) {
|
||||
const files = fs.readdirSync(videosDir);
|
||||
try {
|
||||
const files = await fs.readdir(videosDir);
|
||||
for (const file of files) {
|
||||
if (!/\.mp4$/i.test(file)) continue;
|
||||
const id = randomUUID();
|
||||
@@ -100,7 +118,7 @@ assetsRouter.post('/scan', (_req, res) => {
|
||||
).run(id, accountId, path.relative(PROJECT_ROOT, manifestPath), 'video', relPath, shotIndex);
|
||||
indexed++;
|
||||
}
|
||||
}
|
||||
} catch { /* videos dir may not exist */ }
|
||||
}
|
||||
|
||||
res.json({ indexed });
|
||||
@@ -112,6 +130,6 @@ assetsRouter.get('/file', (req, res) => {
|
||||
if (!filePath) return res.status(400).send('Missing path');
|
||||
const fullPath = path.resolve(PROJECT_ROOT, filePath);
|
||||
if (!fullPath.startsWith(PROJECT_ROOT)) return res.status(403).send('Forbidden');
|
||||
if (!fs.existsSync(fullPath)) return res.status(404).send('Not found');
|
||||
if (!fss.existsSync(fullPath)) return res.status(404).send('Not found');
|
||||
res.sendFile(fullPath);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user