filename sanitation when downloading to device

This commit is contained in:
daniel-j
2023-12-06 16:50:19 +01:00
parent 9ea7644e62
commit 9ea290685e

View File

@@ -155,9 +155,17 @@ router.get('/download/:key', async ctx => {
return
}
expireKey(key)
console.log('Sending file', info.file.path)
// const fallback = basename(info.file.path)
const sanename = info.file.name.replace(/[^\.\w\-"']/g, '_')
console.log('Sending file', [info.file.path, info.file.name, sanename])
await sendfile(ctx, info.file.path)
ctx.attachment(info.file.name)
if (info.agent.includes('Kindle')) {
// Kindle needs a safe name or it thinks it's an invalid file
ctx.attachment(sanename)
} else {
// Kobo always uses fallback
ctx.attachment(info.file.name, {fallback: sanename})
}
})
router.post('/upload', upload.single('file'), async ctx => {