Files
Goldebek/scripts/check-download-metadata.mjs
T
Per Hoener 0d45331f5c
Deploy / validate-dispatch (push) Successful in 43s
Deploy / scheduled-rebuild-dev (push) Skipped
Deploy / scheduled-rebuild-master (push) Skipped
Deploy / rollback-dev (push) Skipped
Deploy / rollback-master (push) Skipped
Deploy / changes (push) Successful in 13s
Deploy / secret-scan (push) Successful in 9s
Deploy / app-quality (push) Successful in 11m21s
Deploy / security-deps (push) Successful in 14s
Deploy / context (push) Failing after 1s
Deploy / app-image (push) Skipped
Deploy / deploy-dev (push) Skipped
Deploy / deploy-master (push) Skipped
Initial commit
2026-09-18 23:37:19 +02:00

31 lines
1.0 KiB
JavaScript

import fs from "node:fs";
import path from "node:path";
const DOWNLOADS_DIR = path.resolve(import.meta.dirname, "../public/downloads");
const PDF_METADATA_PATTERN =
/\/(?:Title|Author|Subject|Keywords|Creator|CreationDate|ModDate)\s*\(|<xmp:(?:CreatorTool|CreateDate|ModifyDate)>|<dc:(?:creator|title)>|<pdf:Keywords>/i;
function collectPdfs(directory) {
if (!fs.existsSync(directory)) return [];
return fs
.readdirSync(directory, { withFileTypes: true })
.filter((entry) => entry.isFile() && entry.name.toLowerCase().endsWith(".pdf"))
.map((entry) => path.join(directory, entry.name));
}
const files = collectPdfs(DOWNLOADS_DIR);
const filesWithMetadata = files.filter((file) =>
PDF_METADATA_PATTERN.test(fs.readFileSync(file, "latin1")),
);
for (const file of filesWithMetadata) {
console.error(`[downloads:check-metadata] PDF metadata found: ${file}`);
}
if (filesWithMetadata.length > 0) {
process.exitCode = 1;
} else {
console.log(`[downloads:check-metadata] ${files.length} PDFs checked; no document metadata found.`);
}