feat(worker): cross-channel CRC-fingerprint repost check for the forward path

This commit is contained in:
2026-07-31 05:00:14 +02:00
parent a46e746298
commit 960da01ec6
4 changed files with 117 additions and 24 deletions
@@ -0,0 +1,33 @@
import type { Client } from "tdl";
import type { FileEntry } from "./zip-reader.js";
import { compareFingerprints, resolveCandidateFingerprintEntries } from "../provenance-backfill.js";
import { findFingerprintDedupCandidates } from "../db/queries.js";
export interface FingerprintRepostResult {
isDuplicate: boolean;
matchedPackageId: string | null;
}
/**
* Cross-channel duplicate check for the forward-priority path: compare the
* new archive's CRC fingerprint against every existing Package sharing its
* name+size, regardless of which channel or ingestion path produced them.
* This is what lets a forwarded copy dedupe against a previously
* fully-downloaded copy of the same archive, despite never sharing a
* byte-hash-derived contentHash.
*/
export async function checkFingerprintRepost(
client: Client,
entries: FileEntry[],
fileName: string,
fileSize: bigint,
): Promise<FingerprintRepostResult> {
const candidates = await findFingerprintDedupCandidates(fileName, fileSize);
for (const candidate of candidates) {
const candidateEntries = await resolveCandidateFingerprintEntries(client, candidate);
if (compareFingerprints(entries, candidateEntries) === "match") {
return { isDuplicate: true, matchedPackageId: candidate.id };
}
}
return { isDuplicate: false, matchedPackageId: null };
}