function registerFileRoutes(app, deps) { app.get('/api/files/whisper/:videoId', (req, res) => { try { const manifest = deps.readManifest(); const video = manifest.find((item) => item.id === req.params.videoId); if (!video) { return res.status(404).json({ error: `未找到视频: ${req.params.videoId}` }); } const baseName = video.filename.replace(/\.[^.]+$/, ''); const outputDir = deps.path.join(deps.whisperDir, baseName); if (!deps.fs.existsSync(outputDir)) { return res.json({ files: [], exists: false }); } const files = deps.fs.readdirSync(outputDir).map((fileName) => ({ name: fileName, path: `Whisper/${baseName}/${fileName}`, size: deps.fs.statSync(deps.path.join(outputDir, fileName)).size })); res.json({ files, exists: true }); } catch (err) { res.status(500).json({ error: err.message }); } }); app.get('/api/files/read', (req, res) => { const filePath = req.query.path; if (!filePath) { return res.status(400).json({ error: '缺少 path 参数' }); } const fullPath = deps.path.join(deps.projectRoot, filePath); if (!fullPath.startsWith(deps.projectRoot)) { return res.status(403).json({ error: '路径不在项目目录内' }); } if (!deps.fs.existsSync(fullPath)) { return res.status(404).json({ error: '文件不存在' }); } const ext = deps.path.extname(fullPath).toLowerCase(); if (ext === '.json') { return res.json(JSON.parse(deps.fs.readFileSync(fullPath, 'utf-8'))); } res.type('text/plain').send(deps.fs.readFileSync(fullPath, 'utf-8')); }); } module.exports = { registerFileRoutes };