bigly-chat/form/settings.js
2024-10-28 04:54:58 -04:00

38 lines
No EOL
1 KiB
JavaScript

import Route from "../route.js";
import initDb from "../db.js";
import auth from "../form/auth.js";
import {exec} from 'node:child_process';
import { promisify } from "node:util";
import captcha from "./captcha.js";
const execP = promisify(exec);
let db = await initDb();
// TODO: rewrite
let main = new Route([auth,captcha], async function (req, res, input) {
let { captchaMatch} = input;
if (!captchaMatch) return { 'success': false, 'message': 'Captcha is incorrect' };
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;