diff options
author | Sheogorath | 2019-11-20 20:07:35 +0100 |
---|---|---|
committer | GitHub | 2019-11-20 20:07:35 +0100 |
commit | 689f5a0a9583fdd774a271a9e6265ee5356d72a0 (patch) | |
tree | 754bed08f4724a4bc4f91743f6dfe12f92857c01 /lib/web/note/slide.js | |
parent | f894d3c2fa29865288a31cd80cd2a772ce44b330 (diff) | |
parent | b5ccceff59002034fbb089935076f40b8aa16e58 (diff) |
Merge pull request #213 from davidmehren/refactor_backend_notes
First steps in refactoring the backend code
Diffstat (limited to 'lib/web/note/slide.js')
-rw-r--r-- | lib/web/note/slide.js | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/lib/web/note/slide.js b/lib/web/note/slide.js new file mode 100644 index 00000000..d2d2ccfc --- /dev/null +++ b/lib/web/note/slide.js @@ -0,0 +1,45 @@ +const noteUtil = require('./util') +const models = require('../../models') +const errors = require('../../errors') +const logger = require('../../logger') +const config = require('../../config') + +exports.publishSlideActions = function (req, res, next) { + noteUtil.findNote(req, res, function (note) { + const action = req.params.action + if (action === 'edit') { + res.redirect(config.serverURL + '/' + (note.alias ? note.alias : models.Note.encodeNoteId(note.id)) + '?both') + } else { res.redirect(config.serverURL + '/p/' + note.shortid) } + }) +} + +exports.showPublishSlide = 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 + '/p/' + (note.alias || note.shortid)) + } + note.increment('viewcount').then(function (note) { + if (!note) { + return errors.errorNotFound(res) + } + noteUtil.getPublishData(req, res, note, (data) => { + res.set({ + 'Cache-Control': 'private' // only cache by client + }) + return res.render('slide.ejs', data) + }) + }).catch(function (err) { + logger.error(err) + return errors.errorInternalError(res) + }) + }, include) +} |