derv-net/routes/walls.js

67 lines
1.7 KiB
JavaScript
Raw Normal View History

2025-02-26 01:10:09 -05:00
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) {
let dat = await db.all('SELECT * FROM comment WHERE id = ?', [
reply.childId
]);
2025-02-26 01:40:27 -05:00
if (reply.childType != 'comment' || dat.length < 1) {
reply.comment = 'fail';
continue;
}
2025-02-26 01:10:09 -05:00
reply.comment = dat[0];
2025-02-26 01:40:27 -05:00
reply.comment.type = reply.childType;
reply.comment.id = reply.childId;
2025-02-26 01:10:09 -05:00
}
2025-02-26 01:40:27 -05:00
replies = replies.filter(x => x.comment != 'fail');
2025-02-26 01:10:09 -05:00
res.ctx.mainPage = 'replies'
res.ctx.mainCtx = {
page: req.params.num,
replies,
2025-02-26 01:40:27 -05:00
opLink: `/${req.params.type}/${req.params.id}`,
type: req.params.type,
id: req.params.id
2025-02-26 01:10:09 -05:00
}
next();
})
export default router;