This commit is contained in:
biglyderv 2024-11-25 14:12:44 -05:00
parent 77f21692cf
commit 4273369736
20 changed files with 56 additions and 53 deletions

View file

@ -5,14 +5,13 @@ import auth from "../form/auth.js";
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
return { 'success': false, 'message': 'Some fields are missing' };
if (content.length > 8192)
return { 'success': false, 'message': 'Comment is too long' };

View file

@ -4,19 +4,18 @@ import auth from "../form/auth.js";
let db = await initDb();
// TODO: rewrite
let main = new Route([auth], async function (req, res, input) {
let { username } = input;
let { target } = req.body;
if (!target ) return { 'success': false, 'message': 'Some fields are missing' }; // probably should not re-use these strings
if (!target) return { 'success': false, 'message': 'Some fields are missing' };
await db.run('DELETE FROM video WHERE id = ? AND username = ?', [
target,
username
]);
return { 'message': 'Video deleted', 'success': true};
return { 'message': 'Video deleted', 'success': true };
});
export default main;

View file

@ -1,20 +1,18 @@
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
return { 'success': false, 'message': 'Some fields are missing' };
let isFollowing = await db.all('SELECT * FROM follow WHERE username = ? AND target = ?', [
username,
@ -26,13 +24,13 @@ let main = new Route([auth], async function (req, res, input) {
username,
target
]);
res.send({'success': true, 'message': 'User unfollowed'});
res.send({ 'success': true, 'message': 'User unfollowed' });
} else {
await db.run('INSERT INTO follow (username,target) VALUES (?,?)', [
username,
target
]);
res.send({'success': true, 'message': 'User followed'});
res.send({ 'success': true, 'message': 'User followed' });
}
});

View file

@ -1,4 +1,3 @@
// from an old project: https://git.zenoverse.net/bigly-archive/auth-thing/raw/branch/main/src/routes/login/+page.server.js
import Route from "../route.js";
import initDb from "../db.js";
import { compare } from "bcrypt";
@ -7,10 +6,9 @@ import captcha from "./captcha.js";
let db = await initDb();
// TODO: rewrite
let main = new Route([captcha], async function (req, res, input) {
let { user, pass } = req.body;
let { captchaMatch} = input;
let { captchaMatch } = input;
if (!captchaMatch) return { 'success': false, 'message': 'Captcha is incorrect' };

View file

@ -1,4 +1,3 @@
// from an old project: https://git.zenoverse.net/bigly-archive/auth-thing/raw/branch/main/src/routes/register/+page.server.js
import Route from "../route.js";
import initDb from "../db.js";
import { hash } from "bcrypt";
@ -13,10 +12,9 @@ function isValid(user) {
return user.search(/[^A-Za-z0-9\-\_]/g) == -1;
}
// TODO: rewrite
let main = new Route([captcha], async function (req, res, input) {
let { user, pass, pass2 } = req.body;
let { captchaMatch} = input;
let { captchaMatch } = input;
if (!captchaMatch) return { 'success': false, 'message': 'Captcha is incorrect' };

View file

@ -1,7 +1,7 @@
import Route from "../route.js";
import initDb from "../db.js";
import auth from "../form/auth.js";
import {exec} from 'node:child_process';
import { exec } from 'node:child_process';
import { promisify } from "node:util";
import captcha from "./captcha.js";
@ -9,9 +9,8 @@ const execP = promisify(exec);
let db = await initDb();
// TODO: rewrite
let main = new Route([auth,captcha], async function (req, res, input) {
let { captchaMatch} = input;
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;

View file

@ -1,7 +1,7 @@
import Route from "../route.js";
import initDb from "../db.js";
import { randomUUID } from 'node:crypto';
import {exec} from 'node:child_process';
import { exec } from 'node:child_process';
import { promisify } from "node:util";
import auth from "../form/auth.js";
import captcha from "./captcha.js";
@ -10,24 +10,23 @@ const execP = promisify(exec);
let db = await initDb();
// TODO: rewrite
let main = new Route([auth,captcha], async function (req, res, input) {
let { captchaMatch} = input;
let main = new Route([auth, captcha], async function (req, res, input) {
let { captchaMatch } = input;
if (!captchaMatch) return { 'success': false, 'message': 'Captcha is incorrect' };
let { username } = input;
let id = randomUUID();
let { title, desc } = req.body;
if (!title || !desc || !req.file || username == '!nobody') 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' };
let {path} = req.file;
let { path } = req.file;
try {
await execP(`ffmpeg -i ${path} videos/${id}.webm`);
await execP(`ffmpeg -i videos/${id}.webm -frames:v 1 videos/${id}.png`);
} catch (err) {
return { 'success': false, 'message': 'Video is invalid'}
return { 'success': false, 'message': 'Video is invalid' }
}
await db.run('INSERT INTO video (id, title, desc, username, date) VALUES (?, ?, ?, ?, ?)', [
@ -38,7 +37,7 @@ let main = new Route([auth,captcha], async function (req, res, input) {
+new Date()
]);
return { 'message': 'Video created', 'success': true, 'redirect': '/client/video?id='+id };
return { 'message': 'Video created', 'success': true, 'redirect': '/client/video?id=' + id };
});
export default main;