mirror of https://gitgud.io/fatchan/jschan.git
parent
8ffdedee8a
commit
e97692408e
6 changed files with 135 additions and 121 deletions
@ -0,0 +1,62 @@ |
||||
'use strict'; |
||||
|
||||
const express = require('express') |
||||
, router = express.Router() |
||||
, utils = require('../utils.js') |
||||
, Posts = require(__dirname+'/../models/posts.js'); |
||||
|
||||
/* |
||||
roughly: |
||||
- GET /api/board/:board/catalog -> all threads (catalog) |
||||
- GET /api/board/:board/recent/:page? -> recent posts per page (board homepage) |
||||
- GET /api/board/:board/thread/:thread -> get all posts in a thread |
||||
|
||||
- POST /api/board/:board -> make a new thread |
||||
- POST /api/board/:board/thread/:thread -> make a new post in a thread |
||||
|
||||
- DELETE /api/board/:board/post/:id -> delete a post |
||||
*/ |
||||
|
||||
// board page/recents
|
||||
router.get('/:board/:page?', Posts.checkBoard, async (req, res, next) => { |
||||
|
||||
//get the recently bumped thread & preview posts
|
||||
let threads; |
||||
try { |
||||
threads = await Posts.getRecent(req.params.board, req.params.page); |
||||
} catch (err) { |
||||
return next(err); |
||||
} |
||||
|
||||
//render the page
|
||||
res.render('board', { |
||||
csrf: req.csrfToken(), |
||||
board: req.params.board, |
||||
threads: threads || [] |
||||
}); |
||||
|
||||
}); |
||||
|
||||
// thread view page
|
||||
router.get('/:board/thread/:thread', Posts.checkBoard, async (req, res, next) => { |
||||
|
||||
//get the recently bumped thread & preview posts
|
||||
let thread; |
||||
try { |
||||
thread = await Posts.getThread(req.params.board, req.params.thread); |
||||
} catch (err) { |
||||
return next(err); |
||||
} |
||||
|
||||
//render the page
|
||||
res.render('thread', { |
||||
csrf: req.csrfToken(), |
||||
board: req.params.board, |
||||
threads: [thread] || [] |
||||
}); |
||||
|
||||
}); |
||||
|
||||
|
||||
module.exports = router; |
||||
|
@ -1,13 +0,0 @@ |
||||
'use strict'; |
||||
|
||||
const fs = require('fs') |
||||
, models = {}; |
||||
|
||||
fs.readdirSync(__dirname).forEach(file => { |
||||
if (file === 'index.js') { |
||||
return; |
||||
} |
||||
const name = file.substring(0,file.length-3); |
||||
const model = require(__dirname+'/'+file); |
||||
module.exports[name] = model; |
||||
}); |
@ -0,0 +1,20 @@ |
||||
extends ../layout.pug |
||||
|
||||
block head |
||||
title /#{board}/ |
||||
|
||||
block content |
||||
for thread in threads |
||||
h1 OP: |
||||
div #{thread._id} |
||||
div #{thread.author} |
||||
div #{thread.date} |
||||
div #{thread.content} |
||||
h1 Replies: |
||||
for post in thread.replies |
||||
div #{post._id} |
||||
div #{post.author} |
||||
div #{post.date} |
||||
div #{post.content} |
||||
br |
||||
hr |
Loading…
Reference in new issue