prototype of comments
This commit is contained in:
parent
9cdf2326b8
commit
11147482d2
11 changed files with 216 additions and 5 deletions
43
routes/comment.js
Normal file
43
routes/comment.js
Normal 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;
|
72
routes/hub.js
Normal file
72
routes/hub.js
Normal file
|
@ -0,0 +1,72 @@
|
|||
import { Router } from "express";
|
||||
const router = Router();
|
||||
|
||||
//todo: fix jank
|
||||
|
||||
router.get('/login', (req, res, next) => {
|
||||
res.ctx.mainPage = 'hub'
|
||||
res.ctx.mainCtx = {
|
||||
title: "Log in",
|
||||
message: 'Log into an existing account.',
|
||||
action: "/api/form/you/login",
|
||||
inputs: [
|
||||
{
|
||||
"key": "Username",
|
||||
"type": "text",
|
||||
"name": "user",
|
||||
"default": ""
|
||||
},
|
||||
{
|
||||
"key": "Password",
|
||||
"type": "password",
|
||||
"name": "pass",
|
||||
"default": ""
|
||||
}
|
||||
]
|
||||
}
|
||||
next();
|
||||
})
|
||||
|
||||
router.get('/logout', (req, res, next) => {
|
||||
res.ctx.mainPage = 'form'
|
||||
res.ctx.mainCtx = {
|
||||
title: "Log out",
|
||||
message: 'Are you sure?',
|
||||
action: "/api/form/you/logout",
|
||||
inputs: []
|
||||
}
|
||||
next();
|
||||
})
|
||||
|
||||
|
||||
router.get('/new', (req, res, next) => {
|
||||
res.ctx.mainPage = 'form'
|
||||
res.ctx.mainCtx = {
|
||||
title: "Register",
|
||||
message: 'Create an account and join the community!',
|
||||
action: "/api/form/you/new",
|
||||
inputs: [
|
||||
{
|
||||
"key": "Username",
|
||||
"type": "text",
|
||||
"name": "user",
|
||||
"default": ""
|
||||
},
|
||||
{
|
||||
"key": "Password",
|
||||
"type": "password",
|
||||
"name": "pass",
|
||||
"default": ""
|
||||
},
|
||||
{
|
||||
"key": "Password (again)",
|
||||
"type": "password",
|
||||
"name": "pass2",
|
||||
"default": ""
|
||||
}
|
||||
]
|
||||
}
|
||||
next();
|
||||
})
|
||||
|
||||
export default router;
|
|
@ -8,12 +8,14 @@ let db = await initDb();
|
|||
const upload = multer({ dest: 'uploads/' });
|
||||
|
||||
const aliases = {
|
||||
'/': '/walls/get/home'
|
||||
'/': '/walls/get/hub/main/0'
|
||||
};
|
||||
|
||||
const routers = {
|
||||
'/you': './routes/you.js',
|
||||
'/api/form/you': './routes/youApi.js'
|
||||
'/api/form/you': './routes/youApi.js',
|
||||
'/walls': './routes/walls.js',
|
||||
'/comments': './routes/comment.js'
|
||||
}
|
||||
|
||||
function doAliases(app) {
|
||||
|
|
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