mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-11-25 16:37:32 +00:00
* fix(cli): make the cache folder private before a pinned download writes into it (SECOPS-2745) The measuring tools' pinned-file downloader (measure/pinnedFiles.ts, for the MediaPipe hand landmarker) made its folder with a plain mkdir, downloaded into it, and only checked the folder was private in the seal afterwards. A folder another account owned, a group/world-writable one, or a link out of the cache received the bytes before the refusal. The model downloaders were worse: the TTS and background-removal models (utils/pinnedFile.ts) and the whisper models never checked at all, and trusted a cached copy from such a folder. Every pinned download into the HyperFrames cache now runs ensurePrivateCacheDir first: a new folder is made 0700, the person's own group/world-writable folder loses those bits, and a link, a foreign owner or a folder another account can change is refused before any partial or final file is written or any cached copy is used. Temp files stay inside the verified folder and are renamed into place. opencv.ts, which already did this, now shares ensurePinnedFiles instead of its own copy of the loop. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(cli): keep the pinned downloaders' comment share at the base (SECOPS-2745) Cuts the comment lines the private-cache fix added to pinnedFiles.ts, pinnedFile.ts and whisper/manager.ts so each file's comment share is back at or under its merge-base share, and names ensurePinnedFile's root cacheRoot so the call reads without the comment. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
40 lines
1.4 KiB
TypeScript
40 lines
1.4 KiB
TypeScript
import { statSync } from "node:fs";
|
|
import { dirname } from "node:path";
|
|
import { ensurePrivateCacheDir } from "@hyperframes/core/cache-dir";
|
|
import { verifies, type ModelFile } from "../whisper/modelFile.js";
|
|
import { downloadFile } from "./download.js";
|
|
|
|
/**
|
|
* `dest` once it holds the pinned bytes: a cached copy that matches is used as it is, any other
|
|
* copy is replaced by a fresh download, and a download that does not match is discarded.
|
|
*/
|
|
export async function ensurePinnedFile(
|
|
url: string,
|
|
dest: string,
|
|
cacheRoot: string,
|
|
pin: ModelFile,
|
|
progress: { downloading: string; onProgress?: (message: string) => void },
|
|
): Promise<string> {
|
|
ensurePrivateCacheDir(dirname(dest), cacheRoot);
|
|
const cached = statSync(dest, { throwIfNoEntry: false }) !== undefined;
|
|
if (cached && (await verifies(dest, pin))) return dest;
|
|
|
|
progress.onProgress?.(
|
|
cached
|
|
? `The cached ${pin.name} does not match its pinned sha256; downloading it again...`
|
|
: progress.downloading,
|
|
);
|
|
await downloadFile(url, dest, {
|
|
keepExisting: (path) => verifies(path, pin),
|
|
verify: async (path) => {
|
|
if (!(await verifies(path, pin))) {
|
|
throw new Error(
|
|
`${pin.name} was discarded because it does not match its expected size and sha256. ` +
|
|
"Retrying helps only if the download was interrupted or corrupted.",
|
|
);
|
|
}
|
|
},
|
|
});
|
|
return dest;
|
|
}
|