|
|
@ -14,6 +14,11 @@ module.exports = { |
|
|
|
// get all thread posts (posts with null thread id)
|
|
|
|
// get all thread posts (posts with null thread id)
|
|
|
|
const threads = await db.collection(board).find({ |
|
|
|
const threads = await db.collection(board).find({ |
|
|
|
'thread': null |
|
|
|
'thread': null |
|
|
|
|
|
|
|
},{ |
|
|
|
|
|
|
|
'projection': { |
|
|
|
|
|
|
|
'salt': 0, |
|
|
|
|
|
|
|
'password': 0 |
|
|
|
|
|
|
|
} |
|
|
|
}).sort({ |
|
|
|
}).sort({ |
|
|
|
'bumped': -1 |
|
|
|
'bumped': -1 |
|
|
|
}).skip(10*(page-1)).limit(10).toArray(); |
|
|
|
}).skip(10*(page-1)).limit(10).toArray(); |
|
|
@ -22,8 +27,11 @@ module.exports = { |
|
|
|
await Promise.all(threads.map(async thread => { |
|
|
|
await Promise.all(threads.map(async thread => { |
|
|
|
const replies = await db.collection(board).find({ |
|
|
|
const replies = await db.collection(board).find({ |
|
|
|
'thread': thread._id |
|
|
|
'thread': thread._id |
|
|
|
}, { |
|
|
|
},{ |
|
|
|
'projection': { 'salt': 0 } |
|
|
|
'projection': { |
|
|
|
|
|
|
|
'salt': 0, |
|
|
|
|
|
|
|
'password': 0, |
|
|
|
|
|
|
|
} |
|
|
|
}).sort({ |
|
|
|
}).sort({ |
|
|
|
'_id': -1 |
|
|
|
'_id': -1 |
|
|
|
}).limit(3).toArray(); |
|
|
|
}).limit(3).toArray(); |
|
|
@ -45,7 +53,10 @@ module.exports = { |
|
|
|
db.collection(board).findOne({ |
|
|
|
db.collection(board).findOne({ |
|
|
|
'_id': id |
|
|
|
'_id': id |
|
|
|
}, { |
|
|
|
}, { |
|
|
|
'projection': { 'salt': 0 } //projection to hide salts
|
|
|
|
'projection': { |
|
|
|
|
|
|
|
'salt': 0, |
|
|
|
|
|
|
|
'password': 0 |
|
|
|
|
|
|
|
} |
|
|
|
}), |
|
|
|
}), |
|
|
|
module.exports.getThreadPosts(board, id) |
|
|
|
module.exports.getThreadPosts(board, id) |
|
|
|
]) |
|
|
|
]) |
|
|
@ -66,7 +77,10 @@ module.exports = { |
|
|
|
return db.collection(board).find({ |
|
|
|
return db.collection(board).find({ |
|
|
|
'thread': id |
|
|
|
'thread': id |
|
|
|
}, { |
|
|
|
}, { |
|
|
|
'projection': { 'salt': 0 } //projection to hide salts
|
|
|
|
'projection': { |
|
|
|
|
|
|
|
'salt': 0 , |
|
|
|
|
|
|
|
'password': 0 |
|
|
|
|
|
|
|
} |
|
|
|
}).sort({ |
|
|
|
}).sort({ |
|
|
|
'_id': 1 |
|
|
|
'_id': 1 |
|
|
|
}).toArray(); |
|
|
|
}).toArray(); |
|
|
@ -79,31 +93,42 @@ module.exports = { |
|
|
|
return db.collection(board).find({ |
|
|
|
return db.collection(board).find({ |
|
|
|
'thread': null |
|
|
|
'thread': null |
|
|
|
}, { |
|
|
|
}, { |
|
|
|
'projection': { 'salt': 0 } //projection to hide salts
|
|
|
|
'projection': { |
|
|
|
|
|
|
|
'salt': 0, |
|
|
|
|
|
|
|
'password': 0 |
|
|
|
|
|
|
|
} |
|
|
|
}).toArray(); |
|
|
|
}).toArray(); |
|
|
|
|
|
|
|
|
|
|
|
}, |
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
getPost: async (board, id, salt) => { |
|
|
|
getPost: async (board, id, admin) => { |
|
|
|
|
|
|
|
|
|
|
|
// get a post
|
|
|
|
// get a post
|
|
|
|
return db.collection(board).findOne({ |
|
|
|
return db.collection(board).findOne({ |
|
|
|
'_id': id |
|
|
|
'_id': id |
|
|
|
}, { |
|
|
|
}, { |
|
|
|
'projection': { 'salt': salt || false } //projection to hide salts
|
|
|
|
'projection': { |
|
|
|
|
|
|
|
'salt': admin || false, |
|
|
|
|
|
|
|
'password': admin || false |
|
|
|
|
|
|
|
//only reveal passwords when admin is true (e.g. getting to check salt)
|
|
|
|
|
|
|
|
} |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
}, |
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
//takes array "ids" of post ids
|
|
|
|
//takes array "ids" of post ids
|
|
|
|
getPosts: async(board, ids) => { |
|
|
|
getPosts: async(board, ids, admin) => { |
|
|
|
|
|
|
|
|
|
|
|
return db.collection(board).find({ |
|
|
|
return db.collection(board).find({ |
|
|
|
'_id': { |
|
|
|
'_id': { |
|
|
|
'$in': ids |
|
|
|
'$in': ids |
|
|
|
} |
|
|
|
} |
|
|
|
}, { |
|
|
|
}, { |
|
|
|
'projection': { 'salt': 0 } //projection to hide salts
|
|
|
|
'projection': { |
|
|
|
|
|
|
|
'salt': admin || false, |
|
|
|
|
|
|
|
'password': admin || false |
|
|
|
|
|
|
|
//only reveal passwords when admin is true (e.g. when fetching for deletion)
|
|
|
|
|
|
|
|
} |
|
|
|
}).toArray(); |
|
|
|
}).toArray(); |
|
|
|
|
|
|
|
|
|
|
|
}, |
|
|
|
}, |
|
|
|