|
|
|
@ -6,10 +6,17 @@ const { Posts, Boards } = require(__dirname+'/../../db/') |
|
|
|
|
|
|
|
|
|
module.exports = async (req, res, next) => { |
|
|
|
|
|
|
|
|
|
const { overboardLimit } = config.get; |
|
|
|
|
const { overboardLimit, allowCustomOverboard } = config.get; |
|
|
|
|
|
|
|
|
|
let selectedBoards = [] |
|
|
|
|
, addBoards = [] |
|
|
|
|
, removeBoards = [] |
|
|
|
|
, removeBoardsSet = new Set() |
|
|
|
|
, includeDefault = true |
|
|
|
|
, cacheQueryString = ''; |
|
|
|
|
|
|
|
|
|
if (allowCustomOverboard === true) { |
|
|
|
|
//sliced to overboardLimit optimisation because there could only be max 1 thread from each of unique boards anyway
|
|
|
|
|
let selectedBoards = []; |
|
|
|
|
const addList = (req.query.add ? (typeof req.query.add === 'string' ? req.query.add.split(',') : req.query.add) : []) |
|
|
|
|
.slice(0, overboardLimit) |
|
|
|
|
.map(b => b.trim()) |
|
|
|
@ -20,19 +27,19 @@ module.exports = async (req, res, next) => { |
|
|
|
|
.map(b => b.trim()) |
|
|
|
|
.filter(b => b) |
|
|
|
|
.sort(); |
|
|
|
|
const addBoards = [...new Set(addList)] |
|
|
|
|
const removeBoardsSet = new Set(removeList); |
|
|
|
|
const removeBoards = [...removeBoardsSet]; |
|
|
|
|
let includeDefault = req.query.include_default === 'true'; |
|
|
|
|
if (!includeDefault && addBoards.length === 0 && removeBoards.length === 0) { |
|
|
|
|
addBoards = [...new Set(addList)] |
|
|
|
|
removeBoardsSet = new Set(removeList); |
|
|
|
|
removeBoards = [...removeBoardsSet]; |
|
|
|
|
includeDefault = req.query.include_default === 'true'; |
|
|
|
|
if (!includeDefault && addBoards.length === 0) { |
|
|
|
|
//...really?
|
|
|
|
|
includeDefault = true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//similar to board list
|
|
|
|
|
const cacheQuery = new URLSearchParams({ include_default: includeDefault, add: addBoards, rem: removeBoards }); |
|
|
|
|
cacheQuery.sort(); |
|
|
|
|
const cacheQueryString = cacheQuery.toString(); |
|
|
|
|
cacheQueryString = cacheQuery.toString(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
let threads = (await cache.get(`overboard:${cacheQueryString}`)) || []; |
|
|
|
|
if (!threads || threads.length === 0) { |
|
|
|
@ -54,7 +61,7 @@ module.exports = async (req, res, next) => { |
|
|
|
|
res |
|
|
|
|
.set('Cache-Control', 'public, max-age=60') |
|
|
|
|
|
|
|
|
|
if (req.path === '/overboard.html') { |
|
|
|
|
if (req.path === '/overboard.json') { |
|
|
|
|
res.json({ |
|
|
|
|
threads, |
|
|
|
|
}); |
|
|
|
@ -66,6 +73,7 @@ module.exports = async (req, res, next) => { |
|
|
|
|
removeBoards, |
|
|
|
|
selectedBoards, |
|
|
|
|
cacheQueryString, |
|
|
|
|
allowCustomOverboard, |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|