fix: 退出登录前确认正在下载的任务

This commit is contained in:
2026-10-25 07:37:08 +08:00
parent 8a23318862
commit a96eaff5fb
3 changed files with 58 additions and 7 deletions
+12 -1
View File
@@ -1,4 +1,4 @@
import { api } from "../../shared/http";
import { ApiError, api } from "../../shared/http";
export interface GroupOption {
id: string;
@@ -45,6 +45,17 @@ export function loadJobs() {
return api<{ jobs: DownloadJob[] }>("/api/download/jobs");
}
export async function loadActiveDownloadCount() {
try {
const result = await api<{ count?: number }>("/api/download/active");
if (typeof result?.count === "number" && Number.isFinite(result.count)) return result.count;
} catch (error) {
if (error instanceof ApiError && (error.status === 401 || error.status === 0)) throw error;
}
const result = await loadJobs();
return result.jobs.filter((job) => job.status === "running").length;
}
export function createJob(form: FormData) {
return api<DownloadJob>("/api/download/jobs", { method: "POST", body: form });
}