bigly-chat/form/settings.js

37 lines
1 KiB
JavaScript
Raw Normal View History

2024-11-25 14:12:44 -05:00
import Route from "../route.js";
import initDb from "../db.js";
import auth from "../form/auth.js";
2024-11-25 14:12:44 -05:00
import { exec } from 'node:child_process';
2024-11-25 14:12:44 -05:00
import { promisify } from "node:util";
2024-11-25 14:12:44 -05:00
import captcha from "./captcha.js";
2024-11-25 14:12:44 -05:00
const execP = promisify(exec);
let db = await initDb();
2024-11-25 14:12:44 -05:00
let main = new Route([auth, captcha], async function (req, res, input) {
let { captchaMatch } = input;
2024-11-25 14:12:44 -05:00
if (!captchaMatch) return { 'success': false, 'message': 'Captcha is incorrect' };
2024-11-25 14:12:44 -05:00
let { path } = req.file;
let { username } = input;
let { desc } = req.body;
if (username == '!nobody' || !desc || !req.file) return { 'success': false, 'message': 'Some fields are missing' };
await execP(`magick ${path} pfp/${username}.png`);
await db.run('DELETE FROM user WHERE username = ?', [
username,
]);
await db.run('INSERT INTO user (username,bio) VALUES (?,?)', [
username,
desc
]);
res.send({ 'success': true, 'message': 'Metadata updated', redir: `/user?id=${username}` });
});
export default main;