mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-05-13 14:44:43 -04:00
Move showPublishNote and publishNoteActions to note controller
Signed-off-by: David Mehren <dmehren1@gmail.com>
This commit is contained in:
parent
dee62ce571
commit
2bc4233ba8
6 changed files with 99 additions and 125 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue