diff --git a/packages/server/client/printer.ts b/packages/server/client/printer.ts index 9d72d71..cc508c7 100644 --- a/packages/server/client/printer.ts +++ b/packages/server/client/printer.ts @@ -56,10 +56,10 @@ function escapeText(s: string) { return res; } -export async function ConvertCodeToPDF(code: Buffer, lang, filename, team, location, codeColor = false) { +export async function ConvertCodeToPDF(code: Buffer, lang, filename, team, location, createAt, codeColor = false) { compiler ||= await createTypstCompiler(); const fakeFilename = randomstring(8); // cubercsl: do not trust filename from user - const typst = generateTypst(team, location, fakeFilename, filename, lang, codeColor); + const typst = generateTypst(team, location, fakeFilename, filename, lang, createAt, codeColor); compiler.addSource('/main.typst', typst); compiler.addSource(`/${fakeFilename}`, escapeText(toUtf8(code))); logger.info(`Convert ${filename} to PDF`); @@ -82,7 +82,7 @@ export async function printFile(docs) { const files = []; for (const doc of docs) { const { - _id, tid, code, lang, filename, team, location, + _id, tid, code, lang, filename, team, location, createAt, } = doc; const pdf = await ConvertCodeToPDF( code ? Buffer.from(code, 'base64') : Buffer.from('empty file'), @@ -90,6 +90,7 @@ export async function printFile(docs) { filename, team, location, + createAt, config.printColor, ); fs.writeFileSync(path.resolve(process.cwd(), `data${path.sep}${tid}#${_id}.pdf`), pdf); diff --git a/packages/server/client/typst.ts b/packages/server/client/typst.ts index e5ba637..413f4b6 100644 --- a/packages/server/client/typst.ts +++ b/packages/server/client/typst.ts @@ -57,9 +57,9 @@ class TypstCompilerDriver { } } -export function generateTypst(team: string, location: string, filename: string, originalFilename: string, lang: string, codeColor: boolean) { +export function generateTypst(team: string, location: string, filename: string, originalFilename: string, lang: string, createAt: number, codeColor: boolean) { return ` -#let fit(name: "", width: 147mm) = { +#let fit(name: "", width: 100mm) = { context { if measure(text(name)).width < width { return name @@ -92,6 +92,8 @@ export function generateTypst(team: string, location: string, filename: string, text(weight: "black", size: 10pt)[[#location] ] } #fit(name: team) + #h(1fr) + ${new Date(createAt).toLocaleString('zh')} #linebreak() filename: #original #h(1fr) diff --git a/packages/server/handler/printer.ts b/packages/server/handler/printer.ts index 22ccd49..7c710a7 100644 --- a/packages/server/handler/printer.ts +++ b/packages/server/handler/printer.ts @@ -29,6 +29,7 @@ class PrintAdminHandler extends AuthHandler { code.filename, code.team, code.location, + code.createAt, params.color ?? true, ); this.response.type = 'application/pdf';