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')
, Boards = require(__dirname+'/boards.js')
, deletePostFiles = require(__dirname+'/../helpers/files/deletepostfiles.js')
, db = Mongo.client.db('jschan').collection('posts');
module.exports = {
@ -272,7 +271,7 @@ module.exports = {
},
insertOne: async (board, data, thread) => {
if (data.thread !== null && data.email !== 'sage' && !thread.saged) {
if (data.thread !== null) {
const filter = {
'postId': data.thread,
'board': board
@ -355,14 +354,6 @@ module.exports = {
const threadPosts = await module.exports.getMultipleThreadPosts(board, threadIds);
//combine them
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
const postMongoIds = postsAndThreads.map(post => Mongo.ObjectId(post._id));
await module.exports.deleteMany(postMongoIds);

@ -49,23 +49,21 @@ module.exports = async (req, res, next) => {
const passwordCombinedQuery = {};
let aggregateNeeded = false;
try {
if (res.locals.hasPerms) {
// if getting global banned, board ban doesnt matter
if (req.body.global_ban) {
const { message, action, query } = await banPoster(req, res, next, null, res.locals.posts);
if (action) {
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);
// if getting global banned, board ban doesnt matter
if (req.body.global_ban) {
const { message, action, query } = await banPoster(req, res, next, null, res.locals.posts);
if (action) {
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);
}
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);
let query = {
'ip': {
@ -88,8 +86,8 @@ module.exports = async (req, res, next) => {
aggregateNeeded = true;
} else {
// if it was getting deleted, we cant do any of these
if (req.body.delete_file) {
const { message, action, query } = await deletePostsFiles(passwordPosts);
if (req.body.delete_file || req.body.unlink_file) {
const { message, action, query } = await deletePostsFiles(passwordPosts, req.body.unlink_file);
if (action) {
aggregateNeeded = true;
passwordCombinedQuery[action] = { ...passwordCombinedQuery[action], ...query}
@ -102,29 +100,27 @@ module.exports = async (req, res, next) => {
}
messages.push(message);
}
if (res.locals.hasPerms) {
//lock, sticky, sage
if (req.body.sage) {
const { message, action, query } = sagePosts(res.locals.posts);
if (action) {
combinedQuery[action] = { ...combinedQuery[action], ...query}
}
messages.push(message);
//lock, sticky, sage
if (req.body.sage) {
const { message, action, query } = sagePosts(res.locals.posts);
if (action) {
combinedQuery[action] = { ...combinedQuery[action], ...query}
}
if (req.body.lock) {
const { message, action, query } = lockPosts(res.locals.posts);
if (action) {
combinedQuery[action] = { ...combinedQuery[action], ...query}
}
messages.push(message);
messages.push(message);
}
if (req.body.lock) {
const { message, action, query } = lockPosts(res.locals.posts);
if (action) {
combinedQuery[action] = { ...combinedQuery[action], ...query}
}
if (req.body.sticky) {
const { message, action, query } = stickyPosts(res.locals.posts);
if (action) {
combinedQuery[action] = { ...combinedQuery[action], ...query}
}
messages.push(message);
messages.push(message);
}
if (req.body.sticky) {
const { message, action, query } = stickyPosts(res.locals.posts);
if (action) {
combinedQuery[action] = { ...combinedQuery[action], ...query}
}
messages.push(message);
}
// cannot report and dismiss at same time
if (req.body.report) {
@ -133,7 +129,7 @@ module.exports = async (req, res, next) => {
combinedQuery[action] = { ...combinedQuery[action], ...query}
}
messages.push(message);
} else if (res.locals.hasPerms && req.body.dismiss) {
} else if (req.body.dismiss) {
const { message, action, query } = dismissReports(res.locals.posts);
if (action) {
combinedQuery[action] = { ...combinedQuery[action], ...query}
@ -147,7 +143,7 @@ module.exports = async (req, res, next) => {
combinedQuery[action] = { ...combinedQuery[action], ...query}
}
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);
if (action) {
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
//rebuild current and newer pages
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
//should rebuild only affected pages, but finding the page of all affected
//threads could end up being slower/more resource intensive. this is simpler.

@ -1,7 +1,6 @@
'use strict';
const uploadDirectory = require(__dirname+'/../../helpers/uploadDirectory.js')
, deletePostFiles = require(__dirname+'/../../helpers/files/deletepostfiles.js')
, remove = require('fs-extra').remove
, Mongo = require(__dirname+'/../../db/db.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
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 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))
})
//delete post files
if (fileNames.length > 0) {
await deletePostFiles(fileNames);
}
//hooray!
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}`);
}));
// 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);
return res.render('message', {

@ -3,7 +3,7 @@
const remove = require('fs-extra').remove
, uploadDirectory = require(__dirname+'/../../helpers/uploadDirectory.js')
module.exports = async (posts) => {
module.exports = async (posts, unlinkOnly) => {
//get filenames from all the posts
let fileNames = [];
@ -13,25 +13,31 @@ module.exports = async (posts) => {
if (fileNames.length === 0) {
return {
message: 'No files to delete'
message: 'No files found'
}
}
//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]}.png`)
])
}));
if (unlinkOnly) {
return {
message:`Unlinked ${fileNames.length} file(s) across ${posts.length} post(s)`,
action:'$set',
query: {
'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)
| Delete
label
input.post-check(type='checkbox', name='delete_file' value=1)
| Delete File Only
input.post-check(type='checkbox', name='unlink_file' value=1)
| Unlink Files
label
input.post-check(type='checkbox', name='spoiler' value=1)
| Spoiler Images
| Spoiler Files
label
input#password(type='text', name='password', placeholder='post password' autocomplete='off')
label
@ -29,6 +29,9 @@ details.toggle-label
label
input.post-check(type='checkbox', name='delete_ip_global' value=1)
| Delete from IP globally
label
input.post-check(type='checkbox', name='delete_file' value=1)
| Delete Files
label
input.post-check(type='checkbox', name='sticky' value=1)
| Sticky

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

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

Loading…
Cancel
Save