Files
bizmatch-qc-desktop/src/paths.ts
2026-07-15 17:38:48 -05:00

23 lines
690 B
TypeScript

import { isAbsolute, join, normalize, relative } from "@std/path";
import type { BuyerDocument } from "./types.ts";
export function resolvePdfPath(
baseDirectory: string,
doc: BuyerDocument,
): string {
if (!baseDirectory.trim()) {
throw new Error("PDF base directory is not configured.");
}
if (!isAbsolute(baseDirectory)) {
throw new Error("PDF base directory must be absolute.");
}
const base = normalize(baseDirectory);
const full = normalize(join(base, doc._letter, doc.file_name));
const rel = relative(base, full);
if (rel.startsWith("..") || isAbsolute(rel)) {
throw new Error("Resolved PDF path escapes the base directory.");
}
return full;
}