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; }