This commit is contained in:
2026-07-15 16:42:28 -05:00
commit 201f5c1b95
11 changed files with 592 additions and 0 deletions

13
src/paths.ts Normal file
View File

@@ -0,0 +1,13 @@
import { isAbsolute, join, normalize, relative } from "jsr:@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;
}