From 4bf56fdc3bdd080a5a4a8548713fab67bbb77df2 Mon Sep 17 00:00:00 2001 From: fatchan Date: Tue, 2 Jul 2019 01:10:42 +0000 Subject: [PATCH] cyclical threads, fix trying empty bulkwrite in deleteposts, fix missing thumbs in catalog tiles --- db/posts.js | 4 ++-- gulp/res/img/cyclic.svg | 4 ++++ helpers/checks/actionchecker.js | 1 + helpers/posting/quotes.js | 1 + models/forms/deletepost.js | 4 +++- models/forms/makepost.js | 18 ++++++++++++++++-- views/includes/actionfooter.pug | 3 +++ views/mixins/catalogtile.pug | 17 ++++++++++++----- views/mixins/post.pug | 7 +++++-- 9 files changed, 47 insertions(+), 12 deletions(-) create mode 100644 gulp/res/img/cyclic.svg diff --git a/db/posts.js b/db/posts.js index 4a5fd8c6..87c59db4 100644 --- a/db/posts.js +++ b/db/posts.js @@ -274,7 +274,7 @@ module.exports = { if (data.thread !== null) { const filter = { 'postId': data.thread, - 'board': board + 'board': board._id } //update thread reply and reply file count const query = { @@ -297,7 +297,7 @@ module.exports = { } //get the postId and add it to the post - const postId = await Boards.getNextId(board); + const postId = await Boards.getNextId(board._id); data.postId = postId; //insert the post itself diff --git a/gulp/res/img/cyclic.svg b/gulp/res/img/cyclic.svg new file mode 100644 index 00000000..f93708fb --- /dev/null +++ b/gulp/res/img/cyclic.svg @@ -0,0 +1,4 @@ + diff --git a/helpers/checks/actionchecker.js b/helpers/checks/actionchecker.js index 020229c2..9358e9e6 100644 --- a/helpers/checks/actionchecker.js +++ b/helpers/checks/actionchecker.js @@ -7,6 +7,7 @@ const actions = [ {name:'delete', global:true, auth:false, passwords:true, build:true}, {name:'lock', global:false, auth:true, passwords:false, build:true}, {name:'sticky', global:false, auth:true, passwords:false, build:true}, + {name:'cyclic', global:false, auth:true, passwords:false, build:true}, {name:'sage', global:false, auth:true, passwords:false, build:true}, {name:'report', global:false, auth:false, passwords:false, build:false}, {name:'global_report', global:false, auth:false, passwords:false, build:false}, diff --git a/helpers/posting/quotes.js b/helpers/posting/quotes.js index 89348348..3961313e 100644 --- a/helpers/posting/quotes.js +++ b/helpers/posting/quotes.js @@ -26,6 +26,7 @@ module.exports = async (board, text, thread) => { } }); } + if (crossQuotes) { for (let i = 0; i < crossQuotes.length; i++) { const crossQuote = crossQuotes[i].split('/'); diff --git a/models/forms/deletepost.js b/models/forms/deletepost.js index 5274e522..ca2cb3d9 100644 --- a/models/forms/deletepost.js +++ b/models/forms/deletepost.js @@ -73,7 +73,9 @@ module.exports = async (posts, board) => { }); } } - await Posts.db.bulkWrite(bulkWrites); + if (bulkWrites.length > 0) { + await Posts.db.bulkWrite(bulkWrites); + } //TODO: remarkup to unlink quotes in posts that quote deleted posts //TODO: file ref counting decrement, oncei implement counting in make post diff --git a/models/forms/makepost.js b/models/forms/makepost.js index 36745a3d..4fd230ea 100644 --- a/models/forms/makepost.js +++ b/models/forms/makepost.js @@ -58,7 +58,7 @@ module.exports = async (req, res, next) => { 'redirect': redirect }); } - if (thread.replyposts >= res.locals.board.settings.replyLimit) { //reply limit + if (thread.replyposts >= res.locals.board.settings.replyLimit && !thread.cyclic) { //reply limit await deleteTempFiles(req).catch(e => console.error); return res.status(400).render('message', { 'title': 'Bad request', @@ -263,11 +263,25 @@ module.exports = async (req, res, next) => { 'sticky': false, 'locked': false, 'saged': false, + 'cyclic': false, 'salt': salt }); } - const postId = await Posts.insertOne(req.params.board, data, thread); + const postId = await Posts.insertOne(res.locals.board, data, thread); + + //for cyclic threads, delete posts beyond bump limit + if (thread && thread.cyclic && thread.replyposts > res.locals.board.settings.replyLimit) { + //is there a way to NOT have to fetch before deleting for this? + const cyclicOverflowPosts = await Posts.db.find({ + 'thread': data.thread, + 'board': req.params.board + }).sort({ + 'postId': -1, + }).skip(res.locals.board.settings.replyLimit).toArray(); + await deletePosts(cyclicOverflowPosts, req.params.board); + } + const successRedirect = `/${req.params.board}/thread/${req.body.thread || postId}.html#${postId}`; console.log('--------------------------------'); console.log(`NEW POST -> ${successRedirect}`); diff --git a/views/includes/actionfooter.pug b/views/includes/actionfooter.pug index 27920fa6..908ecd3f 100644 --- a/views/includes/actionfooter.pug +++ b/views/includes/actionfooter.pug @@ -41,6 +41,9 @@ details.toggle-label label input.post-check(type='checkbox', name='sage' value=1) | Sage + label + input.post-check(type='checkbox', name='cyclic' value=1) + | Cycle label input.post-check(type='checkbox', name='ban' value=1) | Ban Poster diff --git a/views/mixins/catalogtile.pug b/views/mixins/catalogtile.pug index e054bfd4..31668b81 100644 --- a/views/mixins/catalogtile.pug +++ b/views/mixins/catalogtile.pug @@ -3,13 +3,16 @@ mixin catalogtile(board, post, index) - const postURL = `/${board._id}/thread/${post.postId}.html#${post.postId}` header.post-info if post.sticky - img(src='/img/sticky.svg' height='12') + img(src='/img/sticky.svg' height='12' title='Sticky') | if post.saged - img(src='/img/saged.svg' height='12') + img(src='/img/saged.svg' height='12' title='Bumplocked') | if post.locked - img(src='/img/locked.svg' height='12') + img(src='/img/locked.svg' height='12' title='Locked') + | + if post.cyclic + img(src='/img/cyclic.svg' height='13' title='Cyclic') | a.no-decoration.post-subject(href=postURL) #{post.subject || '#'+post.postId} | - @@ -24,7 +27,11 @@ mixin catalogtile(board, post, index) if post.spoiler img.catalog-thumb(src='/img/spoiler.png' width='64' height='64') else - object.catalog-thumb(data=`/img/thumb-${post.files[0].filename.split('.')[0]}.jpg` width='64' height='64') - img(src='/img/deleted.png' width='64' height='64') + if post.files[0].hasThumb + object.catalog-thumb(data=`/img/thumb-${post.files[0].filename.split('.')[0]}.jpg` width='64' height='64') + img(src='/img/deleted.png' width='64' height='64') + else + object.catalog-thumb(data=`/img/${post.files[0].filename}` width='64' height='64') + img(src='/img/deleted.png' width='64' height='64') if post.message pre.no-m-p.post-message !{post.message} diff --git a/views/mixins/post.pug b/views/mixins/post.pug index 223db161..565a5849 100644 --- a/views/mixins/post.pug +++ b/views/mixins/post.pug @@ -10,14 +10,17 @@ mixin post(post, truncate, manage=false, globalmanage=false) | if !post.thread if post.sticky - img(src='/img/sticky.svg' height='12' title='Stickied') + img(src='/img/sticky.svg' height='12' title='Sticky') | if post.saged - img(src='/img/saged.svg' height='12' title='Permasaged') + img(src='/img/saged.svg' height='12' title='Bumplocked') | if post.locked img(src='/img/locked.svg' height='12' title='Locked') | + if post.cyclic + img(src='/img/cyclic.svg' height='13' title='Cyclic') + | if post.subject span.post-subject #{post.subject} |