Move showPublishNote and publishNoteActions to note controller

Signed-off-by: David Mehren <dmehren1@gmail.com>
This commit is contained in:
David Mehren 2019-10-27 15:22:14 +01:00
parent dee62ce571
commit 2bc4233ba8
No known key found for this signature in database
GPG key ID: 6017AF117F9756CB
6 changed files with 99 additions and 125 deletions

View file

@ -3,8 +3,6 @@ const models = require('../../models')
const errors = require('../../errors')
const logger = require('../../logger')
const config = require('../../config')
const fs = require('fs')
const path = require('path')
exports.publishSlideActions = function (req, res, next) {
noteUtil.findNote(req, res, function (note) {
@ -33,34 +31,9 @@ exports.showPublishSlide = function (req, res, next) {
if (!note) {
return errors.errorNotFound(res)
}
const body = note.content
const extracted = models.Note.extractMeta(body)
const markdown = extracted.markdown
const meta = models.Note.parseMeta(extracted.meta)
const createtime = note.createdAt
const updatetime = note.lastchangeAt
let title = models.Note.decodeTitle(note.title)
title = models.Note.generateWebTitle(meta.title || title)
const data = {
title: title,
description: meta.description || (markdown ? models.Note.generateDescription(markdown) : null),
viewcount: note.viewcount,
createtime: createtime,
updatetime: updatetime,
body: markdown,
theme: meta.slideOptions && isRevealTheme(meta.slideOptions.theme),
meta: JSON.stringify(extracted.meta),
owner: note.owner ? note.owner.id : null,
ownerprofile: note.owner ? models.User.getProfile(note.owner) : null,
lastchangeuser: note.lastchangeuser ? note.lastchangeuser.id : null,
lastchangeuserprofile: note.lastchangeuser ? models.User.getProfile(note.lastchangeuser) : null,
robots: meta.robots || false, // default allow robots
GA: meta.GA,
disqus: meta.disqus,
cspNonce: res.locals.nonce,
dnt: req.headers.dnt
}
return renderPublishSlide(data, res)
noteUtil.getPublishData(req, res, note, (data) => {
return renderPublishSlide(data, res)
})
}).catch(function (err) {
logger.error(err)
return errors.errorInternalError(res)
@ -74,10 +47,3 @@ function renderPublishSlide (data, res) {
})
res.render('slide.ejs', data)
}
function isRevealTheme (theme) {
if (fs.existsSync(path.join(__dirname, '..', 'public', 'build', 'reveal.js', 'css', 'theme', theme + '.css'))) {
return theme
}
return undefined
}