add custom fallback image, fix #195

This commit is contained in:
lesion
2022-10-28 12:01:59 +02:00
parent 7de0206272
commit 7d0a920eb9
10 changed files with 84 additions and 21 deletions

View File

@@ -176,7 +176,30 @@ const settingsController = {
settingsController.set('logo', baseImgPath)
res.sendStatus(200)
})
},
setFallbackImage (req, res) {
if (!req.file) {
settingsController.set('fallbackImage', false)
return res.status(200)
}
const uploadedPath = path.join(req.file.destination, req.file.filename)
const baseImgPath = path.resolve(config.upload_path, 'fallbackImage.png')
// convert and resize to png
return sharp(uploadedPath)
.resize(600)
.png({ quality: 99 })
.toFile(baseImgPath, (err) => {
if (err) {
log.error('[FALLBACK IMAGE] ' + err)
}
settingsController.set('fallbackImage', baseImgPath)
res.sendStatus(200)
})
}
}
module.exports = settingsController