feat: 增加下载任务中心与断点续传

This commit is contained in:
lofyer
2026-08-05 15:25:26 +08:00
parent f72c26642f
commit cb7b020dc8
20 changed files with 1094 additions and 70 deletions
+21 -6
View File
@@ -483,17 +483,17 @@ const Browse = (() => {
const lib = await window.api.library.findBySource(sourceId, sourcePostId);
const entryId = (lib.ok && lib.data) ? lib.data.id : undefined;
// 传 meta:条目还不在书库时由主进程自动建,避免下载完却找不到文件
// 元数据与页面内进度回调交给全局任务中心,详情页离开后下载仍由它接管
let res;
try {
res = await window.api.downloadFile(
res = await window.DownloadCenter.start({
key: `${sourceId}:${sourcePostId}:${suggestedName}`,
url,
suggestedName,
suggestName: suggestedName,
entryId,
undefined,
meta,
(data) => { if (progress) updateDownloadProgress(progress, data); }
);
onProgress: (data) => { if (progress) updateDownloadProgress(progress, data); }
});
} catch (error) {
res = { ok: false, error: (error && error.message) || String(error) };
}
@@ -503,6 +503,21 @@ const Browse = (() => {
btn.textContent = orig; btn.disabled = false;
return;
}
if (res.ok && res.data && res.data.paused) {
if (progress) {
progress.box.classList.remove('indeterminate');
progress.label.textContent = '已暂停,可在任务中心继续';
}
btn.textContent = '继续';
btn.disabled = false;
return;
}
if (res.ok && res.data && res.data.deleted) {
if (progress) progress.box.remove();
btn.textContent = orig;
btn.disabled = false;
return;
}
if (!res.ok) {
if (progress) {
progress.box.classList.add('failed');