Add completion-time sort option for downloaded items

This commit is contained in:
tigerenwork 2026-08-21 00:33:55 +08:00
parent 78554ea022
commit a0f7ecec9a
4 changed files with 10 additions and 1 deletions

View File

@ -138,6 +138,7 @@ class DownloadInfo:
self.status = "pending"
self.size = None
self.timestamp = time.time_ns()
self.completion_timestamp = None
self.error = error
self.entry = entry
self.playlist_item_limit = playlist_item_limit
@ -417,6 +418,9 @@ class PersistentQueue:
v.thumbnail = None
if not hasattr(v, 'duration'):
v.duration = None
# Ensure completion timestamp exists (added for completion-time sorting)
if not hasattr(v, 'completion_timestamp'):
v.completion_timestamp = None
self.dict[k] = Download(None, None, None, None, None, None, {}, v)
def exists(self, key):
@ -743,6 +747,7 @@ class DownloadQueue:
if download.canceled:
asyncio.create_task(self.notifier.canceled(download.info.url))
else:
download.info.completion_timestamp = time.time_ns()
self.done.put(download)
asyncio.create_task(self.notifier.completed(download.info))

View File

@ -38,7 +38,7 @@ export class AppComponent implements OnInit, OnDestroy {
status: DownloadTab = 'queued';
selectedFolder = 'all';
filter = '';
sort: 'date' | 'title' | 'size' = 'date';
sort: 'date' | 'completion' | 'title' | 'size' = 'date';
sortAscending = false;
view: 'list' | 'grid' = 'list';
isAdvancedOpen = false;
@ -413,6 +413,8 @@ export class AppComponent implements OnInit, OnDestroy {
rows.sort((a, b) => a.value.title.localeCompare(b.value.title, 'zh') * dir);
} else if (this.sort === 'size') {
rows.sort((a, b) => ((a.value.size || 0) - (b.value.size || 0)) * dir);
} else if (this.sort === 'completion') {
rows.sort((a, b) => ((a.value.completion_timestamp || a.value.timestamp || 0) - (b.value.completion_timestamp || b.value.timestamp || 0)) * dir);
} else {
rows.sort((a, b) => ((a.value.timestamp || 0) - (b.value.timestamp || 0)) * dir);
}

View File

@ -12,6 +12,7 @@
</div>
<select class="tool-select" aria-label="排序方式" [ngModel]="sort" (ngModelChange)="sortChange.emit($event)">
<option value="date">按添加时间</option>
<option value="completion">按完成时间</option>
<option value="title">按标题</option>
<option value="size">按大小</option>
</select>

View File

@ -52,6 +52,7 @@ export interface Download {
duration?: number;
thumbnail?: string;
timestamp?: number;
completion_timestamp?: number;
website?: string;
file_exists?: boolean;
checked?: boolean;