prototype of comments
This commit is contained in:
parent
9cdf2326b8
commit
11147482d2
11 changed files with 216 additions and 5 deletions
57
routes/walls.js
Normal file
57
routes/walls.js
Normal file
|
@ -0,0 +1,57 @@
|
|||
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;
|
Loading…
Add table
Add a link
Reference in a new issue