mirror of https://gitgud.io/fatchan/jschan.git
merge-requests/208/head
parent
8f113d8308
commit
883020cfe9
18 changed files with 258 additions and 10 deletions
@ -0,0 +1,36 @@ |
||||
'use strict'; |
||||
|
||||
const addNews = require(__dirname+'/../../models/forms/addnews.js') |
||||
|
||||
module.exports = async (req, res, next) => { |
||||
|
||||
const errors = []; |
||||
|
||||
if (!req.body.message || req.body.message.length === 0) { |
||||
errors.push('Missing message'); |
||||
} |
||||
if (req.body.message.length > 10000) { |
||||
errors.push('Message must be 10000 characters or less'); |
||||
} |
||||
if (!req.body.title || req.body.title.length === 0) { |
||||
errors.push('Missing title'); |
||||
} |
||||
if (req.body.title.length > 50) { |
||||
errors.push('Title must be 50 characters or less'); |
||||
} |
||||
|
||||
if (errors.length > 0) { |
||||
return res.status(400).render('message', { |
||||
'title': 'Bad request', |
||||
'errors': errors, |
||||
'redirect': '/globalmanage.html' |
||||
}); |
||||
} |
||||
|
||||
try { |
||||
await addNews(req, res, next); |
||||
} catch (err) { |
||||
return next(err); |
||||
} |
||||
|
||||
} |
@ -0,0 +1,27 @@ |
||||
'use strict'; |
||||
|
||||
const deleteNews = require(__dirname+'/../../models/forms/deletenews.js'); |
||||
|
||||
module.exports = async (req, res, next) => { |
||||
|
||||
const errors = []; |
||||
|
||||
if (!req.body.checkednews || req.body.checkednews.length === 0 || req.body.checkednews.length > 10) { |
||||
errors.push('Must select 1-10 newsposts delete'); |
||||
} |
||||
|
||||
if (errors.length > 0) { |
||||
return res.status(400).render('message', { |
||||
'title': 'Bad request', |
||||
'errors': errors, |
||||
'redirect': `/${req.params.board}/manage.html` |
||||
}) |
||||
} |
||||
|
||||
try { |
||||
await deleteNews(req, res, next); |
||||
} catch (err) { |
||||
return next(err); |
||||
} |
||||
|
||||
} |
@ -0,0 +1,31 @@ |
||||
|
||||
'use strict'; |
||||
|
||||
const Mongo = require(__dirname+'/db.js') |
||||
, db = Mongo.client.db('jschan').collection('news'); |
||||
|
||||
module.exports = { |
||||
|
||||
find: () => { |
||||
return db.find({}).sort({ |
||||
'_id': -1 |
||||
}).toArray(); |
||||
}, |
||||
|
||||
insertOne: (news) => { |
||||
return db.insertOne(news); |
||||
}, |
||||
|
||||
deleteMany: (ids) => { |
||||
return db.deleteMany({ |
||||
'_id': { |
||||
'$in': ids |
||||
} |
||||
}) |
||||
}, |
||||
|
||||
deleteAll: () => { |
||||
return db.deleteMany({}); |
||||
}, |
||||
|
||||
} |
@ -0,0 +1,38 @@ |
||||
'use strict'; |
||||
|
||||
const News = require(__dirname+'/../../db/news.js') |
||||
, uploadDirectory = require(__dirname+'/../../helpers/files/uploadDirectory.js') |
||||
, { buildNews } = require(__dirname+'/../../helpers/build.js') |
||||
, linkQuotes = require(__dirname+'/../../helpers/posting/quotes.js') |
||||
, simpleMarkdown = require(__dirname+'/../../helpers/posting/markdown.js') |
||||
, escape = require(__dirname+'/../../helpers/posting/escape.js') |
||||
, sanitizeOptions = require(__dirname+'/../../helpers/posting/sanitizeoptions.js') |
||||
, sanitize = require('sanitize-html'); |
||||
|
||||
module.exports = async (req, res, next) => { |
||||
|
||||
const escaped = escape(req.body.message); |
||||
const styled = simpleMarkdown(escaped); |
||||
const quoted = (await linkQuotes(null, styled, null)).quotedMessage; |
||||
const sanitized = sanitize(quoted, sanitizeOptions.after); |
||||
|
||||
const post = { |
||||
'title': req.body.title, |
||||
'message': { |
||||
'raw': req.body.message, |
||||
'markdown': sanitized |
||||
}, |
||||
'date': new Date(), |
||||
}; |
||||
|
||||
await News.insertOne(post); |
||||
|
||||
await buildNews(); |
||||
|
||||
return res.render('message', { |
||||
'title': 'Success', |
||||
'message': 'Added newspost', |
||||
'redirect': '/globalmanage.html' |
||||
}); |
||||
|
||||
} |
@ -0,0 +1,18 @@ |
||||
'use strict'; |
||||
|
||||
const News = require(__dirname+'/../../db/news.js') |
||||
, { buildNews } = require(__dirname+'/../../helpers/build.js') |
||||
|
||||
module.exports = async (req, res, next) => { |
||||
|
||||
await News.deleteMany(req.body.checkednews); |
||||
|
||||
await buildNews(); |
||||
|
||||
return res.render('message', { |
||||
'title': 'Success', |
||||
'message': 'Deleted news', |
||||
'redirect': '/globalmanage.html' |
||||
}); |
||||
|
||||
} |
@ -0,0 +1,16 @@ |
||||
'use strict'; |
||||
|
||||
const { buildNews } = require(__dirname+'/../../helpers/build.js') |
||||
, uploadDirectory = require(__dirname+'/../../helpers/files/uploadDirectory.js'); |
||||
|
||||
module.exports = async (req, res, next) => { |
||||
|
||||
try { |
||||
await buildNews(); |
||||
} catch (err) { |
||||
return next(err); |
||||
} |
||||
|
||||
return res.sendFile(`${uploadDirectory}html/news.html`); |
||||
|
||||
} |
@ -1,5 +1,6 @@ |
||||
nav.navbar#top |
||||
a.nav-item(href='/') Home |
||||
a.nav-item(href='/news.html') News |
||||
a.nav-item(href=`/${board ? board._id+'/' : 'global'}manage.html`) Manage |
||||
a.nav-item(href='/create.html') Create |
||||
a.nav-item.right(href='/logout') Logout |
||||
|
@ -0,0 +1,16 @@ |
||||
mixin newspost(post, globalmanage=false) |
||||
.table-container.flex-center.mv-5 |
||||
.anchor(id=post._id) |
||||
table.table-body |
||||
tr.table-head |
||||
th |
||||
if globalmanage === true |
||||
input.left.post-check(type='checkbox', name='checkednews[]' value=post._id) |
||||
a.left(href=`#${post._id}`) #{post.title} |
||||
p.right.no-m-p #{post.date.toLocaleString()} |
||||
tr.table-row |
||||
td |
||||
if globalmanage === true |
||||
p.no-m-p #{`${post.message.raw.substring(0,50)}...`} |
||||
else |
||||
pre.post-message.no-m-p !{post.message.markdown} |
@ -0,0 +1,12 @@ |
||||
extends ../layout.pug |
||||
include ../mixins/newspost.pug |
||||
|
||||
block head |
||||
title News |
||||
|
||||
block content |
||||
h1.board-title News |
||||
if news.length === 0 |
||||
p.text-center No news. |
||||
each post in news |
||||
+newspost(post) |
Loading…
Reference in new issue