2025-02-26 01:10:09 -05:00
|
|
|
import { Router } from "express";
|
|
|
|
import { initDb } from "../db.js";
|
2025-02-26 19:50:37 -05:00
|
|
|
import { replyIterator } from "../lib.js";
|
2025-02-26 01:10:09 -05:00
|
|
|
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',
|
2025-03-08 15:57:30 -05:00
|
|
|
'desc': 'Discuss anything you desire'
|
2025-02-26 01:10:09 -05:00
|
|
|
},
|
|
|
|
{
|
|
|
|
'alias': `users/${res.auth.username}`,
|
|
|
|
'name': 'You',
|
2025-03-08 15:57:30 -05:00
|
|
|
'desc': 'Connect with your community'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
'alias': `hub/nilgrinder`,
|
|
|
|
'name': 'Nilgrinder',
|
|
|
|
'desc': 'Idle game: build to everything from nothing'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
'alias': `hub/minecraft`,
|
|
|
|
'name': 'Minecraft',
|
|
|
|
'desc': 'Experimental Minecraft server'
|
2025-02-26 01:10:09 -05:00
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
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
|
|
|
|
]);
|
|
|
|
|
2025-02-26 13:54:25 -05:00
|
|
|
replies.splice(0, 0, {
|
2025-02-26 16:37:48 -05:00
|
|
|
childType: req.params.type,
|
2025-02-26 13:54:25 -05:00
|
|
|
childId: req.params.id
|
|
|
|
})
|
|
|
|
|
2025-02-26 19:50:37 -05:00
|
|
|
replies = await replyIterator(replies,db);
|
2025-02-26 01:10:09 -05:00
|
|
|
|
2025-02-26 13:54:25 -05:00
|
|
|
let comment = replies.splice(0, 1)[0];
|
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,
|
2025-02-26 13:54:25 -05:00
|
|
|
id: req.params.id,
|
|
|
|
|
|
|
|
comment
|
2025-02-26 01:10:09 -05:00
|
|
|
}
|
|
|
|
next();
|
|
|
|
})
|
|
|
|
|
|
|
|
export default router;
|