This commit is contained in:
2026-07-15 17:38:48 -05:00
parent 201f5c1b95
commit 2925f8aa35
14 changed files with 2099 additions and 159 deletions

View File

@@ -1,13 +1,22 @@
import { isAbsolute, join, normalize, relative } from "jsr:@std/path";
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.");
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.");
if (rel.startsWith("..") || isAbsolute(rel)) {
throw new Error("Resolved PDF path escapes the base directory.");
}
return full;
}