Use POST requests, fix formatting
This commit is contained in:
parent
0a7f7bf9ce
commit
ce863e8beb
3 changed files with 23 additions and 18 deletions
20
index.js
20
index.js
|
@ -29,12 +29,16 @@ server.use(function replacer(req, res, next) {
|
|||
replace(req, /^\/post\/([0-9]+)_?/g, '/post?id=$1')
|
||||
replace(req, /^\/comment\/([0-9_]+)\/([0-9_]*)(\?(.*))?/g, '/comment?id=$1&comment=$2&$4')
|
||||
next()
|
||||
console.log(JSON.stringify(req.query))
|
||||
console.log(JSON.stringify(req.body))
|
||||
})
|
||||
|
||||
server.use(require('body-parser').urlencoded({extended: false}))
|
||||
|
||||
server.get('/', function get(req, res) {
|
||||
if(req.query.name && req.query.title && req.query.content) {
|
||||
posts.push({timestamp: new Date().getTime(), author: req.query.name, title: req.query.title, content: req.query.content.replaceAll('\r\n', '\n'), comments: []})
|
||||
|
||||
server.all('/', function get(req, res) {
|
||||
if(req.body.name && req.body.title && req.body.content) {
|
||||
posts.push({timestamp: new Date().getTime(), author: req.body.name, title: req.body.title, content: req.body.content.replaceAll('\r\n', '\n'), comments: []})
|
||||
res.redirect('/')
|
||||
return
|
||||
}
|
||||
|
@ -52,7 +56,7 @@ server.get('/post', function get(req, res) {
|
|||
}
|
||||
}
|
||||
})
|
||||
server.get('/comment', function get(req, res) {
|
||||
server.all('/comment', function get(req, res) {
|
||||
if(req.query.id) {
|
||||
let id = req.query.id
|
||||
let comment = req.query.comment
|
||||
|
@ -61,8 +65,8 @@ server.get('/comment', function get(req, res) {
|
|||
function recurse(post) {
|
||||
console.log(String(cid) + ' ' + comment)
|
||||
if(String(cid) === comment) {
|
||||
if(req.query.name && req.query.title && req.query.content) {
|
||||
post.comments.push({timestamp: new Date().getTime(), author: req.query.name, title: req.query.title, content: req.query.content.replaceAll('\r\n', '\n'), comments: []})
|
||||
if(req.body.name && req.body.title && req.body.content) {
|
||||
post.comments.push({timestamp: new Date().getTime(), author: req.body.name, title: req.body.title, content: req.body.content.replaceAll('\r\n', '\n'), comments: []})
|
||||
res.redirect(`/post/${id}`)
|
||||
cid = -1
|
||||
}
|
||||
|
@ -84,8 +88,8 @@ server.get('/comment', function get(req, res) {
|
|||
res.render('post.ejs', {post: posts[id], postid: id, webname: webname, email: email, comment: cid})
|
||||
}
|
||||
else {
|
||||
if(req.query.name && req.query.title && req.query.content) {
|
||||
posts[id].comments.push({timestamp: new Date().getTime(), author: req.query.name, title: req.query.title, content: req.query.content.replaceAll('\r\n', '\n'), comments: []})
|
||||
if(req.body.name && req.body.title && req.body.content) {
|
||||
posts[id].comments.push({timestamp: new Date().getTime(), author: req.body.name, title: req.body.title, content: req.body.content.replaceAll('\r\n', '\n'), comments: []})
|
||||
res.redirect(`/post/${id}`)
|
||||
}
|
||||
else
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"bdb.js": "^0.2.1-a",
|
||||
"body-parser": "^1.19.1",
|
||||
"ejs": "^3.1.6",
|
||||
"express": "^4.17.2"
|
||||
}
|
||||
|
|
|
@ -108,15 +108,15 @@
|
|||
`<post><div class="content">${date ? (`<h6>${date.toUTCString()}</h6>`) : ''}<h3>${post.author.replaceAll('<','<').replaceAll('>','>')}: ${post.title.replaceAll('<','<').replaceAll('>','>')}</h3>` +
|
||||
post.content.replaceAll('<','<').replaceAll('>','>')
|
||||
.replaceAll(/(https?:\/\/[^ \n]+)/g, '<a href="$1" target="_blank">$1</a>')
|
||||
.replaceAll(/\[[*] ([\w\W]*) [*]\]/g, '<i>$1</i>')
|
||||
.replaceAll(/\[[*][*] ([\w\W]*) [*][*]\]/g, '<b>$1</b>')
|
||||
.replaceAll(/\[[*][*][*] ([\w\W]*) [*][*][*]\]/g, '<b><i>$1</i></b>')
|
||||
.replaceAll(/\[[_] ([\w\W]*) [_]\]/g, '<u>$1</u>')
|
||||
.replaceAll(/\[[*][_] ([\w\W]*) [_][*]\]/g, '<i><u>$1</u></i>')
|
||||
.replaceAll(/\[[*][*][_] ([\w\W]*) [_][*][*]\]/g, '<b><u>$1</u></b>')
|
||||
.replaceAll(/\[[*][*][*][_] ([\w\W]*) [_][*][*][*]\]/g, '<b><i><u>$1</u></i></b>')
|
||||
.replaceAll(/\[["] ([\w\W]*) ["]\]/g, '<pre class="inline">$1</pre>')
|
||||
.replaceAll(/\[["]["]* \n([\w\W]*)\n ["]["]*\]/g, '<pre>$1</pre>')
|
||||
.replaceAll(/\[[*] ([\w\W]*?) [*]\]/g, '<i>$1</i>')
|
||||
.replaceAll(/\[[*][*] ([\w\W]*?) [*][*]\]/g, '<b>$1</b>')
|
||||
.replaceAll(/\[[*][*][*] ([\w\W]*?) [*][*][*]\]/g, '<b><i>$1</i></b>')
|
||||
.replaceAll(/\[[_] ([\w\W]*?) [_]\]/g, '<u>$1</u>')
|
||||
.replaceAll(/\[[*][_] ([\w\W]*?) [_][*]\]/g, '<i><u>$1</u></i>')
|
||||
.replaceAll(/\[[*][*][_] ([\w\W]*?) [_][*][*]\]/g, '<b><u>$1</u></b>')
|
||||
.replaceAll(/\[[*][*][*][_] ([\w\W]*?) [_][*][*][*]\]/g, '<b><i><u>$1</u></i></b>')
|
||||
.replaceAll(/\[["] ([\w\W]*?) ["]\]/g, '<pre class="inline">$1</pre>')
|
||||
.replaceAll(/\[["]["]* \n([\w\W]*?)\n ["]["]*\]/g, '<pre>$1</pre>')
|
||||
.replaceAll('\n', '<br/>')
|
||||
ret += '<div class="controls">'
|
||||
if (postid != -1 || id == '') {
|
||||
|
@ -124,7 +124,7 @@
|
|||
if(postid != -1)
|
||||
ret += `<a href="/post/${postid}">[Nevermind]</a>`
|
||||
ret +=
|
||||
`</div></div><post><div class="content"><form><label>` +
|
||||
`</div></div><post><div class="content"><form method="post"><label>` +
|
||||
`<h3><input type="username" name="name" value="Anonymous" required>: <input type="text" name="title" placeholder="Title" required></h3>` +
|
||||
`<textarea name="content" placeholder="So basically, ..." required></textarea><br/><br/><button type="submit">Submit</button>` +
|
||||
`</label></form></div></post><div>`
|
||||
|
|
Loading…
Add table
Reference in a new issue