Files
harheimertc/server/utils/upload-validation.js
Torsten Schulz (local) 3586704cce
Some checks failed
Code Analysis and Production Deploy / analyze (push) Failing after 10m29s
Code Analysis and Production Deploy / deploy-production (push) Has been skipped
Code Analysis and Production Deploy / deploy-test (push) Has been skipped
Update file permissions for multiple server and test files to executable mode
2026-07-15 08:45:12 +02:00

22 lines
489 B
JavaScript
Executable File

import fs from 'fs/promises'
export async function assertPdfMagicHeader(filePath) {
const fh = await fs.open(filePath, 'r')
try {
const buf = Buffer.alloc(5)
await fh.read(buf, 0, 5, 0)
const header = buf.toString('utf8')
if (header !== '%PDF-') {
throw createError({ statusCode: 400, statusMessage: 'Ungültige Datei: kein PDF' })
}
} finally {
await fh.close()
}
}
export function clamp(n, min, max) {
return Math.max(min, Math.min(max, n))
}