summaryrefslogtreecommitdiff
path: root/lib/web/note/controller.js
diff options
context:
space:
mode:
authorDavid Mehren2019-10-27 15:22:14 +0100
committerDavid Mehren2019-10-27 15:23:38 +0100
commit2bc4233ba80346e60ed4840714a9aa347ccdb361 (patch)
tree1be1516143a0f9c0fe0104f1ca5b9cc209f7f8e7 /lib/web/note/controller.js
parentdee62ce571cc3e33f60499e3ed9cfa4cc5c2f0da (diff)
Move showPublishNote and publishNoteActions to note controller
Signed-off-by: David Mehren <dmehren1@gmail.com>
Diffstat (limited to 'lib/web/note/controller.js')
-rw-r--r--lib/web/note/controller.js52
1 files changed, 52 insertions, 0 deletions
diff --git a/lib/web/note/controller.js b/lib/web/note/controller.js
index 726d3577..991b891d 100644
--- a/lib/web/note/controller.js
+++ b/lib/web/note/controller.js
@@ -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