mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-05-12 22:26:08 -04:00
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>
This commit is contained in:
parent
afb317b551
commit
30487f7c01
3 changed files with 33 additions and 34 deletions
|
@ -9,7 +9,7 @@ var config = require('./config')
|
||||||
var logger = require('./logger')
|
var logger = require('./logger')
|
||||||
var models = require('./models')
|
var models = require('./models')
|
||||||
const noteUtil = require('./web/note/util')
|
const noteUtil = require('./web/note/util')
|
||||||
const noteActions = require('./web/note/actions')
|
const noteController = require('./web/note/controller')
|
||||||
const errors = require('./errors')
|
const errors = require('./errors')
|
||||||
|
|
||||||
// public
|
// public
|
||||||
|
@ -17,7 +17,6 @@ var response = {
|
||||||
showNote: showNote,
|
showNote: showNote,
|
||||||
showPublishNote: showPublishNote,
|
showPublishNote: showPublishNote,
|
||||||
showIndex: showIndex,
|
showIndex: showIndex,
|
||||||
postNote: postNote,
|
|
||||||
publishNoteActions: publishNoteActions,
|
publishNoteActions: publishNoteActions,
|
||||||
githubActions: githubActions,
|
githubActions: githubActions,
|
||||||
gitlabActions: gitlabActions
|
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) {
|
function showNote (req, res, next) {
|
||||||
noteUtil.findNote(req, res, function (note) {
|
noteUtil.findNote(req, res, function (note) {
|
||||||
// force to use note id
|
// force to use note id
|
||||||
|
@ -156,7 +144,7 @@ function publishNoteActions (req, res, next) {
|
||||||
var action = req.params.action
|
var action = req.params.action
|
||||||
switch (action) {
|
switch (action) {
|
||||||
case 'download':
|
case 'download':
|
||||||
noteActions.actionDownload(req, res, note)
|
noteController.downloadMarkdown(req, res, note)
|
||||||
break
|
break
|
||||||
case 'edit':
|
case 'edit':
|
||||||
res.redirect(config.serverURL + '/' + (note.alias ? note.alias : models.Note.encodeNoteId(note.id)) + '?both')
|
res.redirect(config.serverURL + '/' + (note.alias ? note.alias : models.Note.encodeNoteId(note.id)) + '?both')
|
||||||
|
|
|
@ -11,6 +11,17 @@ const moment = require('moment')
|
||||||
const querystring = require('querystring')
|
const querystring = require('querystring')
|
||||||
const noteUtil = require('./util')
|
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) {
|
exports.doAction = function (req, res, next) {
|
||||||
const noteId = req.params.noteId
|
const noteId = req.params.noteId
|
||||||
noteUtil.findNote(req, res, function (note) {
|
noteUtil.findNote(req, res, function (note) {
|
||||||
|
@ -18,30 +29,30 @@ exports.doAction = function (req, res, next) {
|
||||||
switch (action) {
|
switch (action) {
|
||||||
case 'publish':
|
case 'publish':
|
||||||
case 'pretty': // pretty deprecated
|
case 'pretty': // pretty deprecated
|
||||||
actionPublish(req, res, note)
|
publish(req, res, note)
|
||||||
break
|
break
|
||||||
case 'slide':
|
case 'slide':
|
||||||
actionSlide(req, res, note)
|
slide(req, res, note)
|
||||||
break
|
break
|
||||||
case 'download':
|
case 'download':
|
||||||
exports.actionDownload(req, res, note)
|
exports.downloadMarkdown(req, res, note)
|
||||||
break
|
break
|
||||||
case 'info':
|
case 'info':
|
||||||
actionInfo(req, res, note)
|
getInfo(req, res, note)
|
||||||
break
|
break
|
||||||
case 'pdf':
|
case 'pdf':
|
||||||
if (config.allowPDFExport) {
|
if (config.allowPDFExport) {
|
||||||
actionPDF(req, res, note)
|
createPDF(req, res, note)
|
||||||
} else {
|
} else {
|
||||||
logger.error('PDF export failed: Disabled by config. Set "allowPDFExport: true" to enable. Check the documentation for details')
|
logger.error('PDF export failed: Disabled by config. Set "allowPDFExport: true" to enable. Check the documentation for details')
|
||||||
errors.errorForbidden(res)
|
errors.errorForbidden(res)
|
||||||
}
|
}
|
||||||
break
|
break
|
||||||
case 'gist':
|
case 'gist':
|
||||||
actionGist(req, res, note)
|
createGist(req, res, note)
|
||||||
break
|
break
|
||||||
case 'revision':
|
case 'revision':
|
||||||
actionRevision(req, res, note)
|
getRevision(req, res, note)
|
||||||
break
|
break
|
||||||
default:
|
default:
|
||||||
return res.redirect(config.serverURL + '/' + noteId)
|
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))
|
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))
|
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
|
const body = note.content
|
||||||
let filename = models.Note.decodeTitle(note.title)
|
let filename = models.Note.decodeTitle(note.title)
|
||||||
filename = encodeURIComponent(filename)
|
filename = encodeURIComponent(filename)
|
||||||
|
@ -73,7 +84,7 @@ exports.actionDownload = function (req, res, note) {
|
||||||
res.send(body)
|
res.send(body)
|
||||||
}
|
}
|
||||||
|
|
||||||
function actionInfo (req, res, note) {
|
function getInfo (req, res, note) {
|
||||||
const body = note.content
|
const body = note.content
|
||||||
const extracted = models.Note.extractMeta(body)
|
const extracted = models.Note.extractMeta(body)
|
||||||
const markdown = extracted.markdown
|
const markdown = extracted.markdown
|
||||||
|
@ -98,7 +109,7 @@ function actionInfo (req, res, note) {
|
||||||
res.send(data)
|
res.send(data)
|
||||||
}
|
}
|
||||||
|
|
||||||
function actionPDF (req, res, note) {
|
function createPDF (req, res, note) {
|
||||||
const url = config.serverURL || 'http://' + req.get('host')
|
const url = config.serverURL || 'http://' + req.get('host')
|
||||||
const body = note.content
|
const body = note.content
|
||||||
const extracted = models.Note.extractMeta(body)
|
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 = {
|
const data = {
|
||||||
client_id: config.github.clientID,
|
client_id: config.github.clientID,
|
||||||
redirect_uri: config.serverURL + '/auth/github/callback/' + models.Note.encodeNoteId(note.id) + '/gist',
|
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)
|
res.redirect('https://github.com/login/oauth/authorize?' + query)
|
||||||
}
|
}
|
||||||
|
|
||||||
function actionRevision (req, res, note) {
|
function getRevision (req, res, note) {
|
||||||
const actionId = req.params.actionId
|
const actionId = req.params.actionId
|
||||||
if (actionId) {
|
if (actionId) {
|
||||||
const time = moment(parseInt(actionId))
|
const time = moment(parseInt(actionId))
|
|
@ -8,15 +8,15 @@ const { markdownParser } = require('../utils')
|
||||||
|
|
||||||
const router = module.exports = Router()
|
const router = module.exports = Router()
|
||||||
|
|
||||||
const noteActions = require('./actions')
|
const noteController = require('./controller')
|
||||||
const slide = require('./slide')
|
const slide = require('./slide')
|
||||||
|
|
||||||
// get new note
|
// get new note
|
||||||
router.get('/new', response.postNote)
|
router.get('/new', noteController.createFromPOST)
|
||||||
// post new note with content
|
// post new note with content
|
||||||
router.post('/new', markdownParser, response.postNote)
|
router.post('/new', markdownParser, noteController.createFromPOST)
|
||||||
// post new note with content and alias
|
// post new note with content and alias
|
||||||
router.post('/new/:noteId', markdownParser, response.postNote)
|
router.post('/new/:noteId', markdownParser, noteController.createFromPOST)
|
||||||
// get publish note
|
// get publish note
|
||||||
router.get('/s/:shortid', response.showPublishNote)
|
router.get('/s/:shortid', response.showPublishNote)
|
||||||
// publish note actions
|
// publish note actions
|
||||||
|
@ -28,6 +28,6 @@ router.get('/p/:shortid/:action', slide.publishSlideActions)
|
||||||
// get note by id
|
// get note by id
|
||||||
router.get('/:noteId', response.showNote)
|
router.get('/:noteId', response.showNote)
|
||||||
// note actions
|
// note actions
|
||||||
router.get('/:noteId/:action', noteActions.doAction)
|
router.get('/:noteId/:action', noteController.doAction)
|
||||||
// note actions with action id
|
// note actions with action id
|
||||||
router.get('/:noteId/:action/:actionId', noteActions.doAction)
|
router.get('/:noteId/:action/:actionId', noteController.doAction)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue