fix: 退出登录前确认正在下载的任务
This commit is contained in:
@@ -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 });
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user