Repository navigation
feat: download manager #256
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 1 commit
50a633f
a4c620e
f0de032
e2c63b4
fc594c2
5c22e32
999787e
c240dd2
c08a893
644e5b1
26df532
d34a590
ac210f4
84335aa
69c9fb9
9aa4d99
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -60,15 +60,18 @@ ipcMain.handle("downloads:clear-completed", () => { | |||||||||||||||||||||||||||||||||||||||||||||
| if (changed) fireDownloadsChanged(); | ||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+51
to
+61
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧹 Nitpick | 🔵 Trivial Consider checking deletion result in clear-completed loop.
Track actual deletions ipcMain.handle("downloads:clear-completed", () => {
const downloads = listDownloads();
let changed = false;
for (const dl of downloads) {
if (dl.state === "completed" || dl.state === "cancelled") {
- deleteDownloadRecord(dl.id);
- changed = true;
+ const deleted = deleteDownloadRecord(dl.id);
+ if (deleted) changed = true;
}
}
if (changed) fireDownloadsChanged();
});📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| ipcMain.handle("downloads:check-files-exist", (_event, downloadIds: string[]) => { | ||||||||||||||||||||||||||||||||||||||||||||||
| const result: Record<string, boolean> = {}; | ||||||||||||||||||||||||||||||||||||||||||||||
| for (const id of downloadIds) { | ||||||||||||||||||||||||||||||||||||||||||||||
| const record = getDownloadRecord(id); | ||||||||||||||||||||||||||||||||||||||||||||||
| if (!record?.savePath) { | ||||||||||||||||||||||||||||||||||||||||||||||
| result[id] = false; | ||||||||||||||||||||||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||||||||||||||||||||||
| result[id] = fs.existsSync(record.savePath); | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
| return result; | ||||||||||||||||||||||||||||||||||||||||||||||
| ipcMain.handle("downloads:check-files-exist", async (_event, downloadIds: string[]) => { | ||||||||||||||||||||||||||||||||||||||||||||||
| const checks = await Promise.all( | ||||||||||||||||||||||||||||||||||||||||||||||
| downloadIds.map(async (id) => { | ||||||||||||||||||||||||||||||||||||||||||||||
| const record = getDownloadRecord(id); | ||||||||||||||||||||||||||||||||||||||||||||||
| if (!record?.savePath) return [id, false] as const; | ||||||||||||||||||||||||||||||||||||||||||||||
| try { | ||||||||||||||||||||||||||||||||||||||||||||||
| await fs.promises.access(record.savePath); | ||||||||||||||||||||||||||||||||||||||||||||||
| return [id, true] as const; | ||||||||||||||||||||||||||||||||||||||||||||||
| } catch { | ||||||||||||||||||||||||||||||||||||||||||||||
| return [id, false] as const; | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||||
| return Object.fromEntries(checks); | ||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reject duplicate resume requests for the same download.
Until
will-downloadarrives, this record stayspaused/interrupted, soresumeDownload()can be called again and queue a secondcreateInterruptedDownload()for the samedownloadId. Once both events arrive,activeDownloadsByIdgets overwritten andupdated/donefrom the first item can be applied to the second one.💡 Suggested fix
const targetSession = this.getSessionForDownload(record.originProfileId); this.registerSession(targetSession); + if ((this.pendingResumeRequests.get(targetSession) ?? []).some((r) => r.downloadId === downloadId)) { + return false; + } this.enqueuePendingResume(targetSession, { downloadId, savePath: record.savePath!, lastUrl: record.urlChain[record.urlChain.length - 1] ?? record.url, autoResume: true🤖 Prompt for AI Agents