From 2bc4233ba80346e60ed4840714a9aa347ccdb361 Mon Sep 17 00:00:00 2001 From: David Mehren Date: Sun, 27 Oct 2019 15:22:14 +0100 Subject: Move showPublishNote and publishNoteActions to note controller Signed-off-by: David Mehren --- lib/response.js | 82 --------------------------------------------------------- 1 file changed, 82 deletions(-) (limited to 'lib/response.js') diff --git a/lib/response.js b/lib/response.js index 8b027c12..2e944e32 100644 --- a/lib/response.js +++ b/lib/response.js @@ -9,14 +9,11 @@ var config = require('./config') var logger = require('./logger') var models = require('./models') const noteUtil = require('./web/note/util') -const noteController = require('./web/note/controller') const errors = require('./errors') // public var response = { - showPublishNote: showPublishNote, showIndex: showIndex, - publishNoteActions: publishNoteActions, githubActions: githubActions, gitlabActions: gitlabActions } @@ -51,85 +48,6 @@ function showIndex (req, res, next) { } } -function showPublishNote (req, res, next) { - var include = [{ - model: models.User, - as: 'owner' - }, { - model: models.User, - as: 'lastchangeuser' - }] - noteUtil.findNote(req, res, function (note) { - // force to use short id - var 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) - } - var body = note.content - var extracted = models.Note.extractMeta(body) - var markdown = extracted.markdown - var meta = models.Note.parseMeta(extracted.meta) - var createtime = note.createdAt - var updatetime = note.lastchangeAt - var title = models.Note.decodeTitle(note.title) - title = models.Note.generateWebTitle(meta.title || title) - var ogdata = models.Note.parseOpengraph(meta, title) - var data = { - title: title, - description: meta.description || (markdown ? models.Note.generateDescription(markdown) : null), - viewcount: note.viewcount, - createtime: createtime, - updatetime: updatetime, - body: body, - 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, - opengraph: ogdata - } - 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) -} - -function publishNoteActions (req, res, next) { - noteUtil.findNote(req, res, function (note) { - var action = req.params.action - switch (action) { - case 'download': - noteController.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 - } - }) -} - - - function githubActions (req, res, next) { var noteId = req.params.noteId noteUtil.findNote(req, res, function (note) { -- cgit v1.2.3