apply board settings limits in handlers and display on manage page, no form handling to edit them YET

merge-requests/208/head
fatchan 5 years ago
parent dd3812c6e4
commit 281dba8819
  1. 8
      db/posts.js
  2. 15
      models/forms/make-post.js
  3. 8
      views/includes/postform.pug
  4. 1
      views/pages/globalmanage.pug
  5. 29
      views/pages/manage.pug
  6. 8
      wipe.js

@ -260,7 +260,6 @@ module.exports = {
},
insertOne: async (board, data, thread) => {
console.log(thread)
if (data.thread !== null && data.email !== 'sage' && !thread.saged) {
const filter = {
'postId': data.thread,
@ -286,9 +285,6 @@ console.log(thread)
const postId = await Boards.getNextId(board);
data.postId = postId;
await db.insertOne(data);
if (!data.thread) { //if we just added a new thread, prune anyold ones
await module.exports.pruneOldThreads(board);
}
return postId;
},
@ -328,7 +324,7 @@ console.log(thread)
return db.deleteOne(options);
},
pruneOldThreads: async (board) => {
pruneOldThreads: async (board, threadLimit) => {
//get lowest bumped threads
const threads = await db.find({
'thread': null,
@ -336,7 +332,7 @@ console.log(thread)
}).sort({
'sticky': -1,
'bumped': -1
}).skip(100).toArray(); //100 therads in board limit for now
}).skip(threadLimit).toArray(); //100 therads in board limit for now
//if there are any
if (threads.length > 0) {
//get the postIds

@ -59,7 +59,7 @@ module.exports = async (req, res, next, numFiles) => {
'redirect': redirect
});
}
if (thread.replyposts >= 100) { //reply limit
if (thread.replyposts >= res.locals.board.settings.replyLimit) { //reply limit
return res.status(400).render('message', {
'title': 'Bad request',
'message': 'Thread reached reply limit',
@ -71,7 +71,7 @@ module.exports = async (req, res, next, numFiles) => {
// if we got a file
if (numFiles > 0) {
// check all mime types befoer we try saving anything
for (let i = 0; i < numFiles; i++) {
for (let i = 0; i < res.locals.board.settings.maxImages; i++) {
if (!fileCheckMimeType(req.files.file[i].mimetype, {image: true, video: true})) {
return res.status(400).render('message', {
'title': 'Bad request',
@ -161,12 +161,12 @@ module.exports = async (req, res, next, numFiles) => {
userId = fullUserIdHash.substring(fullUserIdHash.length-6);
}
//forceanon hide reply subjects so cant be used as name
let subject = hasPerms || !forceAnon ? req.body.subject : null;
//forceanon hide reply subjects so cant be used as name for replies
let subject = hasPerms || !forceAnon || !req.body.thread ? req.body.subject : null;
//forceanon only allow sage email
let email = hasPerms || !forceAnon || req.body.email === 'sage' ? req.body.email : null;
let name = 'Anonymous';
let name = res.locals.board.settins.defaultName;
let tripcode = null;
let capcode = null;
if ((hasPerms || !forceAnon) && req.body.name && req.body.name.length > 0) {
@ -233,7 +233,10 @@ module.exports = async (req, res, next, numFiles) => {
let postId;
try {
postId = await Posts.insertOne(req.params.board, data, thread);
postId = await Posts.insertOne(res.locals.board, data, thread);
if (!data.thread) { //if we just added a new thread, prune anyold ones
await module.exports.pruneOldThreads(req.params.board, res.locals.board.settings.threadLimit);
}
} catch (err) {
return next(err);
}

@ -2,7 +2,7 @@ section.form-wrapper
form.form-post(action=`/forms/board/${board._id}/post`, enctype='multipart/form-data', method='POST')
input(type='hidden' name='_csrf' value=csrf)
input(type='hidden' name='thread' value=thread != null ? thread.postId : null)
if !board.settings.forceAnon
unless board.settings.forceAnon
section.postform-row
.postform-label Name
input#name(type='text', name='name', placeholder='Anonymous' autocomplete='off' maxlength='50')
@ -12,12 +12,16 @@ section.form-wrapper
section.postform-row
.postform-label Email
input#name(type='text', name='email', autocomplete='off' maxlength='50')
else
else
section.postform-row
.postform-label Sage
label.postform-style.ph-5
input#spoiler(type='checkbox', name='email', value='sage')
| Sage
if thread
section.postform-row
.postform-label Subject
input#title(type='text', name='subject', autocomplete='off' maxlength='50')
section.postform-row
.postform-label Message
textarea#message(name='message', rows='5', autocomplete='off' maxlength='2000')

@ -7,7 +7,6 @@ block head
block content
h1.board-title Global Management
p: a(href='/changepassword') Change password
h4 All Reports:
form(action=`/forms/global/actions` method='POST' enctype='application/x-www-form-urlencoded')
input(type='hidden' name='_csrf' value=csrf)

@ -7,8 +7,35 @@ block head
block content
include ../includes/boardheader.pug
h4 Settings:
section.form-wrapper
form.form-post(action=`/forms/board/${board._id}/settings` method='POST' enctype='application/x-www-form-urlencoded')
input(type='hidden' name='_csrf' value=csrf)
section.postform-row
.postform-label IDs
label.postform-style.ph-5
input(type='checkbox', name='ids', value='true' checked=board.settings.ids)
| Show per-thread IDs
section.postform-row
.postform-label Force Anon
label.postform-style.ph-5
input(type='checkbox', name='force_anon', value='true' checked=board.settings.forceAnon)
| Disable names and only allow sage email
section.postform-row
.postform-label Anon Name
input(type='text' name='default_name' placeholder=board.settings.defaultName)
section.postform-row
.postform-label Thread Limit
input(type='text' name='thread_limit' placeholder=board.settings.threadLimit)
section.postform-row
.postform-label Reply Limit
input(type='text' name='reply_limit' placeholder=board.settings.replyLimit)
section.postform-row
.postform-label Max Images
input(type='text' name='max_images' placeholder=board.settings.maxImages)
input(type='submit', value='save settings')
h4 Banners:
include ../includes/bannerform.pug
p: a(href='/changepassword') Change password
h4 Reports:
form(action=`/forms/board/${board._id}/modactions` method='POST' enctype='application/x-www-form-urlencoded')
input(type='hidden' name='_csrf' value=csrf)

@ -42,6 +42,10 @@ const Mongo = require(__dirname+'/db/db.js')
settings: {
forceAnon: true,
ids: true,
threadLimit: 100,
replyLimit: 300,
maxImages: 3,
defaultName: 'Anonymous',
}
})
await Boards.insertOne({
@ -54,6 +58,10 @@ const Mongo = require(__dirname+'/db/db.js')
settings: {
forceAnon: false,
ids: false,
threadLimit: 100,
replyLimit: 300,
maxImages: 3,
defaultNAme: 'Anonymous',
}
})
console.log('creating indexes')

Loading…
Cancel
Save