修复批量下载不添加注册表的问题,增加下载系统鲁棒性

This commit is contained in:
2025-10-03 10:08:29 +08:00
parent 16f60b4b77
commit 6508d2c438
10 changed files with 933 additions and 63 deletions
+14
View File
@@ -73,6 +73,20 @@ class DownloadService {
return apiService.post(`/api/download/resume/${taskId}`);
}
/**
* 暂停批量下载任务
*/
async pauseBatchTask(taskId: string) {
return apiService.post(`/api/download/batch/pause/${taskId}`);
}
/**
* 恢复批量下载任务
*/
async resumeBatchTask(taskId: string) {
return apiService.post(`/api/download/batch/resume/${taskId}`);
}
/**
* 取消任务
*/
+27 -3
View File
@@ -303,7 +303,19 @@ export const useDownloadStore = defineStore('download', () => {
// 恢复任务
const resumeTask = async (taskId: string) => {
try {
const response = await downloadService.resumeTask(taskId);
// 获取任务信息以确定类型
const task = getTask(taskId);
let response;
// 判断是否为批量下载任务(batch、artist、art类型都是批量下载)
if (task && ['batch', 'artist', 'art'].includes(task.type)) {
// 使用批量下载专用API
response = await downloadService.resumeBatchTask(taskId);
} else {
// 使用单个下载API
response = await downloadService.resumeTask(taskId);
}
if (response.success) {
await fetchTasks();
// 重新管理SSE连接
@@ -321,7 +333,19 @@ export const useDownloadStore = defineStore('download', () => {
// 暂停任务
const pauseTask = async (taskId: string) => {
try {
const response = await downloadService.pauseTask(taskId);
// 获取任务信息以确定类型
const task = getTask(taskId);
let response;
// 判断是否为批量下载任务(batch、artist、art类型都是批量下载)
if (task && ['batch', 'artist', 'art'].includes(task.type)) {
// 使用批量下载专用API
response = await downloadService.pauseBatchTask(taskId);
} else {
// 使用单个下载API
response = await downloadService.pauseTask(taskId);
}
if (response.success) {
await fetchTasks();
} else {
@@ -410,4 +434,4 @@ export const useDownloadStore = defineStore('download', () => {
startRefreshInterval,
stopRefreshInterval
};
});
});
+33 -7
View File
@@ -62,6 +62,9 @@
</span>
</div>
<div class="task-actions">
<button v-if="task.status === 'downloading'" @click="pauseTask(task.id)" class="btn btn-warning btn-sm">
暂停
</button>
<button v-if="task.status === 'downloading'" @click="cancelTask(task.id)" class="btn btn-danger btn-sm">
取消
</button>
@@ -281,11 +284,11 @@ const getHistoryTitle = (item: any) => {
const count = item.total_files || 0;
let title = '排行榜下载';
if (item.mode && item.ranking_type) {
const modeText = item.mode === 'daily' ? '日榜' :
item.mode === 'weekly' ? '周榜' :
item.mode === 'monthly' ? '月榜' : item.mode;
const typeText = item.ranking_type === 'illust' ? '插画' :
item.ranking_type === 'manga' ? '漫画' : item.ranking_type;
const modeText = item.mode === 'daily' ? '日榜' :
item.mode === 'weekly' ? '周榜' :
item.mode === 'monthly' ? '月榜' : item.mode;
const typeText = item.ranking_type === 'illust' ? '插画' :
item.ranking_type === 'manga' ? '漫画' : item.ranking_type;
title = `${modeText}${typeText}`;
}
return `${title} - ${count} 个作品`;
@@ -370,6 +373,16 @@ const resumeTask = async (taskId: string) => {
}
};
// 暂停任务
const pauseTask = async (taskId: string) => {
try {
await downloadStore.pauseTask(taskId);
} catch (err) {
error.value = err instanceof Error ? err.message : '暂停任务失败';
console.error('暂停任务失败:', err);
}
};
// 清理历史记录
const cleanupHistory = async () => {
if (confirm('确定要清理下载历史吗?这将保留最新的500条记录。')) {
@@ -783,7 +796,7 @@ onUnmounted(() => {
background-clip: text;
}
.stat-value.success + .stat-label {
.stat-value.success+.stat-label {
color: #047857;
}
@@ -799,7 +812,7 @@ onUnmounted(() => {
background-clip: text;
}
.stat-value.error + .stat-label {
.stat-value.error+.stat-label {
color: #b91c1c;
}
@@ -905,6 +918,19 @@ onUnmounted(() => {
box-shadow: 0 4px 6px -1px rgba(220, 38, 38, 0.3);
}
.btn-warning {
background: #f59e0b;
color: white;
border: 1px solid #f59e0b;
}
.btn-warning:hover:not(:disabled) {
background: #d97706;
border-color: #d97706;
transform: translateY(-1px);
box-shadow: 0 4px 6px -1px rgba(245, 158, 11, 0.3);
}
@media (max-width: 768px) {
.container {
padding: 0 1rem;