57 lines
1.4 KiB
JavaScript
57 lines
1.4 KiB
JavaScript
|
import { Router } from "express";
|
||
|
import { initDb } from "../db.js";
|
||
|
const router = Router();
|
||
|
let db = await initDb();
|
||
|
|
||
|
//todo: fix jank
|
||
|
|
||
|
router.get('/list', (req, res, next) => {
|
||
|
res.ctx.mainPage = 'walls'
|
||
|
res.ctx.mainCtx = {
|
||
|
walls: [
|
||
|
{
|
||
|
'alias': 'hub/main',
|
||
|
'name': 'Home',
|
||
|
'desc': 'Discuss anything you desire.'
|
||
|
},
|
||
|
{
|
||
|
'alias': `users/${res.auth.username}`,
|
||
|
'name': 'You',
|
||
|
'desc': 'Connect with your fanbase.'
|
||
|
}
|
||
|
]
|
||
|
}
|
||
|
next();
|
||
|
})
|
||
|
|
||
|
router.get('/get/:type/:id/:num', async (req, res, next) => {
|
||
|
if (isNaN(req.params.num * 1)) {
|
||
|
next();
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
let replies = await db.all('SELECT * FROM feeder WHERE parentType = ? AND parentId = ? ORDER BY sortId DESC LIMIT ? OFFSET ?', [
|
||
|
req.params.type,
|
||
|
req.params.id,
|
||
|
10,
|
||
|
req.params.num * 10
|
||
|
]);
|
||
|
|
||
|
for (let reply of replies) {
|
||
|
if (reply.childType != 'comment') continue;
|
||
|
let dat = await db.all('SELECT * FROM comment WHERE id = ?', [
|
||
|
reply.childId
|
||
|
]);
|
||
|
reply.comment = dat[0];
|
||
|
}
|
||
|
|
||
|
res.ctx.mainPage = 'replies'
|
||
|
res.ctx.mainCtx = {
|
||
|
page: req.params.num,
|
||
|
replies,
|
||
|
opLink: `/${req.params.type}/${req.params.id}`
|
||
|
}
|
||
|
next();
|
||
|
})
|
||
|
|
||
|
export default router;
|