diff --git a/.gitignore b/.gitignore index 4595370d..43af1fe0 100644 --- a/.gitignore +++ b/.gitignore @@ -2,5 +2,6 @@ node_modules/ backup.sh configs/*.json static/* +gulp/res/js/socket.io.js gulp/dist/ tmp/ diff --git a/db/accounts.js b/db/accounts.js index 5c2b1a41..e1ce00f3 100644 --- a/db/accounts.js +++ b/db/accounts.js @@ -7,6 +7,8 @@ const Mongo = require(__dirname+'/db.js') module.exports = { + db, + count: (usernames) => { return db.countDocuments({ '_id': { @@ -22,7 +24,6 @@ module.exports = { insertOne: async (username, password, authLevel) => { // hash the password const passwordHash = await bcrypt.hash(password, 12); - //add to db return db.insertOne({ '_id': username, diff --git a/db/files.js b/db/files.js index 81ebc0a3..988a902e 100644 --- a/db/files.js +++ b/db/files.js @@ -56,10 +56,18 @@ module.exports = { } ]).toArray().then(res => { const stats = res[0]; - return { - count: stats.count, - totalSize: stats.size, - totalSizeString: formatSize(stats.size) + if (stats) { + return { + count: stats.count, + totalSize: stats.size, + totalSizeString: formatSize(stats.size) + } + } else { + return { + count: 0, + totalSize: 0, + totalSizeString: '0B' + } } }); }, diff --git a/db/modlogs.js b/db/modlogs.js index 921f1cef..31f2b626 100644 --- a/db/modlogs.js +++ b/db/modlogs.js @@ -5,6 +5,8 @@ const Mongo = require(__dirname+'/db.js') module.exports = { + db, + getDates: (board) => { return db.aggregate([ { diff --git a/db/news.js b/db/news.js index 285a0c3e..288f786e 100644 --- a/db/news.js +++ b/db/news.js @@ -6,6 +6,8 @@ const Mongo = require(__dirname+'/db.js') module.exports = { + db, + find: () => { return db.find({}).sort({ '_id': -1 diff --git a/db/ratelimits.js b/db/ratelimits.js index 6854498b..fc5d24cc 100644 --- a/db/ratelimits.js +++ b/db/ratelimits.js @@ -31,7 +31,7 @@ module.exports = { }, deleteAll: () => { - return ratelimit.deleteMany({}); + return db.deleteMany({}); }, } diff --git a/db/stats.js b/db/stats.js index fc27e37d..d13f4606 100644 --- a/db/stats.js +++ b/db/stats.js @@ -6,6 +6,8 @@ const Mongo = require(__dirname+'/db.js') module.exports = { + db, + updateOne: (board, ip, thread) => { return db.updateOne({ 'board': board, diff --git a/gulpfile.js b/gulpfile.js index 43d4a577..f34d00a5 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -34,14 +34,7 @@ async function wipe() { const Mongo = require(__dirname+'/db/db.js'); await Mongo.connect(); const { Boards, Posts, Captchas, Ratelimits, - Accounts, Files, Stats, Modlogs, Bans } = require(__dirname+'/db/') - , Posts = require(__dirname+'/db/posts.js') - , Bans = require(__dirname+'/db/bans.js') - , Captchas = require(__dirname+'/db/captchas.js') - , Ratelimits = require(__dirname+'/db/ratelimits.js') - , Accounts = require(__dirname+'/db/accounts.js') - , Files = require(__dirname+'/db/files.js') - , Stats = require(__dirname+'/db/stats.js'); + Accounts, Files, Stats, Modlogs, Bans } = require(__dirname+'/db/'); //wipe db shit await Promise.all([ @@ -157,7 +150,7 @@ function scripts() { .pipe(gulp.dest(paths.scripts.dest)); } -const build = gulp.parallel(css, scripts, images, deletehtml, custompages); +const build = gulp.parallel(css, scripts, images, gulp.series(deletehtml, custompages)); const reset = gulp.series(wipe, build) const html = gulp.series(deletehtml, custompages) diff --git a/helpers/sessionrefresh.js b/helpers/sessionrefresh.js index 8cd82fdc..e914a28b 100644 --- a/helpers/sessionrefresh.js +++ b/helpers/sessionrefresh.js @@ -6,10 +6,14 @@ module.exports = async (req, res, next) => { if (req.session && req.session.authenticated === true) { // keeping session updated incase user updated on global manage const account = await Accounts.findOne(req.session.user.username); - req.session.user = { - 'username': account._id, - 'authLevel': account.authLevel - }; + if (!account) { + req.session.destroy(); + } else { + req.session.user = { + 'username': account._id, + 'authLevel': account.authLevel + }; + } } next(); }