fix: handle duplicate page entries without render content

This commit is contained in:
Nick 2019-06-25 22:48:23 -04:00
parent 4e990d50eb
commit 2890d9ccf0
3 changed files with 45 additions and 26 deletions

View File

@ -160,6 +160,7 @@ router.get('/*', async (req, res, next) => {
return res.status(403).render('unauthorized', { action: 'view' })
}
try {
const page = await WIKI.models.pages.getPage({
path: pageArgs.path,
locale: pageArgs.locale,
@ -190,6 +191,9 @@ router.get('/*', async (req, res, next) => {
res.status(404).render('notfound', { action: 'view' })
}
}
} catch (err) {
next(err)
}
} else {
if (!WIKI.auth.checkAccess(req.user, ['read:assets'], pageArgs)) {
return res.sendStatus(403)

View File

@ -18,6 +18,12 @@ module.exports = async (pageId) => {
const pipeline = await WIKI.models.renderers.getRenderingPipeline(page.contentType)
let output = page.content
if (_.isEmpty(page.content)) {
await WIKI.models.knex.destroy()
WIKI.logger.warn(`Failed to render page ID ${pageId} because content was empty: [ FAILED ]`)
}
for (let core of pipeline) {
const renderer = require(`../modules/rendering/${_.kebabCase(core.key)}/renderer.js`)
output = await renderer.render.call({

View File

@ -306,11 +306,20 @@ module.exports = class Page extends Model {
}
static async getPage(opts) {
// -> Get from cache first
let page = await WIKI.models.pages.getPageFromCache(opts)
if (!page) {
// -> Get from DB
page = await WIKI.models.pages.getPageFromDb(opts)
if (page) {
if (page.render) {
// -> Save render to cache
await WIKI.models.pages.savePageToCache(page)
} else {
// -> No render? Possible duplicate issue
/* TODO: Detect duplicate and delete */
throw new Error('Error while fetching page. Duplicate entry detected. Reload the page to try again.')
}
}
}
return page