重构批量下载逻辑,优化历史显示和下载管理

This commit is contained in:
2025-08-25 09:10:00 +08:00
parent 29ef34b5a9
commit 4033e4eed2
10 changed files with 1240 additions and 254 deletions
+67
View File
@@ -583,4 +583,71 @@ router.get('/stream/:taskId', async (req, res) => {
});
});
/**
* 清理历史记录
* POST /api/download/cleanup/history
*/
router.post('/cleanup/history', async (req, res) => {
try {
const { keepCount = 500 } = req.body;
const downloadService = req.backend.getDownloadService();
const result = await downloadService.cleanupHistory(parseInt(keepCount));
res.json({
success: true,
data: result
});
} catch (error) {
res.status(500).json({
success: false,
error: error.message
});
}
});
/**
* 清理已完成的任务
* POST /api/download/cleanup/tasks
*/
router.post('/cleanup/tasks', async (req, res) => {
try {
const { keepActive = true, keepCompleted = 100 } = req.body;
const downloadService = req.backend.getDownloadService();
const result = await downloadService.cleanupTasks(keepActive, parseInt(keepCompleted));
res.json({
success: true,
data: result
});
} catch (error) {
res.status(500).json({
success: false,
error: error.message
});
}
});
/**
* 获取系统统计信息
* GET /api/download/stats
*/
router.get('/stats', async (req, res) => {
try {
const downloadService = req.backend.getDownloadService();
const result = await downloadService.getSystemStats();
res.json({
success: true,
data: result
});
} catch (error) {
res.status(500).json({
success: false,
error: error.message
});
}
});
module.exports = router;