summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorDavid Mehren2019-10-27 14:40:36 +0100
committerDavid Mehren2019-10-27 14:40:36 +0100
commit30487f7c01dc15435d86d95d24257853d7930154 (patch)
treecc34d4b2b13f0502583fc953fc3a3dba49c9d30a /lib
parentafb317b55155eed2cfcad0fee5aba2107dc0b106 (diff)
Rename actions.js to controller.js and rename functions to be more descriptive
Move postNote to NoteController and rename to createFromPost Signed-off-by: David Mehren <dmehren1@gmail.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/response.js16
-rw-r--r--lib/web/note/controller.js (renamed from lib/web/note/actions.js)39
-rw-r--r--lib/web/note/router.js12
3 files changed, 33 insertions, 34 deletions
diff --git a/lib/response.js b/lib/response.js
index 934179fd..20612b68 100644
--- a/lib/response.js
+++ b/lib/response.js
@@ -9,7 +9,7 @@ var config = require('./config')
var logger = require('./logger')
var models = require('./models')
const noteUtil = require('./web/note/util')
-const noteActions = require('./web/note/actions')
+const noteController = require('./web/note/controller')
const errors = require('./errors')
// public
@@ -17,7 +17,6 @@ var response = {
showNote: showNote,
showPublishNote: showPublishNote,
showIndex: showIndex,
- postNote: postNote,
publishNoteActions: publishNoteActions,
githubActions: githubActions,
gitlabActions: gitlabActions
@@ -70,17 +69,6 @@ function responseCodiMD (res, note) {
})
}
-function postNote (req, res, next) {
- var body = ''
- if (req.body && req.body.length > config.documentMaxLength) {
- return errors.errorTooLong(res)
- } else if (req.body) {
- body = req.body
- }
- body = body.replace(/[\r]/g, '')
- return noteUtil.newNote(req, res, body)
-}
-
function showNote (req, res, next) {
noteUtil.findNote(req, res, function (note) {
// force to use note id
@@ -156,7 +144,7 @@ function publishNoteActions (req, res, next) {
var action = req.params.action
switch (action) {
case 'download':
- noteActions.actionDownload(req, res, note)
+ noteController.downloadMarkdown(req, res, note)
break
case 'edit':
res.redirect(config.serverURL + '/' + (note.alias ? note.alias : models.Note.encodeNoteId(note.id)) + '?both')
diff --git a/lib/web/note/actions.js b/lib/web/note/controller.js
index a124277a..c89cc5de 100644
--- a/lib/web/note/actions.js
+++ b/lib/web/note/controller.js
@@ -11,6 +11,17 @@ const moment = require('moment')
const querystring = require('querystring')
const noteUtil = require('./util')
+exports.createFromPOST = function (req, res, next) {
+ let body = ''
+ if (req.body && req.body.length > config.documentMaxLength) {
+ return errors.errorTooLong(res)
+ } else if (req.body) {
+ body = req.body
+ }
+ body = body.replace(/[\r]/g, '')
+ return noteUtil.newNote(req, res, body)
+}
+
exports.doAction = function (req, res, next) {
const noteId = req.params.noteId
noteUtil.findNote(req, res, function (note) {
@@ -18,30 +29,30 @@ exports.doAction = function (req, res, next) {
switch (action) {
case 'publish':
case 'pretty': // pretty deprecated
- actionPublish(req, res, note)
+ publish(req, res, note)
break
case 'slide':
- actionSlide(req, res, note)
+ slide(req, res, note)
break
case 'download':
- exports.actionDownload(req, res, note)
+ exports.downloadMarkdown(req, res, note)
break
case 'info':
- actionInfo(req, res, note)
+ getInfo(req, res, note)
break
case 'pdf':
if (config.allowPDFExport) {
- actionPDF(req, res, note)
+ createPDF(req, res, note)
} else {
logger.error('PDF export failed: Disabled by config. Set "allowPDFExport: true" to enable. Check the documentation for details')
errors.errorForbidden(res)
}
break
case 'gist':
- actionGist(req, res, note)
+ createGist(req, res, note)
break
case 'revision':
- actionRevision(req, res, note)
+ getRevision(req, res, note)
break
default:
return res.redirect(config.serverURL + '/' + noteId)
@@ -49,15 +60,15 @@ exports.doAction = function (req, res, next) {
})
}
-function actionPublish (req, res, note) {
+function publish (req, res, note) {
res.redirect(config.serverURL + '/s/' + (note.alias || note.shortid))
}
-function actionSlide (req, res, note) {
+function slide (req, res, note) {
res.redirect(config.serverURL + '/p/' + (note.alias || note.shortid))
}
-exports.actionDownload = function (req, res, note) {
+exports.downloadMarkdown = function (req, res, note) {
const body = note.content
let filename = models.Note.decodeTitle(note.title)
filename = encodeURIComponent(filename)
@@ -73,7 +84,7 @@ exports.actionDownload = function (req, res, note) {
res.send(body)
}
-function actionInfo (req, res, note) {
+function getInfo (req, res, note) {
const body = note.content
const extracted = models.Note.extractMeta(body)
const markdown = extracted.markdown
@@ -98,7 +109,7 @@ function actionInfo (req, res, note) {
res.send(data)
}
-function actionPDF (req, res, note) {
+function createPDF (req, res, note) {
const url = config.serverURL || 'http://' + req.get('host')
const body = note.content
const extracted = models.Note.extractMeta(body)
@@ -129,7 +140,7 @@ function actionPDF (req, res, note) {
})
}
-function actionGist (req, res, note) {
+function createGist (req, res, note) {
const data = {
client_id: config.github.clientID,
redirect_uri: config.serverURL + '/auth/github/callback/' + models.Note.encodeNoteId(note.id) + '/gist',
@@ -140,7 +151,7 @@ function actionGist (req, res, note) {
res.redirect('https://github.com/login/oauth/authorize?' + query)
}
-function actionRevision (req, res, note) {
+function getRevision (req, res, note) {
const actionId = req.params.actionId
if (actionId) {
const time = moment(parseInt(actionId))
diff --git a/lib/web/note/router.js b/lib/web/note/router.js
index 2a6bf2aa..39da4c2c 100644
--- a/lib/web/note/router.js
+++ b/lib/web/note/router.js
@@ -8,15 +8,15 @@ const { markdownParser } = require('../utils')
const router = module.exports = Router()
-const noteActions = require('./actions')
+const noteController = require('./controller')
const slide = require('./slide')
// get new note
-router.get('/new', response.postNote)
+router.get('/new', noteController.createFromPOST)
// post new note with content
-router.post('/new', markdownParser, response.postNote)
+router.post('/new', markdownParser, noteController.createFromPOST)
// post new note with content and alias
-router.post('/new/:noteId', markdownParser, response.postNote)
+router.post('/new/:noteId', markdownParser, noteController.createFromPOST)
// get publish note
router.get('/s/:shortid', response.showPublishNote)
// publish note actions
@@ -28,6 +28,6 @@ router.get('/p/:shortid/:action', slide.publishSlideActions)
// get note by id
router.get('/:noteId', response.showNote)
// note actions
-router.get('/:noteId/:action', noteActions.doAction)
+router.get('/:noteId/:action', noteController.doAction)
// note actions with action id
-router.get('/:noteId/:action/:actionId', noteActions.doAction)
+router.get('/:noteId/:action/:actionId', noteController.doAction)