Refactor file handling to prioritize internal data directories for backups and uploads; enhance error handling and logging for metadata and CSV operations.
Some checks failed
Code Analysis (JS/Vue) / analyze (push) Failing after 47s
Some checks failed
Code Analysis (JS/Vue) / analyze (push) Failing after 47s
This commit is contained in:
@@ -60,25 +60,34 @@ async function inspect(pdfPath) {
|
||||
async function main() {
|
||||
const repoRoot = process.cwd()
|
||||
const template = path.join(repoRoot, 'server', 'templates', 'mitgliedschaft-fillable.pdf')
|
||||
// pick latest generated PDF in public/uploads that is not the sample
|
||||
// nosemgrep: javascript.lang.security.audit.path-traversal.path-join-resolve-traversal.path-join-resolve-traversal
|
||||
const uploads = path.join(repoRoot, 'public', 'uploads')
|
||||
|
||||
// Prefer internal upload directory used by the API (server/data/uploads).
|
||||
// If legacy files exist in public/uploads, warn and inspect them as well.
|
||||
const internalUploads = path.join(repoRoot, 'server', 'data', 'uploads')
|
||||
const publicUploads = path.join(repoRoot, 'public', 'uploads')
|
||||
|
||||
let pdfFiles = []
|
||||
if (fs.existsSync(uploads)) {
|
||||
pdfFiles = fs.readdirSync(uploads).filter(f => f.toLowerCase().endsWith('.pdf'))
|
||||
if (fs.existsSync(internalUploads)) {
|
||||
pdfFiles = fs.readdirSync(internalUploads).filter(f => f.toLowerCase().endsWith('.pdf'))
|
||||
.map(f => {
|
||||
// nosemgrep: javascript.lang.security.audit.path-traversal.path-join-resolve-traversal.path-join-resolve-traversal
|
||||
const filePath = path.join(uploads, f)
|
||||
return { f, mtime: fs.statSync(filePath).mtimeMs }
|
||||
const filePath = path.join(internalUploads, f)
|
||||
return { f, mtime: fs.statSync(filePath).mtimeMs, dir: internalUploads }
|
||||
})
|
||||
.sort((a,b) => b.mtime - a.mtime)
|
||||
.map(x => x.f)
|
||||
}
|
||||
const apiPdf = pdfFiles.find(n => !n.includes('sample')) || pdfFiles[0]
|
||||
|
||||
// Do NOT fall back to public/uploads to avoid encouraging public exposure.
|
||||
if (pdfFiles.length === 0) {
|
||||
if (fs.existsSync(publicUploads)) {
|
||||
console.warn('WARN: PDFs exist in public/uploads. Please migrate them to server/data/uploads using scripts/migrate-public-galerie-to-metadata.js')
|
||||
}
|
||||
}
|
||||
|
||||
pdfFiles = pdfFiles.sort((a, b) => b.mtime - a.mtime)
|
||||
const apiPdfEntry = pdfFiles.find(e => !e.f.includes('sample')) || pdfFiles[0]
|
||||
|
||||
await inspect(template)
|
||||
// nosemgrep: javascript.lang.security.audit.path-traversal.path-join-resolve-traversal.path-join-resolve-traversal
|
||||
if (apiPdf) await inspect(path.join(uploads, apiPdf))
|
||||
else console.log('No API-generated PDF found in public/uploads')
|
||||
if (apiPdfEntry) await inspect(path.join(apiPdfEntry.dir, apiPdfEntry.f))
|
||||
else console.log('No API-generated PDF found in server/data/uploads or public/uploads')
|
||||
}
|
||||
|
||||
main().catch(e => { console.error(e); process.exit(1) })
|
||||
|
||||
Reference in New Issue
Block a user