fix: Codex review P2 issues + frontend test failure

- Reset download_phase when transitioning to paused (pause(), update_status(),
  _post_download_cleanup()) so UI shows 'Paused' instead of stale phase label
- Reset download_phase when starting/resuming download (start() preparing state)
- Count 'postprocessing' as active download in updateMetrics() so dashboard
  shows accurate counts during ffmpeg post-processing
- Add missing completedDownload Subject to DownloadsServiceStub in app.spec.ts
- Add Download type import to app.spec.ts

Fixes: TypeError Cannot read properties of undefined (reading 'pipe')
       at app.ts:300 (completedDownload not in test stub)
This commit is contained in:
TonyBlu 2026-05-25 20:09:17 +08:00
parent 03cee14948
commit e639caa21d
3 changed files with 8 additions and 0 deletions

View file

@ -647,6 +647,7 @@ class Download:
self.loop = asyncio.get_running_loop()
self.notifier = notifier
self.info.status = 'preparing'
self.info.download_phase = None
await self.notifier.updated(self.info)
self.status_task = asyncio.create_task(self.update_status())
await self.loop.run_in_executor(None, self.proc.join)
@ -673,6 +674,7 @@ class Download:
self.paused = True
self.start_generation += 1
self.info.status = 'paused'
self.info.download_phase = None
self.info.speed = None
self.info.eta = None
if self.running():
@ -705,6 +707,7 @@ class Download:
return
if self.paused:
self.info.status = 'paused'
self.info.download_phase = None
self.info.speed = None
self.info.eta = None
await self.notifier.updated(self.info)
@ -988,6 +991,7 @@ class DownloadQueue:
key = getattr(download.info, 'key', download.info.url)
if download.paused:
download.info.status = 'paused'
download.info.download_phase = None
download.info.speed = None
download.info.eta = None
download.close()

View file

@ -5,6 +5,7 @@ import { App } from './app';
import { DownloadsService } from './services/downloads.service';
import { SubscriptionsService } from './services/subscriptions.service';
import { CookieService } from 'ngx-cookie-service';
import { Download } from './interfaces';
class DownloadsServiceStub {
loading = false;
@ -18,6 +19,7 @@ class DownloadsServiceStub {
customDirsChanged = new Subject<Record<string, string[]>>();
ytdlOptionsChanged = new Subject<Record<string, unknown>>();
updated = new Subject<void>();
completedDownload = new Subject<Download>();
getCookieStatus() {
return of({ status: 'ok', has_cookies: false });

View file

@ -1651,6 +1651,8 @@ export class App implements AfterViewInit, OnInit, OnDestroy {
speed += download.speed || 0;
} else if (download.status === 'preparing') {
active++;
} else if (download.status === 'postprocessing') {
active++;
} else if (download.status === 'pending' || download.status === 'paused') {
queued++;
}