Skip to content

Commit f476018

Browse files
committed
Allow posting new note with content
Signed-off-by: Dustin Frisch <fooker@lab.sh>
1 parent a8fa888 commit f476018

3 files changed

Lines changed: 13 additions & 1 deletion

File tree

lib/response.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,8 @@ function newNote (req, res, next) {
117117
}
118118
models.Note.create({
119119
ownerId: owner,
120-
alias: req.alias ? req.alias : null
120+
alias: req.alias ? req.alias : null,
121+
content: req.body ? req.body : ''
121122
}).then(function (note) {
122123
return res.redirect(config.serverurl + '/' + LZString.compressToBase64(note.id))
123124
}).catch(function (err) {

lib/web/noteRouter.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,14 @@ const Router = require('express').Router
44

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

7+
const {markdownParser} = require('./utils')
8+
79
const noteRouter = module.exports = Router()
810

911
// get new note
1012
noteRouter.get('/new', response.newNote)
13+
// post new note with content
14+
noteRouter.post('/new', markdownParser, response.newNote)
1115
// get publish note
1216
noteRouter.get('/s/:shortid', response.showPublishNote)
1317
// publish note actions

lib/web/utils.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,10 @@ exports.urlencodedParser = bodyParser.urlencoded({
77
extended: false,
88
limit: 1024 * 1024 * 10 // 10 mb
99
})
10+
11+
// create text/markdown parser
12+
exports.markdownParser = bodyParser.text({
13+
inflate: true,
14+
type: ['text/plain', 'text/markdown'],
15+
limit: 1024 * 1024 * 10 // 10 mb
16+
})

0 commit comments

Comments
 (0)