Fix hybrid-extract item matching: use fileName for robust part detection

The previous targetPath-only matching missed items whose targetPath
differed from the on-disk filename. Now matches by basename and
fileName for reliable archive-part to item association.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Sucukdeluxe 2026-03-03 18:22:00 +01:00
parent 9747cabb14
commit 2f43164732

View File

@ -5199,8 +5199,8 @@ export class DownloadManager extends EventEmitter {
const completedItems = items.filter((item) => item.status === "completed"); const completedItems = items.filter((item) => item.status === "completed");
// Build set of item targetPaths belonging to ready archives // Build set of file names belonging to ready archives (for matching items)
const hybridItemPaths = new Set<string>(); const hybridFileNames = new Set<string>();
let dirFiles: string[] | undefined; let dirFiles: string[] | undefined;
try { try {
dirFiles = (await fs.promises.readdir(pkg.outputDir, { withFileTypes: true })) dirFiles = (await fs.promises.readdir(pkg.outputDir, { withFileTypes: true }))
@ -5210,13 +5210,20 @@ export class DownloadManager extends EventEmitter {
for (const archiveKey of readyArchives) { for (const archiveKey of readyArchives) {
const parts = collectArchiveCleanupTargets(archiveKey, dirFiles); const parts = collectArchiveCleanupTargets(archiveKey, dirFiles);
for (const part of parts) { for (const part of parts) {
hybridItemPaths.add(pathKey(part)); hybridFileNames.add(path.basename(part).toLowerCase());
} }
hybridItemPaths.add(pathKey(archiveKey)); hybridFileNames.add(path.basename(archiveKey).toLowerCase());
} }
const hybridItems = completedItems.filter((item) => const isHybridItem = (item: DownloadItem): boolean => {
item.targetPath && hybridItemPaths.has(pathKey(item.targetPath)) if (item.targetPath && hybridFileNames.has(path.basename(item.targetPath).toLowerCase())) {
); return true;
}
if (item.fileName && hybridFileNames.has(item.fileName.toLowerCase())) {
return true;
}
return false;
};
const hybridItems = completedItems.filter(isHybridItem);
const resolveArchiveItems = (archiveName: string): DownloadItem[] => const resolveArchiveItems = (archiveName: string): DownloadItem[] =>
resolveArchiveItemsFromList(archiveName, hybridItems); resolveArchiveItemsFromList(archiveName, hybridItems);