Files
Multi-Debrid-Downloader/src/renderer/collector-enrichment.ts
T
Sucukdeluxe 2ea494cd5c Prepare v2.0.74 sidepanel reliability release
Restore and persist the package-based link collector with progressive metadata, bounded high-volume updates, safe hydration, visible selection, and complete localization.

Harden download controls, snapshot ordering, history pagination, statistics recovery, settings saves, backup imports, notification persistence, and Windows storage races with regression coverage.
2026-08-26 20:35:06 +02:00

50 lines
1.6 KiB
TypeScript

import type { CollectorPackage } from "../shared/collector";
export type CollectorEnrichmentGenerationSnapshot = Map<string, number>;
function collectorUrlKey(url: string): string {
return url.trim();
}
export function beginCollectorEnrichment(
packages: CollectorPackage[],
current: Map<string, number>
): CollectorEnrichmentGenerationSnapshot {
const snapshot = new Map<string, number>();
for (const link of packages.flatMap((pkg) => pkg.links)) {
const url = collectorUrlKey(link.url);
const generation = (current.get(url) ?? 0) + 1;
current.set(url, generation);
snapshot.set(url, generation);
}
return snapshot;
}
export function pruneCollectorEnrichmentGenerations(
current: Map<string, number>,
packages: CollectorPackage[],
activeSnapshots: Iterable<ReadonlyMap<string, number>>
): void {
const retainedUrls = new Set(packages.flatMap((pkg) => pkg.links.map((link) => collectorUrlKey(link.url))));
for (const snapshot of activeSnapshots) {
for (const url of snapshot.keys()) retainedUrls.add(url);
}
for (const url of current.keys()) {
if (!retainedUrls.has(url)) current.delete(url);
}
}
export function filterCurrentCollectorEnrichment(
packages: CollectorPackage[],
requested: CollectorEnrichmentGenerationSnapshot,
current: ReadonlyMap<string, number>
): CollectorPackage[] {
return packages.flatMap((pkg) => {
const links = pkg.links.filter((link) => {
const url = collectorUrlKey(link.url);
return requested.get(url) === current.get(url);
});
return links.length > 0 ? [{ ...pkg, links }] : [];
});
}