dont delete files since we hash them. keep for later

merge-requests/208/head
fatchan 5 years ago
parent 8b327111e1
commit 1a186b865c
  1. 11
      db/posts.js
  2. 76
      models/forms/actionhandler.js
  3. 8
      models/forms/delete-post.js
  4. 2
      models/forms/deletebanners.js
  5. 40
      models/forms/deletepostsfiles.js
  6. 9
      views/includes/actionfooter.pug
  7. 4
      views/includes/actionfooter_globalmanage.pug
  8. 4
      views/includes/actionfooter_manage.pug

@ -2,7 +2,6 @@
const Mongo = require(__dirname+'/db.js') const Mongo = require(__dirname+'/db.js')
, Boards = require(__dirname+'/boards.js') , Boards = require(__dirname+'/boards.js')
, deletePostFiles = require(__dirname+'/../helpers/files/deletepostfiles.js')
, db = Mongo.client.db('jschan').collection('posts'); , db = Mongo.client.db('jschan').collection('posts');
module.exports = { module.exports = {
@ -272,7 +271,7 @@ module.exports = {
}, },
insertOne: async (board, data, thread) => { insertOne: async (board, data, thread) => {
if (data.thread !== null && data.email !== 'sage' && !thread.saged) { if (data.thread !== null) {
const filter = { const filter = {
'postId': data.thread, 'postId': data.thread,
'board': board 'board': board
@ -355,14 +354,6 @@ module.exports = {
const threadPosts = await module.exports.getMultipleThreadPosts(board, threadIds); const threadPosts = await module.exports.getMultipleThreadPosts(board, threadIds);
//combine them //combine them
const postsAndThreads = threads.concat(threadPosts); const postsAndThreads = threads.concat(threadPosts);
//get the filenames and delete all the files
let fileNames = [];
postsAndThreads.forEach(post => {
fileNames = fileNames.concat(post.files.map(x => x.filename))
});
if (fileNames.length > 0) {
await deletePostFiles(fileNames);
}
//get the mongoIds and delete them all //get the mongoIds and delete them all
const postMongoIds = postsAndThreads.map(post => Mongo.ObjectId(post._id)); const postMongoIds = postsAndThreads.map(post => Mongo.ObjectId(post._id));
await module.exports.deleteMany(postMongoIds); await module.exports.deleteMany(postMongoIds);

@ -49,23 +49,21 @@ module.exports = async (req, res, next) => {
const passwordCombinedQuery = {}; const passwordCombinedQuery = {};
let aggregateNeeded = false; let aggregateNeeded = false;
try { try {
if (res.locals.hasPerms) { // if getting global banned, board ban doesnt matter
// if getting global banned, board ban doesnt matter if (req.body.global_ban) {
if (req.body.global_ban) { const { message, action, query } = await banPoster(req, res, next, null, res.locals.posts);
const { message, action, query } = await banPoster(req, res, next, null, res.locals.posts); if (action) {
if (action) { combinedQuery[action] = { ...combinedQuery[action], ...query}
combinedQuery[action] = { ...combinedQuery[action], ...query}
}
messages.push(message);
} else if (req.body.ban) {
const { message, action, query } = await banPoster(req, res, next, req.params.board, res.locals.posts);
if (action) {
combinedQuery[action] = { ...combinedQuery[action], ...query}
}
messages.push(message);
} }
messages.push(message);
} else if (req.body.ban) {
const { message, action, query } = await banPoster(req, res, next, req.params.board, res.locals.posts);
if (action) {
combinedQuery[action] = { ...combinedQuery[action], ...query}
}
messages.push(message);
} }
if (res.locals.hasPerms && (req.body.delete_ip_board || req.body.delete_ip_global)) { if (req.body.delete_ip_board || req.body.delete_ip_global) {
const deletePostIps = res.locals.posts.map(x => x.ip); const deletePostIps = res.locals.posts.map(x => x.ip);
let query = { let query = {
'ip': { 'ip': {
@ -88,8 +86,8 @@ module.exports = async (req, res, next) => {
aggregateNeeded = true; aggregateNeeded = true;
} else { } else {
// if it was getting deleted, we cant do any of these // if it was getting deleted, we cant do any of these
if (req.body.delete_file) { if (req.body.delete_file || req.body.unlink_file) {
const { message, action, query } = await deletePostsFiles(passwordPosts); const { message, action, query } = await deletePostsFiles(passwordPosts, req.body.unlink_file);
if (action) { if (action) {
aggregateNeeded = true; aggregateNeeded = true;
passwordCombinedQuery[action] = { ...passwordCombinedQuery[action], ...query} passwordCombinedQuery[action] = { ...passwordCombinedQuery[action], ...query}
@ -102,29 +100,27 @@ module.exports = async (req, res, next) => {
} }
messages.push(message); messages.push(message);
} }
if (res.locals.hasPerms) { //lock, sticky, sage
//lock, sticky, sage if (req.body.sage) {
if (req.body.sage) { const { message, action, query } = sagePosts(res.locals.posts);
const { message, action, query } = sagePosts(res.locals.posts); if (action) {
if (action) { combinedQuery[action] = { ...combinedQuery[action], ...query}
combinedQuery[action] = { ...combinedQuery[action], ...query}
}
messages.push(message);
} }
if (req.body.lock) { messages.push(message);
const { message, action, query } = lockPosts(res.locals.posts); }
if (action) { if (req.body.lock) {
combinedQuery[action] = { ...combinedQuery[action], ...query} const { message, action, query } = lockPosts(res.locals.posts);
} if (action) {
messages.push(message); combinedQuery[action] = { ...combinedQuery[action], ...query}
} }
if (req.body.sticky) { messages.push(message);
const { message, action, query } = stickyPosts(res.locals.posts); }
if (action) { if (req.body.sticky) {
combinedQuery[action] = { ...combinedQuery[action], ...query} const { message, action, query } = stickyPosts(res.locals.posts);
} if (action) {
messages.push(message); combinedQuery[action] = { ...combinedQuery[action], ...query}
} }
messages.push(message);
} }
// cannot report and dismiss at same time // cannot report and dismiss at same time
if (req.body.report) { if (req.body.report) {
@ -133,7 +129,7 @@ module.exports = async (req, res, next) => {
combinedQuery[action] = { ...combinedQuery[action], ...query} combinedQuery[action] = { ...combinedQuery[action], ...query}
} }
messages.push(message); messages.push(message);
} else if (res.locals.hasPerms && req.body.dismiss) { } else if (req.body.dismiss) {
const { message, action, query } = dismissReports(res.locals.posts); const { message, action, query } = dismissReports(res.locals.posts);
if (action) { if (action) {
combinedQuery[action] = { ...combinedQuery[action], ...query} combinedQuery[action] = { ...combinedQuery[action], ...query}
@ -147,7 +143,7 @@ module.exports = async (req, res, next) => {
combinedQuery[action] = { ...combinedQuery[action], ...query} combinedQuery[action] = { ...combinedQuery[action], ...query}
} }
messages.push(message); messages.push(message);
} else if (res.locals.hasPerms && req.body.global_dismiss) { } else if (req.body.global_dismiss) {
const { message, action, query } = dismissGlobalReports(res.locals.posts); const { message, action, query } = dismissGlobalReports(res.locals.posts);
if (action) { if (action) {
combinedQuery[action] = { ...combinedQuery[action], ...query} combinedQuery[action] = { ...combinedQuery[action], ...query}
@ -293,7 +289,7 @@ module.exports = async (req, res, next) => {
} else if (req.body.sticky) { //else if -- if deleting, other actions are not executed/irrelevant } else if (req.body.sticky) { //else if -- if deleting, other actions are not executed/irrelevant
//rebuild current and newer pages //rebuild current and newer pages
parallelPromises.push(buildBoardMultiple(buildBoards[boardName], 1, threadPageOldest)); parallelPromises.push(buildBoardMultiple(buildBoards[boardName], 1, threadPageOldest));
} else if (req.body.lock || req.body.sage || req.body.spoiler || req.body.ban || req.body.global_ban) { } else if (req.body.lock || req.body.sage || req.body.spoiler || req.body.ban || req.body.global_ban || req.body.unlink_file) {
//rebuild inbewteen pages for things that dont cause page/thread movement //rebuild inbewteen pages for things that dont cause page/thread movement
//should rebuild only affected pages, but finding the page of all affected //should rebuild only affected pages, but finding the page of all affected
//threads could end up being slower/more resource intensive. this is simpler. //threads could end up being slower/more resource intensive. this is simpler.

@ -1,7 +1,6 @@
'use strict'; 'use strict';
const uploadDirectory = require(__dirname+'/../../helpers/uploadDirectory.js') const uploadDirectory = require(__dirname+'/../../helpers/uploadDirectory.js')
, deletePostFiles = require(__dirname+'/../../helpers/files/deletepostfiles.js')
, remove = require('fs-extra').remove , remove = require('fs-extra').remove
, Mongo = require(__dirname+'/../../db/db.js') , Mongo = require(__dirname+'/../../db/db.js')
, Posts = require(__dirname+'/../../db/posts.js'); , Posts = require(__dirname+'/../../db/posts.js');
@ -39,7 +38,7 @@ module.exports = async (req, res, next, posts, board) => {
//combine them all into one array, there may be duplicates but it shouldnt matter //combine them all into one array, there may be duplicates but it shouldnt matter
const allPosts = posts.concat(threadPosts) const allPosts = posts.concat(threadPosts)
//delete posts from DB //get all mongoids and delete posts from
const postMongoIds = allPosts.map(post => Mongo.ObjectId(post._id)) const postMongoIds = allPosts.map(post => Mongo.ObjectId(post._id))
const deletedPosts = await Posts.deleteMany(postMongoIds).then(result => result.deletedCount); const deletedPosts = await Posts.deleteMany(postMongoIds).then(result => result.deletedCount);
@ -49,11 +48,6 @@ module.exports = async (req, res, next, posts, board) => {
fileNames = fileNames.concat(post.files.map(x => x.filename)) fileNames = fileNames.concat(post.files.map(x => x.filename))
}) })
//delete post files
if (fileNames.length > 0) {
await deletePostFiles(fileNames);
}
//hooray! //hooray!
return { message:`Deleted ${threads.length} threads and ${deletedPosts-threads.length} posts` }; return { message:`Deleted ${threads.length} threads and ${deletedPosts-threads.length} posts` };

@ -12,8 +12,6 @@ module.exports = async (req, res, next) => {
remove(`${uploadDirectory}banner/${filename}`); remove(`${uploadDirectory}banner/${filename}`);
})); }));
// i dont think there is a way to get the number of array items removed with $pullAll
// so i cant return how many banners were deleted
await Boards.removeBanners(req.params.board, req.body.checkedbanners); await Boards.removeBanners(req.params.board, req.body.checkedbanners);
return res.render('message', { return res.render('message', {

@ -3,7 +3,7 @@
const remove = require('fs-extra').remove const remove = require('fs-extra').remove
, uploadDirectory = require(__dirname+'/../../helpers/uploadDirectory.js') , uploadDirectory = require(__dirname+'/../../helpers/uploadDirectory.js')
module.exports = async (posts) => { module.exports = async (posts, unlinkOnly) => {
//get filenames from all the posts //get filenames from all the posts
let fileNames = []; let fileNames = [];
@ -13,25 +13,31 @@ module.exports = async (posts) => {
if (fileNames.length === 0) { if (fileNames.length === 0) {
return { return {
message: 'No files to delete' message: 'No files found'
} }
} }
//delete all the files using the filenames if (unlinkOnly) {
await Promise.all(fileNames.map(async filename => { return {
//dont question it. message:`Unlinked ${fileNames.length} file(s) across ${posts.length} post(s)`,
return Promise.all([ action:'$set',
remove(`${uploadDirectory}img/${filename}`), query: {
remove(`${uploadDirectory}img/thumb-${filename.split('.')[0]}.png`) 'files': []
]) }
})); };
} else {
//delete all the files using the filenames
await Promise.all(fileNames.map(async filename => {
//dont question it.
return Promise.all([
remove(`${uploadDirectory}img/${filename}`),
remove(`${uploadDirectory}img/thumb-${filename.split('.')[0]}.jpg`)
])
}));
return {
message:`Deleted ${fileNames.length} file(s) from server`,
};
}
return {
message:`Deleted ${fileNames.length} file(s) across ${posts.length} post(s)`,
action:'$set',
query: {
'files': []
}
};
} }

@ -6,11 +6,11 @@ details.toggle-label
input.post-check(type='checkbox', name='delete' value=1) input.post-check(type='checkbox', name='delete' value=1)
| Delete | Delete
label label
input.post-check(type='checkbox', name='delete_file' value=1) input.post-check(type='checkbox', name='unlink_file' value=1)
| Delete File Only | Unlink Files
label label
input.post-check(type='checkbox', name='spoiler' value=1) input.post-check(type='checkbox', name='spoiler' value=1)
| Spoiler Images | Spoiler Files
label label
input#password(type='text', name='password', placeholder='post password' autocomplete='off') input#password(type='text', name='password', placeholder='post password' autocomplete='off')
label label
@ -29,6 +29,9 @@ details.toggle-label
label label
input.post-check(type='checkbox', name='delete_ip_global' value=1) input.post-check(type='checkbox', name='delete_ip_global' value=1)
| Delete from IP globally | Delete from IP globally
label
input.post-check(type='checkbox', name='delete_file' value=1)
| Delete Files
label label
input.post-check(type='checkbox', name='sticky' value=1) input.post-check(type='checkbox', name='sticky' value=1)
| Sticky | Sticky

@ -7,10 +7,10 @@ details.toggle-label
| Delete | Delete
label label
input.post-check(type='checkbox', name='delete_file' value=1) input.post-check(type='checkbox', name='delete_file' value=1)
| Delete File Only | Delete Files
label label
input.post-check(type='checkbox', name='spoiler' value=1) input.post-check(type='checkbox', name='spoiler' value=1)
| Spoiler Images | Spoiler Files
label label
input.post-check(type='checkbox', name='delete_ip_global' value=1) input.post-check(type='checkbox', name='delete_ip_global' value=1)
| Delete from IP globally | Delete from IP globally

@ -7,10 +7,10 @@ details.toggle-label
| Delete | Delete
label label
input.post-check(type='checkbox', name='delete_file' value=1) input.post-check(type='checkbox', name='delete_file' value=1)
| Delete File Only | Delete Files
label label
input.post-check(type='checkbox', name='spoiler' value=1) input.post-check(type='checkbox', name='spoiler' value=1)
| Spoiler Images | Spoiler Files
label label
input.post-check(type='checkbox', name='global_report' value=1) input.post-check(type='checkbox', name='global_report' value=1)
| Global Report | Global Report

Loading…
Cancel
Save