mirror of https://gitgud.io/fatchan/jschan.git
merge-requests/208/head
parent
6ae05b58ed
commit
ebf0b603f5
16 changed files with 103 additions and 46 deletions
@ -1,29 +1,16 @@ |
||||
'use strict'; |
||||
|
||||
const Boards = require(__dirname+'/../../db/boards.js'); |
||||
const { buildBanners } = require(__dirname+'/../../build.js') |
||||
, uploadDirectory = require(__dirname+'/../../helpers/uploadDirectory.js'); |
||||
|
||||
module.exports = async (req, res, next) => { |
||||
|
||||
if (!req.query.board) { |
||||
return next(); |
||||
try { |
||||
await buildBanners(res.locals.board); |
||||
} catch (err) { |
||||
return next(err); |
||||
} |
||||
|
||||
//agregate to get single random item from banners array
|
||||
const board = await Boards.db.aggregate([ |
||||
{ |
||||
'$unwind': '$banners' |
||||
}, |
||||
{ |
||||
'$sample': { |
||||
'size' : 1 |
||||
} |
||||
} |
||||
]).toArray().then(res => res[0]); |
||||
|
||||
if (board && board.banners != null) { |
||||
return res.redirect(`/banner/${req.query.board}/${board.banners}`); |
||||
} |
||||
|
||||
return res.redirect('/img/defaultbanner.png'); |
||||
return res.sendFile(`${uploadDirectory}html/${req.params.board}/banners.html`); |
||||
|
||||
} |
||||
|
@ -0,0 +1,29 @@ |
||||
'use strict'; |
||||
|
||||
const Boards = require(__dirname+'/../../db/boards.js'); |
||||
|
||||
module.exports = async (req, res, next) => { |
||||
|
||||
if (!req.query.board) { |
||||
return next(); |
||||
} |
||||
|
||||
//agregate to get single random item from banners array
|
||||
const board = await Boards.db.aggregate([ |
||||
{ |
||||
'$unwind': '$banners' |
||||
}, |
||||
{ |
||||
'$sample': { |
||||
'size' : 1 |
||||
} |
||||
} |
||||
]).toArray().then(res => res[0]); |
||||
|
||||
if (board && board.banners != null) { |
||||
return res.redirect(`/banner/${req.query.board}/${board.banners}`); |
||||
} |
||||
|
||||
return res.redirect('/img/defaultbanner.png'); |
||||
|
||||
} |
@ -0,0 +1,2 @@ |
||||
section.board-header |
||||
h1.board-title Banners (#[a.no-decoration(href=`/${board._id}/index.html`) /#{board._id}/]) |
@ -1,4 +1,4 @@ |
||||
section.board-header |
||||
img.board-banner(src=`/banners?board=${board._id}` width='300' height='100') |
||||
img.board-banner(src=`/randombanner?board=${board._id}` width='300' height='100') |
||||
br |
||||
h1.board-title Catalog (#[a.no-decoration(href=`/${board._id}/index.html`) /#{board._id}/]) |
||||
|
@ -1,15 +1,5 @@ |
||||
| Page: |
||||
if page === 1 |
||||
a(href=`/${board._id}/index.html`) [#{1}] |
||||
| |
||||
else |
||||
a(href=`/${board._id}/index.html`) #{1} |
||||
| |
||||
- for(let i = 2; i <= maxPage; i++) |
||||
if i === page |
||||
a(href=`/${board._id}/${i}.html`) [#{i}] |
||||
| |
||||
else |
||||
a(href=`/${board._id}/${i}.html`) #{i} |
||||
- for(let i = 1; i <= maxPage; i++) |
||||
a(class=`${page === i ? 'bold' : ''}` href=`/${board._id}/${i === 1 ? 'index' : i}.html`) [#{i}] |
||||
| |
||||
| | |
||||
|
@ -0,0 +1,14 @@ |
||||
extends ../layout.pug |
||||
|
||||
block head |
||||
title /#{board._id}/ - Banners |
||||
|
||||
block content |
||||
include ../includes/bannersheader.pug |
||||
hr(size=1) |
||||
section.catalog |
||||
if board.banners.length > 0 |
||||
each banner in board.banners |
||||
img.board-banner(src=`/banner/${board._id}/${banner}` width='300' height='100') |
||||
else |
||||
p Board has no custom banners. |
Loading…
Reference in new issue