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

@ -8,6 +8,58 @@ const errors = require('../../errors')
const noteUtil = require('./util')
const noteActions = require('./actions')
exports.publishNoteActions = function (req, res, next) {
noteUtil.findNote(req, res, function (note) {
const action = req.params.action
switch (action) {
case 'download':
exports.downloadMarkdown(req, res, note)
break
case 'edit':
res.redirect(config.serverURL + '/' + (note.alias ? note.alias : models.Note.encodeNoteId(note.id)) + '?both')
break
default:
res.redirect(config.serverURL + '/s/' + note.shortid)
break
}
})
}
exports.showPublishNote = function (req, res, next) {
const include = [{
model: models.User,
as: 'owner'
}, {
model: models.User,
as: 'lastchangeuser'
}]
noteUtil.findNote(req, res, function (note) {
// force to use short id
const shortid = req.params.shortid
if ((note.alias && shortid !== note.alias) || (!note.alias && shortid !== note.shortid)) {
return res.redirect(config.serverURL + '/s/' + (note.alias || note.shortid))
}
note.increment('viewcount').then(function (note) {
if (!note) {
return errors.errorNotFound(res)
}
noteUtil.getPublishData(req, res, note, (data) => {
return renderPublish(data, res)
})
}).catch(function (err) {
logger.error(err)
return errors.errorInternalError(res)
})
}, include)
}
function renderPublish (data, res) {
res.set({
'Cache-Control': 'private' // only cache by client
})
res.render('pretty.ejs', data)
}
exports.showNote = function (req, res, next) {
noteUtil.findNote(req, res, function (note) {
// force to use note id