fix custom logo / favicon
This commit is contained in:
@@ -11,6 +11,7 @@ const toIco = require('to-ico')
|
|||||||
const generateKeyPair = util.promisify(crypto.generateKeyPair)
|
const generateKeyPair = util.promisify(crypto.generateKeyPair)
|
||||||
const readFile = util.promisify(fs.readFile)
|
const readFile = util.promisify(fs.readFile)
|
||||||
const writeFile = util.promisify(fs.writeFile)
|
const writeFile = util.promisify(fs.writeFile)
|
||||||
|
const sharp = require('sharp')
|
||||||
|
|
||||||
const defaultSettings = {
|
const defaultSettings = {
|
||||||
instance_timezone: 'Europe/Rome',
|
instance_timezone: 'Europe/Rome',
|
||||||
@@ -106,19 +107,27 @@ const settingsController = {
|
|||||||
if (ret) { res.sendStatus(200) } else { res.sendStatus(400) }
|
if (ret) { res.sendStatus(200) } else { res.sendStatus(400) }
|
||||||
},
|
},
|
||||||
|
|
||||||
async setLogo (req, res) {
|
setLogo (req, res) {
|
||||||
if (!req.file) {
|
if (!req.file) {
|
||||||
return res.status(400).send('Mmmmm sould not be here!')
|
return res.status(400).send('Mmmmm sould not be here!')
|
||||||
}
|
}
|
||||||
|
|
||||||
const image = await readFile(path.join(req.file.destination, req.file.filename))
|
const uploaded_path = path.join(req.file.destination, req.file.filename)
|
||||||
const favicon_path = path.resolve(config.upload_path, 'favicon.ico')
|
const logo_path = path.resolve(config.upload_path, 'favicon')
|
||||||
const favicon = await toIco([image], { sizes: [64], resize: true })
|
const favicon_path = path.resolve(config.upload_path, 'favicon')
|
||||||
|
|
||||||
writeFile(favicon_path, favicon)
|
// convert and resize to png
|
||||||
settingsController.set('favicon', favicon_path)
|
sharp(uploaded_path)
|
||||||
|
.resize(400)
|
||||||
res.sendStatus(200)
|
.png({ quality: 90 })
|
||||||
|
.toFile(logo_path + '.png', async (err, info) => {
|
||||||
|
console.error(err)
|
||||||
|
const image = await readFile(logo_path + '.png')
|
||||||
|
const favicon = await toIco([image], { sizes: [64], resize: true })
|
||||||
|
writeFile(favicon_path + '.ico', favicon)
|
||||||
|
settingsController.set('favicon', favicon_path)
|
||||||
|
res.sendStatus(200)
|
||||||
|
})
|
||||||
},
|
},
|
||||||
|
|
||||||
getAllRequest (req, res) {
|
getAllRequest (req, res) {
|
||||||
|
|||||||
@@ -26,15 +26,18 @@ app.use((req, res, next) => {
|
|||||||
next()
|
next()
|
||||||
})
|
})
|
||||||
|
|
||||||
// serve favicon and static content
|
|
||||||
app.use('/logo.png', express.static('./static/gancio.png'))
|
|
||||||
app.use('/media/', express.static(config.upload_path))
|
app.use('/media/', express.static(config.upload_path))
|
||||||
|
|
||||||
// initialize instance settings / authentication / locale
|
// initialize instance settings / authentication / locale
|
||||||
app.use(helpers.initSettings)
|
app.use(helpers.initSettings)
|
||||||
|
// serve favicon and static content
|
||||||
|
app.use('/logo.png', (req, res, next) => {
|
||||||
|
const logo_path = req.settings.favicon || './static/gancio'
|
||||||
|
return express.static(logo_path + '.png')(req, res, next)
|
||||||
|
})
|
||||||
|
|
||||||
app.use('/favicon.ico', (req, res, next) => {
|
app.use('/favicon.ico', (req, res, next) => {
|
||||||
const favicon_path = req.settings.favicon || config.favicon || './assets/favicon.ico'
|
const favicon_path = req.settings.favicon || './assets/favicon'
|
||||||
return express.static(path.resolve(favicon_path))(req, res, next)
|
return express.static(favicon_path + '.ico')(req, res, next)
|
||||||
})
|
})
|
||||||
|
|
||||||
// rss/ics/atom feed
|
// rss/ics/atom feed
|
||||||
|
|||||||
Reference in New Issue
Block a user