bios, crude post editing
This commit is contained in:
parent
ef68abe802
commit
091fba6910
4 changed files with 32 additions and 4 deletions
|
@ -12,7 +12,7 @@ const maxChar = 2048;
|
||||||
|
|
||||||
router.post('/', async (req, res, next) => {
|
router.post('/', async (req, res, next) => {
|
||||||
let { username } = res.auth;
|
let { username } = res.auth;
|
||||||
let { post, type, id } = req.body;
|
let { post, type, id, edit } = req.body;
|
||||||
|
|
||||||
if (!username) {
|
if (!username) {
|
||||||
apiStat(res, next, 'Log in to chat with the community.')
|
apiStat(res, next, 'Log in to chat with the community.')
|
||||||
|
@ -34,6 +34,15 @@ router.post('/', async (req, res, next) => {
|
||||||
post += `\nfile::${req.file.path}`;
|
post += `\nfile::${req.file.path}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (edit == 'edit') {
|
||||||
|
await db.run('UPDATE comment SET content = ? WHERE username = ? AND id = ?', [
|
||||||
|
post,
|
||||||
|
username,
|
||||||
|
id
|
||||||
|
]);
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
await db.run('INSERT INTO comment (username, date, content, id) VALUES (?,?,?,?)', [
|
await db.run('INSERT INTO comment (username, date, content, id) VALUES (?,?,?,?)', [
|
||||||
username,
|
username,
|
||||||
(+new Date),
|
(+new Date),
|
||||||
|
|
|
@ -1,13 +1,26 @@
|
||||||
import { Router } from "express";
|
import { Router } from "express";
|
||||||
|
import { replyIterator } from "../lib.js";
|
||||||
|
import { initDb } from "../db.js";
|
||||||
|
let db = await initDb();
|
||||||
|
|
||||||
const router = Router();
|
const router = Router();
|
||||||
|
|
||||||
//todo: fix jank
|
//todo: fix jank
|
||||||
|
|
||||||
router.get('/:username', (req, res, next) => {
|
router.get('/:username', async (req, res, next) => {
|
||||||
|
let topComment = await db.all('SELECT * FROM feeder WHERE parentType = ? AND parentId = ? ORDER BY sortId ASC LIMIT ? OFFSET ?', [
|
||||||
|
'users',
|
||||||
|
req.params.username,
|
||||||
|
1,
|
||||||
|
0
|
||||||
|
]);
|
||||||
|
topComment = await replyIterator(topComment,db);
|
||||||
|
|
||||||
res.ctx.mainPage = 'user'
|
res.ctx.mainPage = 'user'
|
||||||
res.ctx.mainCtx = {
|
res.ctx.mainCtx = {
|
||||||
username: req.params.username,
|
username: req.params.username,
|
||||||
isYou: res.auth && req.params.username == res.auth.username
|
isYou: res.auth && req.params.username == res.auth.username,
|
||||||
|
desc: topComment[0] ? topComment[0].comment.content : false
|
||||||
}
|
}
|
||||||
next();
|
next();
|
||||||
})
|
})
|
||||||
|
|
|
@ -25,6 +25,12 @@
|
||||||
"name": "file",
|
"name": "file",
|
||||||
"default": ""
|
"default": ""
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"key": "Edit?",
|
||||||
|
"type": "checkbox",
|
||||||
|
"name": "edit",
|
||||||
|
"default": "edit"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"key": "",
|
"key": "",
|
||||||
"type": "hidden",
|
"type": "hidden",
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
<img src="/uploads/pfp_<%= username %>.png" class="avatar-img">
|
<img src="/uploads/pfp_<%= username %>.png" class="avatar-img">
|
||||||
<span><%= username %></span>
|
<span><%= username %></span>
|
||||||
</h1>
|
</h1>
|
||||||
<div class='commentbox'>A very cool person!</div>
|
<div class='commentbox'><%= desc || "A very cool person!" %></div>
|
||||||
<%- include ('vblock.ejs', {link: `/walls/get/users/${username}/0`, icon: '/icon.svg', name: 'Replies'}) %>
|
<%- include ('vblock.ejs', {link: `/walls/get/users/${username}/0`, icon: '/icon.svg', name: 'Replies'}) %>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue