Skip to content

Commit

Permalink
Allow posting new note with content
Browse files Browse the repository at this point in the history
  • Loading branch information
fooker committed Jan 10, 2018
1 parent a8fa888 commit 4e22c98
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/response.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,8 @@ function newNote (req, res, next) {
}
models.Note.create({
ownerId: owner,
alias: req.alias ? req.alias : null
alias: req.alias ? req.alias : null,
content: req.body ? req.body : ''
}).then(function (note) {
return res.redirect(config.serverurl + '/' + LZString.compressToBase64(note.id))
}).catch(function (err) {
Expand Down
4 changes: 4 additions & 0 deletions lib/web/noteRouter.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,14 @@ const Router = require('express').Router

const response = require('../response')

const {markdownParser} = require('./utils')

const noteRouter = module.exports = Router()

// get new note
noteRouter.get('/new', response.newNote)
// post new note with content
noteRouter.post('/new', markdownParser, response.newNote)
// get publish note
noteRouter.get('/s/:shortid', response.showPublishNote)
// publish note actions
Expand Down
7 changes: 7 additions & 0 deletions lib/web/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,10 @@ exports.urlencodedParser = bodyParser.urlencoded({
extended: false,
limit: 1024 * 1024 * 10 // 10 mb
})

// create text/markdown parser
exports.markdownParser = bodyParser.text({
inflate: true,
type: ['text/plain', 'text/markdown'],
limit: 1024 * 1024 * 10 // 10 mb
})

0 comments on commit 4e22c98

Please sign in to comment.