refactor: Update download history logic to exclude cancelled tasks
This commit is contained in:
@@ -11,6 +11,7 @@ interface DownloadTask {
|
||||
cancelFn?: () => void;
|
||||
sourceUrl?: string;
|
||||
type?: string;
|
||||
cancelled?: boolean;
|
||||
}
|
||||
|
||||
class DownloadManager {
|
||||
@@ -141,6 +142,7 @@ class DownloadManager {
|
||||
const task = this.activeTasks.get(id);
|
||||
if (task) {
|
||||
console.log(`Cancelling active download: ${task.title} (${id})`);
|
||||
task.cancelled = true;
|
||||
|
||||
// Call the cancel function if available
|
||||
if (task.cancelFn) {
|
||||
@@ -269,6 +271,7 @@ class DownloadManager {
|
||||
}
|
||||
|
||||
// Add to history
|
||||
if (!task.cancelled) {
|
||||
storageService.addDownloadHistoryItem({
|
||||
id: task.id,
|
||||
title: finalTitle || task.title,
|
||||
@@ -279,6 +282,7 @@ class DownloadManager {
|
||||
sourceUrl: videoData.sourceUrl || task.sourceUrl,
|
||||
author: videoData.author,
|
||||
});
|
||||
}
|
||||
|
||||
// Trigger Cloud Upload (Async, don't await to block queue processing?)
|
||||
// Actually, we might want to await it if we want to ensure it's done before resolving,
|
||||
@@ -298,6 +302,7 @@ class DownloadManager {
|
||||
storageService.removeActiveDownload(task.id);
|
||||
|
||||
// Add to history
|
||||
if (!task.cancelled) {
|
||||
storageService.addDownloadHistoryItem({
|
||||
id: task.id,
|
||||
title: task.title,
|
||||
@@ -306,6 +311,7 @@ class DownloadManager {
|
||||
error: error instanceof Error ? error.message : String(error),
|
||||
sourceUrl: task.sourceUrl,
|
||||
});
|
||||
}
|
||||
|
||||
task.reject(error);
|
||||
} finally {
|
||||
|
||||
Reference in New Issue
Block a user