proper page responses or frontend stuff with redirects back to board. Fixes #5

merge-requests/208/head
fatchan 5 years ago
parent 50f09d2f83
commit 39b6999c9e
  1. 4
      db-models/posts.js
  2. 15
      models/api/delete-post.js
  3. 16
      models/api/make-post.js
  4. 9
      views/pages/message.pug

@ -80,13 +80,13 @@ module.exports = {
}, },
getPost: async (board, id) => { getPost: async (board, id, salt) => {
// get a post // get a post
return db.collection(board).findOne({ return db.collection(board).findOne({
'_id': id '_id': id
}, { }, {
'projection': { 'salt': 0 } //projection to hide salts 'projection': { 'salt': salt || false } //projection to hide salts
}); });
}, },

@ -14,7 +14,7 @@ module.exports = async (req, res) => {
posts = await Posts.getPosts(req.params.board, req.body.checked); posts = await Posts.getPosts(req.params.board, req.body.checked);
} catch (err) { } catch (err) {
console.error(err); console.error(err);
return res.status(500).json({ 'message': 'Error fetching from DB' }); return res.status(500).render('error');
} }
//filter it to ones that match the password //filter it to ones that match the password
@ -42,7 +42,7 @@ module.exports = async (req, res) => {
deletedPosts = result.deletedCount; deletedPosts = result.deletedCount;
} catch (err) { } catch (err) {
console.error(err); console.error(err);
return res.status(500).json({ 'message': 'Error deleting posts from DB' }); return res.status(500).render('error');
} }
//get filenames from all the posts //get filenames from all the posts
@ -61,9 +61,16 @@ module.exports = async (req, res) => {
})); }));
//hooray! //hooray!
return res.json({ 'message': `deleted ${threadIds.length} threads and ${deletedPosts} posts` }) return res.render('message', {
'message': `deleted ${threadIds.length} threads and ${deletedPosts} posts`,
'redirect': `/${req.params.board}`
});
} }
return res.status(403).json({ 'message': 'Password did not match any selected posts' }) return res.render('message', {
'message': 'Password did not match any selected posts',
'redirect': `/${req.params.board}`
});
} }

@ -19,13 +19,16 @@ module.exports = async (req, res, numFiles) => {
if (req.body.thread) { if (req.body.thread) {
let thread; let thread;
try { try {
thread = await Posts.getPost(req.params.board, req.body.thread); thread = await Posts.getPost(req.params.board, req.body.thread, true);
} catch (err) { } catch (err) {
console.error(err); console.error(err);
return res.status(500).json({ 'message': 'Error fetching from DB' }); return res.status(500).render('error');
} }
if (!thread || thread.thread != null) { if (!thread || thread.thread != null) {
return res.status(400).json({ 'message': 'thread does not exist' }) return res.status(400).render('message', {
'message': 'Thread does not exist.',
'redirect': `/${req.params.board}`
})
} }
salt = thread.salt; salt = thread.salt;
} }
@ -36,7 +39,10 @@ module.exports = async (req, res, numFiles) => {
// check all mime types befoer we try saving anything // check all mime types befoer we try saving anything
for (let i = 0; i < numFiles; i++) { for (let i = 0; i < numFiles; i++) {
if (!fileCheckMimeType(req.files.file[i].mimetype)) { if (!fileCheckMimeType(req.files.file[i].mimetype)) {
return res.status(400).json({ 'message': 'Invalid file type' }); return res.status(400).render('message', {
'message': 'Invalid file type',
'redirect': `/${req.params.board}`
});
} }
} }
// then upload, thumb, get metadata, etc. // then upload, thumb, get metadata, etc.
@ -71,7 +77,7 @@ module.exports = async (req, res, numFiles) => {
} catch (err) { } catch (err) {
console.error(err); console.error(err);
//TODO: DELETE FAILED FILES //TODO: DELETE FAILED FILES
return res.status(500).json({ 'message': 'Error uploading file' }); return res.status(500).render('error');
} }
} }
} }

@ -0,0 +1,9 @@
extends ../layout.pug
block head
meta(http-equiv="refresh" content=`5;url=${redirect}`)
block content
h1 Success
p #{message}
p You will be redirected shortly. If you are not redirected automatically, you can #[a(href=redirect) click here].
Loading…
Cancel
Save