fix(downloads): harden playlist state and scrolling

This commit is contained in:
NimBold
2026-07-16 16:57:35 +03:30
parent a136fa832c
commit feb5d8e87d
4 changed files with 93 additions and 14 deletions
+49 -2
View File
@@ -293,7 +293,10 @@ describe('add download metadata workflow', () => {
const existing = row({
file: 'old-name.zip',
requestContextVersion: 1,
generation: 2
generation: 2,
size: '10 MB',
sizeBytes: 10,
resumable: true
});
const refreshed = reconcileDownloadRows(
@@ -310,7 +313,47 @@ describe('add download metadata workflow', () => {
file: 'new-name.zip',
status: 'loading',
generation: 3,
requestContextVersion: 2
requestContextVersion: 2,
size: undefined,
sizeBytes: undefined,
resumable: undefined
});
});
it('drops stale playlist provenance when an entry remains after its playlist is removed', () => {
const videoUrl = 'https://www.youtube.com/watch?v=one';
const playlistUrl = 'https://www.youtube.com/playlist?list=PL123';
const existing = row({
sourceUrl: videoUrl,
downloadUrl: videoUrl,
file: '001 - First.mp4',
status: 'ready',
generation: 3,
isMedia: true,
playlistSourceUrl: playlistUrl,
playlistTitle: 'Example playlist',
playlistIndex: 1,
playlistCount: 2,
playlistEntryTitle: 'First',
requestContextVersion: 7,
size: '10 MB',
sizeBytes: 10,
resumable: true
});
const rows = reconcileDownloadRows(videoUrl, [existing]);
expect(rows[0]).toMatchObject({
file: 'watch',
status: 'loading',
generation: 4,
isMedia: true,
playlistSourceUrl: undefined,
playlistIndex: undefined,
size: undefined,
sizeBytes: undefined,
resumable: undefined,
requestContextVersion: undefined
});
});
@@ -425,6 +468,10 @@ describe('add download metadata workflow', () => {
row({ status: 'metadata-error', selected: false }),
row({ id: 'ready', status: 'ready' })
])).toContain('Ready to add 1 download');
expect(metadataSummaryMessage([
row({ status: 'metadata-error' }),
row({ id: 'skipped', status: 'ready', selected: false })
])).toContain('can still be added');
});
it('keeps failed media routing without a format selector', () => {
+24 -6
View File
@@ -182,21 +182,39 @@ export const reconcileDownloadRows = (
const requestContextVersion = input.requestContextVersion;
const contextChanged = requestContextVersion !== undefined
&& requestContextVersion !== preserved.requestContextVersion;
if ((forcedMedia && !preserved.isMedia) || contextChanged) {
const playlistContextChanged = preserved.playlistSourceUrl !== input.playlistSourceUrl
|| preserved.playlistTitle !== input.playlistTitle
|| preserved.playlistIndex !== input.playlistIndex
|| preserved.playlistCount !== input.playlistCount
|| preserved.playlistEntryTitle !== input.playlistEntryTitle;
if ((forcedMedia && !preserved.isMedia) || contextChanged || playlistContextChanged) {
const requestedFilename = input.playlistSourceUrl
? `${playlistFilePrefix(input.playlistIndex, input.playlistCount)}${input.playlistEntryTitle || 'video'}`
: requestFilenames[input.sourceUrl];
return {
...preserved,
file: contextChanged
file: contextChanged || playlistContextChanged
? canonicalizeDownloadFileName(requestedFilename || fileNameFromUrl(input.sourceUrl))
: preserved.file,
status: 'loading',
generation: preserved.generation + 1,
requestContextVersion,
isMedia: preserved.isMedia || forcedMedia,
formats: preserved.isMedia || forcedMedia ? undefined : preserved.formats,
selectedFormat: preserved.isMedia || forcedMedia ? undefined : preserved.selectedFormat,
isMedia: preserved.isMedia || forcedMedia || Boolean(input.playlistSourceUrl),
size: undefined,
sizeBytes: undefined,
resumable: undefined,
formats: preserved.isMedia || forcedMedia || Boolean(input.playlistSourceUrl)
? undefined
: preserved.formats,
selectedFormat: preserved.isMedia || forcedMedia || Boolean(input.playlistSourceUrl)
? undefined
: preserved.selectedFormat,
isPlaylist: input.isPlaylist,
playlistSourceUrl: input.playlistSourceUrl,
playlistTitle: input.playlistTitle,
playlistIndex: input.playlistIndex,
playlistCount: input.playlistCount,
playlistEntryTitle: input.playlistEntryTitle,
playlistError: undefined
};
}
@@ -361,7 +379,7 @@ export const metadataSummaryMessage = (rows: AddDownloadDraftRow[]): string => {
if (failedMedia > 0) {
return `Media metadata is unavailable for ${failedMedia} item${failedMedia === 1 ? '' : 's'}. Refresh metadata before adding.`;
}
if (failed === rows.length) {
if (failed === selectedRows.length) {
return 'Metadata is unavailable. Downloads can still be added using fallback details.';
}
if (failed > 0) {