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

View File

@@ -141,6 +141,7 @@ if (config.status !== 'READY') {
api.post('/settings', isAdmin, settingsController.setRequest)
api.get('/settings', isAdmin, settingsController.getAll)
api.post('/settings/logo', isAdmin, multer({ dest: config.upload_path }).single('logo'), settingsController.setLogo)
api.post('/settings/fallbackImage', isAdmin, multer({ dest: config.upload_path }).single('fallbackImage'), settingsController.setFallbackImage)
api.post('/settings/smtp', isAdmin, settingsController.testSMTP)
api.get('/settings/smtp', isAdmin, settingsController.getSMTPSettings)

View File

@@ -22,7 +22,6 @@ const { JSDOM } = require('jsdom')
const { window } = new JSDOM('<!DOCTYPE html>')
const domPurify = DOMPurify(window)
const url = require('url')
const locales = require('../locales')
domPurify.addHook('beforeSanitizeElements', node => {
if (node.hasAttribute && node.hasAttribute('href')) {
@@ -108,10 +107,14 @@ module.exports = {
}
})
})
router.use('/noimg.svg', express.static('./static/noimg.svg'))
router.use('/fallbackimage.png', (req, res, next) => {
const fallbackImagePath = settingsController.settings.fallbackImage || './static/noimg.svg'
return express.static(fallbackImagePath)(req, res, next)
})
router.use('/logo.png', (req, res, next) => {
const logoPath = res.locals.settings.logo || './static/gancio'
const logoPath = settingsController.settings.logo || './static/gancio'
return express.static(logoPath + '.png')(req, res, next)
})