mirror of
https://github.com/BobbyWibowo/lolisafe.git
synced 2025-02-07 05:49:01 +00:00
fix: album pages cache
This commit is contained in:
parent
e9736f436c
commit
8f3d6b1557
@ -32,7 +32,7 @@ routes.get('/a/:identifier', async (req, res) => {
|
|||||||
|
|
||||||
const cache = utils.albumRenderStore.get(cacheid)
|
const cache = utils.albumRenderStore.get(cacheid)
|
||||||
if (cache) {
|
if (cache) {
|
||||||
return res.send(cache)
|
return res.type('html').send(cache)
|
||||||
} else if (cache === null) {
|
} else if (cache === null) {
|
||||||
return res.render('album-notice', {
|
return res.render('album-notice', {
|
||||||
config,
|
config,
|
||||||
@ -75,27 +75,25 @@ routes.get('/a/:identifier', async (req, res) => {
|
|||||||
? utils.md.instance.render(album.description)
|
? utils.md.instance.render(album.description)
|
||||||
: null
|
: null
|
||||||
|
|
||||||
return res.render('album', {
|
// This will already end the Response,
|
||||||
|
// thus may only continue with tasks that will not interface with Response any further
|
||||||
|
const html = await res.render('album', {
|
||||||
config,
|
config,
|
||||||
utils,
|
utils,
|
||||||
versions: utils.versionStrings,
|
versions: utils.versionStrings,
|
||||||
album,
|
album,
|
||||||
files,
|
files,
|
||||||
nojs
|
nojs
|
||||||
}, (error, html) => {
|
})
|
||||||
const data = error ? null : html
|
|
||||||
if (cacheid) {
|
if (cacheid) {
|
||||||
// Only store rendered page if it did not error out and album actually have files
|
// Only store rendered page if it did not error out and album actually have files
|
||||||
if (data && files.length) {
|
if (html && files.length) {
|
||||||
utils.albumRenderStore.set(cacheid, data)
|
utils.albumRenderStore.set(cacheid, html)
|
||||||
} else {
|
} else {
|
||||||
utils.albumRenderStore.delete(cacheid)
|
utils.albumRenderStore.delete(cacheid)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Express should already send error to the next handler
|
|
||||||
if (!error) return res.send(data)
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
|
|
||||||
module.exports = routes
|
module.exports = routes
|
||||||
|
Loading…
Reference in New Issue
Block a user