增加了自动openpgp签名选项,修改了打印版本的样式
This commit is contained in:
1 parent
59a5400fe1
commit
7a3f8b0e81
51 files changed
+1176
-419
No files matched your search
@@ -4,7 +4,9 @@ import MarkdownIt from "markdown-it";
|
||||
import TurndownService from "turndown";
|
||||
import { PDFParse } from "pdf-parse";
|
||||
import { PDFDocument, PDFHexString, PDFName } from "pdf-lib";
|
||||
|
||||
import "openpgp";
|
||||
import * as openpgp from "openpgp";
|
||||
import { PathLike } from "node:fs";
|
||||
function resolveChromiumPath(): string {
|
||||
const chromiumPath = Deno.env.get("CHROMIUM_PATH");
|
||||
if (chromiumPath) {
|
||||
@@ -88,26 +90,40 @@ export class DocuBuilder {
|
||||
const html = this.pages.join("\n");
|
||||
|
||||
// Ensure a DOMParser is available; if not, try to load deno_dom dynamically.
|
||||
let domParserCtor = (globalThis as {
|
||||
DOMParser?: new () => {
|
||||
let domParserCtor: {
|
||||
new (): {
|
||||
parseFromString: (
|
||||
html: string,
|
||||
mimeType: string,
|
||||
) => { documentElement?: { outerHTML: string } } | null;
|
||||
};
|
||||
}).DOMParser;
|
||||
} | undefined = (globalThis as { DOMParser?: unknown }).DOMParser as
|
||||
| {
|
||||
new (): {
|
||||
parseFromString: (
|
||||
html: string,
|
||||
mimeType: string,
|
||||
) => { documentElement?: { outerHTML: string } } | null;
|
||||
};
|
||||
}
|
||||
| undefined;
|
||||
|
||||
if (domParserCtor == null) {
|
||||
try {
|
||||
const denoDom = await import(
|
||||
// deno-lint-ignore no-import-prefix
|
||||
"https://deno.land/x/deno_dom/deno-dom-wasm.ts"
|
||||
);
|
||||
if (denoDom && denoDom.DOMParser) {
|
||||
// deno-lint-ignore no-explicit-any
|
||||
(globalThis as any).DOMParser = denoDom.DOMParser;
|
||||
domParserCtor = denoDom.DOMParser;
|
||||
// Cast via unknown to satisfy TypeScript when converting between incompatible constructor types
|
||||
domParserCtor = denoDom
|
||||
.DOMParser as unknown as typeof domParserCtor;
|
||||
}
|
||||
} catch (e) {
|
||||
// ignore; will throw below with helpful message
|
||||
console.error(e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -419,3 +435,29 @@ export class IndexBuilder {
|
||||
await Deno.writeFile(this.file_path, outlinedPdfBytes);
|
||||
}
|
||||
}
|
||||
|
||||
export class OpenPGPSigner {
|
||||
file_path: PathLike;
|
||||
output_path: PathLike;
|
||||
pri_key: Promise<openpgp.PrivateKey>;
|
||||
|
||||
constructor(file: PathLike, pri_key: PathLike, output_path: PathLike) {
|
||||
this.file_path = file;
|
||||
this.output_path = output_path;
|
||||
this.pri_key = openpgp.readPrivateKey({
|
||||
armoredKey: Deno.readTextFileSync(pri_key as string),
|
||||
});
|
||||
}
|
||||
|
||||
async sign() {
|
||||
const file_bytes = await Deno.readFile(this.file_path as string);
|
||||
const message = await openpgp.createMessage({ binary: file_bytes });
|
||||
const signature = await openpgp.sign({
|
||||
message,
|
||||
signingKeys: await this.pri_key,
|
||||
format: "armored",
|
||||
detached: true,
|
||||
});
|
||||
await Deno.writeTextFile(this.output_path as string, signature);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user