init
This commit is contained in:
13
src/paths.ts
Normal file
13
src/paths.ts
Normal 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;
|
||||
}
|
||||
Reference in New Issue
Block a user