fix: handle duplicate page entries without render content
This commit is contained in:
parent
4e990d50eb
commit
2890d9ccf0
@ -160,35 +160,39 @@ router.get('/*', async (req, res, next) => {
|
|||||||
return res.status(403).render('unauthorized', { action: 'view' })
|
return res.status(403).render('unauthorized', { action: 'view' })
|
||||||
}
|
}
|
||||||
|
|
||||||
const page = await WIKI.models.pages.getPage({
|
try {
|
||||||
path: pageArgs.path,
|
const page = await WIKI.models.pages.getPage({
|
||||||
locale: pageArgs.locale,
|
path: pageArgs.path,
|
||||||
userId: req.user.id,
|
locale: pageArgs.locale,
|
||||||
isPrivate: false
|
userId: req.user.id,
|
||||||
})
|
isPrivate: false
|
||||||
|
})
|
||||||
|
|
||||||
_.set(res, 'locals.siteConfig.lang', pageArgs.locale)
|
_.set(res, 'locals.siteConfig.lang', pageArgs.locale)
|
||||||
|
|
||||||
if (page) {
|
if (page) {
|
||||||
_.set(res.locals, 'pageMeta.title', page.title)
|
_.set(res.locals, 'pageMeta.title', page.title)
|
||||||
_.set(res.locals, 'pageMeta.description', page.description)
|
_.set(res.locals, 'pageMeta.description', page.description)
|
||||||
const sidebar = await WIKI.models.navigation.getTree({ cache: true })
|
const sidebar = await WIKI.models.navigation.getTree({ cache: true })
|
||||||
const injectCode = {
|
const injectCode = {
|
||||||
css: WIKI.config.theming.injectCSS,
|
css: WIKI.config.theming.injectCSS,
|
||||||
head: WIKI.config.theming.injectHead,
|
head: WIKI.config.theming.injectHead,
|
||||||
body: WIKI.config.theming.injectBody
|
body: WIKI.config.theming.injectBody
|
||||||
}
|
}
|
||||||
res.render('page', { page, sidebar, injectCode })
|
res.render('page', { page, sidebar, injectCode })
|
||||||
} else if (pageArgs.path === 'home') {
|
} else if (pageArgs.path === 'home') {
|
||||||
_.set(res.locals, 'pageMeta.title', 'Welcome')
|
_.set(res.locals, 'pageMeta.title', 'Welcome')
|
||||||
res.render('welcome')
|
res.render('welcome')
|
||||||
} else {
|
|
||||||
_.set(res.locals, 'pageMeta.title', 'Page Not Found')
|
|
||||||
if (WIKI.auth.checkAccess(req.user, ['write:pages'], pageArgs)) {
|
|
||||||
res.status(404).render('new', { pagePath: req.path })
|
|
||||||
} else {
|
} else {
|
||||||
res.status(404).render('notfound', { action: 'view' })
|
_.set(res.locals, 'pageMeta.title', 'Page Not Found')
|
||||||
|
if (WIKI.auth.checkAccess(req.user, ['write:pages'], pageArgs)) {
|
||||||
|
res.status(404).render('new', { pagePath: req.path })
|
||||||
|
} else {
|
||||||
|
res.status(404).render('notfound', { action: 'view' })
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
} catch (err) {
|
||||||
|
next(err)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (!WIKI.auth.checkAccess(req.user, ['read:assets'], pageArgs)) {
|
if (!WIKI.auth.checkAccess(req.user, ['read:assets'], pageArgs)) {
|
||||||
|
@ -18,6 +18,12 @@ module.exports = async (pageId) => {
|
|||||||
const pipeline = await WIKI.models.renderers.getRenderingPipeline(page.contentType)
|
const pipeline = await WIKI.models.renderers.getRenderingPipeline(page.contentType)
|
||||||
|
|
||||||
let output = page.content
|
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) {
|
for (let core of pipeline) {
|
||||||
const renderer = require(`../modules/rendering/${_.kebabCase(core.key)}/renderer.js`)
|
const renderer = require(`../modules/rendering/${_.kebabCase(core.key)}/renderer.js`)
|
||||||
output = await renderer.render.call({
|
output = await renderer.render.call({
|
||||||
|
@ -306,11 +306,20 @@ module.exports = class Page extends Model {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static async getPage(opts) {
|
static async getPage(opts) {
|
||||||
|
// -> Get from cache first
|
||||||
let page = await WIKI.models.pages.getPageFromCache(opts)
|
let page = await WIKI.models.pages.getPageFromCache(opts)
|
||||||
if (!page) {
|
if (!page) {
|
||||||
|
// -> Get from DB
|
||||||
page = await WIKI.models.pages.getPageFromDb(opts)
|
page = await WIKI.models.pages.getPageFromDb(opts)
|
||||||
if (page) {
|
if (page) {
|
||||||
await WIKI.models.pages.savePageToCache(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
|
return page
|
||||||
|
Loading…
Reference in New Issue
Block a user