diff --git a/routes/commenter.js b/routes/commenter.js
index 7a996ff..09c4d63 100644
--- a/routes/commenter.js
+++ b/routes/commenter.js
@@ -12,7 +12,7 @@ const maxChar = 2048;
router.post('/', async (req, res, next) => {
let { username } = res.auth;
- let { post, type, id } = req.body;
+ let { post, type, id, edit } = req.body;
if (!username) {
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}`;
}
+ 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 (?,?,?,?)', [
username,
(+new Date),
diff --git a/routes/user.js b/routes/user.js
index caa9e96..dbb5aab 100644
--- a/routes/user.js
+++ b/routes/user.js
@@ -1,13 +1,26 @@
import { Router } from "express";
+import { replyIterator } from "../lib.js";
+import { initDb } from "../db.js";
+let db = await initDb();
+
const router = Router();
//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.mainCtx = {
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();
})
diff --git a/views/replies.ejs b/views/replies.ejs
index a178bd7..c126f09 100644
--- a/views/replies.ejs
+++ b/views/replies.ejs
@@ -25,6 +25,12 @@
"name": "file",
"default": ""
},
+ {
+ "key": "Edit?",
+ "type": "checkbox",
+ "name": "edit",
+ "default": "edit"
+ },
{
"key": "",
"type": "hidden",
diff --git a/views/user.ejs b/views/user.ejs
index 7eb8c29..25f6671 100644
--- a/views/user.ejs
+++ b/views/user.ejs
@@ -3,7 +3,7 @@
<%= username %>
-