add comments
This commit is contained in:
parent
e8cc01e66f
commit
59c1daeac5
11 changed files with 94 additions and 11 deletions
33
form/comment.js
Normal file
33
form/comment.js
Normal file
|
@ -0,0 +1,33 @@
|
|||
import Route from "../route.js";
|
||||
import initDb from "../db.js";
|
||||
import { randomUUID } from 'node:crypto';
|
||||
import { exec } from 'node:child_process';
|
||||
import { promisify } from "node:util";
|
||||
import auth from "../form/auth.js";
|
||||
|
||||
const execP = promisify(exec);
|
||||
|
||||
let db = await initDb();
|
||||
|
||||
// TODO: rewrite
|
||||
let main = new Route([auth], async function (req, res, input) {
|
||||
let { username } = input;
|
||||
let id = randomUUID();
|
||||
|
||||
let { targetType, targetId, content } = req.body;
|
||||
if (!targetType || !targetId || !content || username == '!nobody')
|
||||
return { 'success': false, 'message': 'Some fields are missing' }; // probably should not re-use these strings
|
||||
|
||||
await db.run('INSERT INTO comment (username, targetType, targetId, date, content, id) VALUES (?,?,?,?,?,?)', [
|
||||
username,
|
||||
targetType,
|
||||
targetId,
|
||||
+new Date(),
|
||||
content,
|
||||
id
|
||||
]);
|
||||
|
||||
res.send({ redir: `?` });
|
||||
});
|
||||
|
||||
export default main;
|
|
@ -15,7 +15,7 @@ let main = new Route([auth], async function (req, res, input) {
|
|||
let id = randomUUID();
|
||||
|
||||
let { title, desc } = req.body;
|
||||
if (!title || !desc || !req.file) return { 'success': false, 'message': 'Some fields are missing' }; // probably should not re-use these strings
|
||||
if (!title || !desc || !req.file || username == '!nobody') return { 'success': false, 'message': 'Some fields are missing' }; // probably should not re-use these strings
|
||||
|
||||
let {path} = req.file;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue