This repository was archived by the owner on Oct 10, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
61 lines (47 loc) · 2.34 KB
/
Copy pathmain.js
File metadata and controls
61 lines (47 loc) · 2.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// made by recanman
const {Router} = require("express")
const router = Router()
const {boards, boardList} = require("../helpers/getBoards").GetBoards()
const CheckBoard = require("../middlewares/checkBoard")
const CheckPage = require("../middlewares/checkPage")
const BoardsController = require("../controllers/boards")
router.get("/", (req, res) => res.render("index", {boards: boards}))
router.get("/search", (req, res) => res.render("search"))
router.post("/search", async (req, res, next) => {
const {query} = req.body
if (typeof(query) != "string") {return next("Query must be a string.")}
BoardsController.Search(query).then(result => {
res.render("search", {search: {count: result.nhits || 0, threads: result.threads, query}})
}).catch(err => next(err))
})
router.get("/:board_code/", CheckBoard, async (req, res, next) => {
const {board_code} = req.params
BoardsController.GetThreadsForBoard(board_code, 1).then(result => {
res.render("board", {board: boardList[board_code], current_page: 1, threads: result})
}).catch(err => next(err))
})
router.get("/:board_code/search", CheckBoard, (req, res) => {
const {board_code} = req.params
res.render("board_search", {board: boardList[board_code]})
})
router.post("/:board_code/search", CheckBoard, async (req, res, next) => {
const {board_code} = req.params
const {query} = req.body
if (typeof(query) != "string") {return next("Query must be a string.")}
BoardsController.Search(query, board_code).then(result => {
res.render("board_search", {board: boardList[board_code], search: {count: result.nhits || 0, threads: result.threads, query}})
}).catch(err => next(err))
})
router.get("/:board_code/:index", CheckBoard, CheckPage, async (req, res, next) => {
const {board_code, index} = req.params
BoardsController.GetThreadsForBoard(board_code, index).then(result => {
res.render("board", {board: boardList[board_code], current_page: index, threads: result})
}).catch(err => next(err))
})
router.get("/:board_code/thread/:thread_id", CheckBoard, async (req, res, next) => {
const {board_code, thread_id} = req.params
BoardsController.GetThreadForBoard(board_code, thread_id).then(result => {
res.render("thread", {board: boardList[board_code], posts: result})
}).catch(err => next(err))
})
module.exports = router