new hide_calendar / hide_thumbs / header_image settings

This commit is contained in:
lesion
2022-11-09 10:17:52 +01:00
parent 68b7fc6cd0
commit 31cfef1d89
9 changed files with 111 additions and 21 deletions

View File

@@ -36,6 +36,8 @@ const defaultSettings = {
trusted_instances: [],
'theme.is_dark': true,
'theme.primary': '#FF4500',
hide_thumbs: false,
hide_calendar: false,
footerLinks: [
{ href: '/', label: 'home' },
{ href: '/about', label: 'about' }
@@ -180,7 +182,7 @@ const settingsController = {
setFallbackImage (req, res) {
if (!req.file) {
settingsController.set('fallbackImage', false)
settingsController.set('fallback_image', false)
return res.status(200)
}
@@ -195,7 +197,29 @@ const settingsController = {
if (err) {
log.error('[FALLBACK IMAGE] ' + err)
}
settingsController.set('fallbackImage', baseImgPath)
settingsController.set('fallback_image', baseImgPath)
res.sendStatus(200)
})
},
setHeaderImage (req, res) {
if (!req.file) {
settingsController.set('header_image', 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('[HEADER IMAGE] ' + err)
}
settingsController.set('header_image', baseImgPath)
res.sendStatus(200)
})
}

View File

@@ -142,6 +142,7 @@ if (config.status !== 'READY') {
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/headerImage', isAdmin, multer({ dest: config.upload_path }).single('headerImage'), settingsController.setHeaderImage)
api.post('/settings/smtp', isAdmin, settingsController.testSMTP)
api.get('/settings/smtp', isAdmin, settingsController.getSMTPSettings)

View File

@@ -88,7 +88,10 @@ module.exports = {
trusted_instances: settings.trusted_instances,
'theme.is_dark': settings['theme.is_dark'],
'theme.primary': settings['theme.primary'],
footerLinks: settings.footerLinks
hide_thumbs: settings.hide_thumbs,
hide_calendar: settings.hide_calendar,
footerLinks: settings.footerLinks,
about: settings.about
}
// set user locale
res.locals.user_locale = settingsController.user_locale[res.locals.acceptedLocale]
@@ -114,18 +117,23 @@ module.exports = {
})
router.use('/fallbackimage.png', (req, res, next) => {
const fallbackImagePath = settingsController.settings.fallbackImage || './static/noimg.svg'
return express.static(fallbackImagePath)(req, res, next)
const fallbackImagePath = settingsController.settings.fallback_image || './static/noimg.svg'
return express.static(fallbackImagePath, { maxAge: '1d' })(req, res, next)
})
router.use('/headerimage.png', (req, res, next) => {
const headerImagePath = settingsController.settings.header_image || './static/noimg.svg'
return express.static(headerImagePath)(req, res, next)
})
router.use('/logo.png', (req, res, next) => {
const logoPath = settingsController.settings.logo || './static/gancio'
return express.static(logoPath + '.png')(req, res, next)
return express.static(logoPath + '.png', {maxAge: '1d'})(req, res, next)
})
router.use('/favicon.ico', (req, res, next) => {
const faviconPath = res.locals.settings.logo ? res.locals.settings.logo + '.png' : './assets/favicon.ico'
return express.static(faviconPath)(req, res, next)
return express.static(faviconPath, {maxAge: '1d'})(req, res, next)
})
return router