asset忘了上传了,重新传一下,增加了模板引擎(见README),修复了printable的目录bug

This commit is contained in:
Nobody committed 2026-11-10 00:35:41 +08:00
1 parent 0817d33309
commit 8b88de4942
7268 files changed
+1257020

No files matched your search

@@ -0,0 +1,26 @@
import { assertEquals } from "@std/assert";
import { DocuBuilder } from "./docu_builder.ts";
Deno.test("PDF rendering loads relative assets from configured file base", async () => {
const chromiumPath = Deno.env.get("CHROMIUM_PATH");
if (!chromiumPath) {
console.warn("Skipping Chromium asset test: CHROMIUM_PATH is unset");
return;
}
const builder = new DocuBuilder({
asset_base: "../../assets",
journal: { build_js_script: false },
});
const pdfPath = await Deno.makeTempFile({ suffix: ".pdf" });
await builder.with_browser();
try {
await builder.build_as_pdf({ path: pdfPath, format: "A4" }, [
'<img src="pictures/rsf.png" alt="Asset">',
]);
} finally {
await builder.close_browser();
}
assertEquals((await Deno.stat(pdfPath)).size > 0, true);
await Deno.remove(pdfPath);
});
@@ -0,0 +1,61 @@
import "openpgp";
import * as openpgp from "openpgp";
import { PathLike } from "node:fs";
export function resolveChromiumPath(): string {
const chromiumPath = Deno.env.get("CHROMIUM_PATH");
if (chromiumPath) {
return chromiumPath;
}
throw new Error(
[
"CHROMIUM_PATH is not set.",
"Use the provided flake shell or set CHROMIUM_PATH manually.",
'Example: export CHROMIUM_PATH="$(command -v chromium)"',
].join("\n"),
);
}
export class OpenPGPSigner {
file_path: PathLike;
output_path: PathLike;
pri_key: Promise<openpgp.PrivateKey>;
pri_passphrase?: string;
constructor(
file: PathLike,
pri_key: PathLike,
output_path: PathLike,
pri_passphrase?: string,
) {
this.file_path = file;
this.output_path = output_path;
this.pri_passphrase = pri_passphrase;
this.pri_key = openpgp.readPrivateKey({
armoredKey: Deno.readTextFileSync(pri_key as string),
});
}
private async getDecryptedPrivateKey(): Promise<openpgp.PrivateKey> {
let privateKey = await this.pri_key;
if (this.pri_passphrase) {
privateKey = await openpgp.decryptKey({
privateKey,
passphrase: this.pri_passphrase,
});
}
return privateKey;
}
async sign() {
const file_bytes = await Deno.readFile(this.file_path as string);
const message = await openpgp.createMessage({ binary: file_bytes });
const signingKey = await this.getDecryptedPrivateKey();
const signature = await openpgp.sign({
message,
signingKeys: signingKey,
format: "armored",
detached: true,
});
await Deno.writeTextFile(this.output_path as string, signature);
}
}