|
|
@ -12,57 +12,67 @@ const Mongo = require(__dirname+'/../db/db.js') |
|
|
|
module.exports = { |
|
|
|
module.exports = { |
|
|
|
|
|
|
|
|
|
|
|
buildBanners: async(board) => { |
|
|
|
buildBanners: async(board) => { |
|
|
|
console.log('building banners', `${board._id}/banners.html`); |
|
|
|
const buildName = `Building: ${board._id}/banners.html`; |
|
|
|
return render(`${board._id}/banners.html`, 'banners.pug', { |
|
|
|
console.time(buildName); |
|
|
|
|
|
|
|
await render(`${board._id}/banners.html`, 'banners.pug', { |
|
|
|
board: board, |
|
|
|
board: board, |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
console.timeEnd(buildName); |
|
|
|
}, |
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
buildCatalog: async (board) => { |
|
|
|
buildCatalog: async (board) => { |
|
|
|
console.log('building catalog', `${board._id}/catalog.html`); |
|
|
|
const buildName = `Building: ${board._id}/catalog.html`; |
|
|
|
|
|
|
|
console.time(buildName); |
|
|
|
if (!board._id) { |
|
|
|
if (!board._id) { |
|
|
|
board = await Boards.findOne(board); |
|
|
|
board = await Boards.findOne(board); |
|
|
|
} |
|
|
|
} |
|
|
|
const threads = await Posts.getCatalog(board._id); |
|
|
|
const threads = await Posts.getCatalog(board._id); |
|
|
|
return render(`${board._id}/catalog.html`, 'catalog.pug', { |
|
|
|
await render(`${board._id}/catalog.html`, 'catalog.pug', { |
|
|
|
board, |
|
|
|
board, |
|
|
|
threads, |
|
|
|
threads, |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
console.timeEnd(buildName); |
|
|
|
}, |
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
buildThread: async (threadId, board) => { |
|
|
|
buildThread: async (threadId, board) => { |
|
|
|
console.log('building thread', `${board._id || board}/thread/${threadId}.html`); |
|
|
|
const buildName = `Building: ${board._id || board}/thread/${threadId}.html`; |
|
|
|
|
|
|
|
console.time(buildName); |
|
|
|
if (!board._id) { |
|
|
|
if (!board._id) { |
|
|
|
board = await Boards.findOne(board); |
|
|
|
board = await Boards.findOne(board); |
|
|
|
} |
|
|
|
} |
|
|
|
const thread = await Posts.getThread(board._id, threadId) |
|
|
|
const thread = await Posts.getThread(board._id, threadId) |
|
|
|
if (!thread) { |
|
|
|
if (!thread) { |
|
|
|
|
|
|
|
console.timeEnd(buildName, 'deleted OP') |
|
|
|
return; //this thread may have been an OP that was deleted
|
|
|
|
return; //this thread may have been an OP that was deleted
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
await render(`${board._id}/thread/${threadId}.html`, 'thread.pug', { |
|
|
|
return render(`${board._id}/thread/${threadId}.html`, 'thread.pug', { |
|
|
|
|
|
|
|
board, |
|
|
|
board, |
|
|
|
thread, |
|
|
|
thread, |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
console.timeEnd(buildName); |
|
|
|
}, |
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
buildBoard: async (board, page, maxPage=null) => { |
|
|
|
buildBoard: async (board, page, maxPage=null) => { |
|
|
|
console.log('building board page', `${board._id}/${page === 1 ? 'index' : page}.html`); |
|
|
|
const buildName = `Building: ${board._id || board}/${page === 1 ? 'index' : page}.html`; |
|
|
|
|
|
|
|
console.time(buildName); |
|
|
|
const threads = await Posts.getRecent(board._id, page); |
|
|
|
const threads = await Posts.getRecent(board._id, page); |
|
|
|
if (maxPage == null) { |
|
|
|
if (maxPage == null) { |
|
|
|
maxPage = Math.min(Math.ceil((await Posts.getPages(board._id)) / 10), Math.ceil(board.settings.threadLimit/10)); |
|
|
|
maxPage = Math.min(Math.ceil((await Posts.getPages(board._id)) / 10), Math.ceil(board.settings.threadLimit/10)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return render(`${board._id}/${page === 1 ? 'index' : page}.html`, 'board.pug', { |
|
|
|
await render(`${board._id}/${page === 1 ? 'index' : page}.html`, 'board.pug', { |
|
|
|
board, |
|
|
|
board, |
|
|
|
threads, |
|
|
|
threads, |
|
|
|
maxPage, |
|
|
|
maxPage, |
|
|
|
page, |
|
|
|
page, |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
console.timeEnd(buildName); |
|
|
|
}, |
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
//building multiple pages (for rebuilds)
|
|
|
|
//building multiple pages (for rebuilds)
|
|
|
|
buildBoardMultiple: async (board, startpage=1, endpage) => { |
|
|
|
buildBoardMultiple: async (board, startpage=1, endpage) => { |
|
|
|
|
|
|
|
const buildName = 'multi page build'; |
|
|
|
|
|
|
|
console.time(buildName); |
|
|
|
const maxPage = Math.min(Math.ceil((await Posts.getPages(board._id)) / 10), Math.ceil(board.settings.threadLimit/10)); |
|
|
|
const maxPage = Math.min(Math.ceil((await Posts.getPages(board._id)) / 10), Math.ceil(board.settings.threadLimit/10)); |
|
|
|
if (endpage === 0) { |
|
|
|
if (endpage === 0) { |
|
|
|
//deleted only/all posts, so only 1 page will remain
|
|
|
|
//deleted only/all posts, so only 1 page will remain
|
|
|
@ -73,9 +83,8 @@ console.log('building board page', `${board._id}/${page === 1 ? 'index' : page}. |
|
|
|
} |
|
|
|
} |
|
|
|
const difference = endpage-startpage + 1; //+1 because for single pagemust be > 0
|
|
|
|
const difference = endpage-startpage + 1; //+1 because for single pagemust be > 0
|
|
|
|
const threads = await Posts.getRecent(board._id, startpage, difference*10); |
|
|
|
const threads = await Posts.getRecent(board._id, startpage, difference*10); |
|
|
|
|
|
|
|
console.timeLog(buildName, `${board._id}/ ${startpage === 1 ? 'index' : startpage} -> ${endpage === 1 ? 'index' : endpage} .html`); |
|
|
|
const buildArray = []; |
|
|
|
const buildArray = []; |
|
|
|
console.log('multi building board pages', `${board._id}/ ${startpage === 1 ? 'index' : startpage} -> ${endpage === 1 ? 'index' : endpage} .html`); |
|
|
|
|
|
|
|
for (let i = startpage; i <= endpage; i++) { |
|
|
|
for (let i = startpage; i <= endpage; i++) { |
|
|
|
let spliceStart = (i-1)*10; |
|
|
|
let spliceStart = (i-1)*10; |
|
|
|
if (spliceStart > 0) { |
|
|
|
if (spliceStart > 0) { |
|
|
@ -90,11 +99,13 @@ console.log('multi building board pages', `${board._id}/ ${startpage === 1 ? 'in |
|
|
|
}) |
|
|
|
}) |
|
|
|
); |
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|
return Promise.all(buildArray); |
|
|
|
await Promise.all(buildArray); |
|
|
|
|
|
|
|
console.timeEnd(buildName); |
|
|
|
}, |
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
buildHomepage: async () => { |
|
|
|
buildHomepage: async () => { |
|
|
|
console.log('building homepage /index.html'); |
|
|
|
const buildName = `Building: index.html`; |
|
|
|
|
|
|
|
console.time(buildName); |
|
|
|
//getting boards
|
|
|
|
//getting boards
|
|
|
|
const boards = await Boards.find(); |
|
|
|
const boards = await Boards.find(); |
|
|
|
//geting PPH for each board
|
|
|
|
//geting PPH for each board
|
|
|
@ -142,10 +153,11 @@ console.log('building homepage /index.html'); |
|
|
|
totalSizeString: formatSize(stats.size) |
|
|
|
totalSizeString: formatSize(stats.size) |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
}); |
|
|
|
return render('index.html', 'home.pug', { |
|
|
|
await render('index.html', 'home.pug', { |
|
|
|
boards, |
|
|
|
boards, |
|
|
|
fileStats, |
|
|
|
fileStats, |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
console.timeEnd(buildName); |
|
|
|
}, |
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
buildChangePassword: () => { |
|
|
|
buildChangePassword: () => { |
|
|
|