Merge branch '340-confidential-issue' into new-dev

merge-requests/218/head^2
Thomas Lynch 3 years ago
commit 19a8240001
  1. 58
      db/posts.js
  2. 8
      models/forms/makepost.js
  3. 2
      models/pages/globalmanage/recent.js

@ -21,38 +21,20 @@ module.exports = {
return Math.ceil(threadsBefore/10) || 1; //1 because 0 threads before is page 1
},
getGlobalRecent: (offset=0, limit=20, ip, permLevel) => {
//global recent posts for recent section of global manage page
getBoardRecent: async (offset=0, limit=20, ip, board, permLevel) => {
const query = {};
const projection = {
'salt': 0,
'password': 0,
'reports': 0,
};
if (ip instanceof RegExp) {
query['ip.single'] = ip;
} else if (typeof ip === 'string') {
query['ip.raw'] = ip;
}
if (permLevel > config.get.ipHashPermLevel) {
projection['ip.raw'] = 0;
if (board) {
query['board'] = board;
}
return db.find(query, {
projection
}).sort({
'_id': -1
}).skip(offset).limit(limit).toArray();
},
getBoardRecent: (offset=0, limit=20, ip, board, permLevel) => {
const query = {
board
};
const projection = {
'salt': 0,
'password': 0,
'globalreports': 0,
};
if (!board) {
projection['reports'] = 0;
} else {
projection['globalreports'] = 0;
}
if (ip instanceof RegExp) {
query['ip.single'] = ip;
} else if (typeof ip === 'string') {
@ -60,12 +42,34 @@ module.exports = {
}
if (permLevel > config.get.ipHashPermLevel) {
projection['ip.raw'] = 0;
//MongoError, why cant i just projection['reports.ip.raw'] = 0;
if (board) {
projection['reports'] = { ip: { raw: 0 } };
} else {
projection['globalreports'] = { ip: { raw: 0 } };
}
}
return db.find(query, {
const posts = await db.find(query, {
projection
}).sort({
'_id': -1
}).skip(offset).limit(limit).toArray();
posts.forEach(p => {
//kill me
p.ip.single = p.ip.single.slice(-10);
p.ip.qrange = p.ip.qrange.slice(-10);
p.ip.hrange = p.ip.hrange.slice(-10);
if (board) {
p.reports.forEach(r => {
r.ip.single = r.ip.single.slice(-10);
});
} else {
p.globalreports.forEach(r => {
r.ip.single = r.ip.single.slice(-10);
});
}
});
return posts;
},
getRecent: async (board, page, limit=10, getSensitive=false, sortSticky=true) => {

@ -595,10 +595,10 @@ ${res.locals.numFiles > 0 ? req.files.file.map(f => f.name+'|'+(f.phash || '')).
}
const { raw, single } = data.ip;
//but emit it to manage pages because they need to get all posts through socket including thread
Socketio.emitRoom('globalmanage-recent-hashed', 'newPost', { ...projectedPost, ip: { single, raw: null } });
Socketio.emitRoom('globalmanage-recent-raw', 'newPost', { ...projectedPost, ip: { single, raw } });
Socketio.emitRoom(`${res.locals.board._id}-manage-recent-hashed`, 'newPost', { ...projectedPost, ip: { single, raw: null } });
Socketio.emitRoom(`${res.locals.board._id}-manage-recent-raw`, 'newPost', { ...projectedPost, ip: { single, raw } });
Socketio.emitRoom('globalmanage-recent-hashed', 'newPost', { ...projectedPost, ip: { single: single.slice(-10), raw: null } });
Socketio.emitRoom('globalmanage-recent-raw', 'newPost', { ...projectedPost, ip: { single: single.slice(-10), raw } });
Socketio.emitRoom(`${res.locals.board._id}-manage-recent-hashed`, 'newPost', { ...projectedPost, ip: { single: single.slice(-10), raw: null } });
Socketio.emitRoom(`${res.locals.board._id}-manage-recent-raw`, 'newPost', { ...projectedPost, ip: { single: single.slice(-10), raw } });
//now add other pages to be built in background
if (enableCaptcha) {

@ -12,7 +12,7 @@ module.exports = async (req, res, next) => {
let posts;
try {
posts = await Posts.getGlobalRecent(offset, limit, ipMatch, res.locals.permLevel);
posts = await Posts.getBoardRecent(offset, limit, ipMatch, null, res.locals.permLevel);
} catch (err) {
return next(err)
}

Loading…
Cancel
Save