prototype of comments

This commit is contained in:
biglyderv 2025-02-26 01:10:09 -05:00
parent 9cdf2326b8
commit 11147482d2
Signed by: biglyderv
GPG key ID: 0E2EB0B4CD7397B5
11 changed files with 216 additions and 5 deletions

43
routes/comment.js Normal file
View file

@ -0,0 +1,43 @@
import { Router } from "express";
import { initDb } from "../db.js";
const router = Router();
let db = await initDb();
//todo: fix jank
router.get('/:id', async (req, res, next) => {
let replies = [{parentType: 'comment', parentId: req.params.id}];
let feeder = req.params.id;
while (true) {
let tmpReplies = await db.all('SELECT * FROM feeder WHERE childType = ? AND childId = ?', [
'comment',
feeder,
]);
if (tmpReplies.length == 0) break;
feeder = tmpReplies[0].parentId
replies.splice(0,0,tmpReplies[0])
}
for (let reply of replies) {
let dat = await db.all('SELECT * FROM comment WHERE id = ?', [
reply.parentId
]);
if (reply.parentType != 'comment' || dat.length < 1) {
reply.comment = {username: 'fail', date: 'fail', content: 'fail'};
continue;
}
reply.comment = dat[0];
}
res.ctx.mainPage = 'commenter'
res.ctx.mainCtx = {
replies,
opLink: `/comments/${req.params.id}`
}
next();
})
export default router;