bigly-chat/form/settings.js
2024-11-25 14:12:44 -05:00

34 lines
No EOL
901 B
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";
const execP = promisify(exec);
let db = await initDb();
// TODO: rewrite
let main = new Route([auth], async function (req, res, input) {
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;