add following and ui updates

This commit is contained in:
biglyderv 2024-11-25 14:12:43 -05:00
parent 95fde911c5
commit 7bec5f61f0
8 changed files with 75 additions and 23 deletions

View file

@ -1,12 +1,8 @@
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

40
form/follow.js Normal file
View file

@ -0,0 +1,40 @@
import Route from "../route.js";
import initDb from "../db.js";
import { randomUUID } from 'node:crypto';
import auth from "../form/auth.js";
let db = await initDb();
function isValid(user) {
return user.search(/[^A-Za-z0-9\-\_]/g) == -1;
}
// TODO: rewrite
let main = new Route([auth], async function (req, res, input) {
let { username } = input;
let id = randomUUID();
let { target } = req.body;
if (!isValid(target) || username == '!nobody')
return { 'success': false, 'message': 'Some fields are missing' }; // probably should not re-use these strings
let isFollowing = await db.all('SELECT * FROM follow WHERE username = ? AND target = ?', [
username,
target
]);
if (isFollowing.length > 0) {
await db.run('DELETE FROM follow WHERE username = ? AND target = ?', [
username,
target
]);
} else {
await db.run('INSERT INTO follow (username,target) VALUES (?,?)', [
username,
target
]);
}
res.send({ redir: `?` });
});
export default main;