cleanup
This commit is contained in:
parent
77f21692cf
commit
4273369736
20 changed files with 56 additions and 53 deletions
|
@ -7,7 +7,6 @@ import crypto from "node:crypto";
|
||||||
|
|
||||||
let db = await initDb();
|
let db = await initDb();
|
||||||
|
|
||||||
// TODO: rewrite
|
|
||||||
let main = new Route([], async function (req, res, input) {
|
let main = new Route([], async function (req, res, input) {
|
||||||
const canvas = new Canvas.Canvas(250, 100)
|
const canvas = new Canvas.Canvas(250, 100)
|
||||||
const ctx = canvas.getContext('2d')
|
const ctx = canvas.getContext('2d')
|
||||||
|
@ -47,6 +46,7 @@ let main = new Route([], async function (req, res, input) {
|
||||||
res.header('Cache-Control', 'no-cache, private, no-store, must-revalidate, max-stale=0, post-check=0, pre-check=0')
|
res.header('Cache-Control', 'no-cache, private, no-store, must-revalidate, max-stale=0, post-check=0, pre-check=0')
|
||||||
res.header('Expires', 'Sun, 19 May 1984 02:00:00 GMT')
|
res.header('Expires', 'Sun, 19 May 1984 02:00:00 GMT')
|
||||||
canvas.jpegStream().pipe(res)
|
canvas.jpegStream().pipe(res)
|
||||||
|
return true;
|
||||||
});
|
});
|
||||||
|
|
||||||
export default main;
|
export default main;
|
|
@ -2,9 +2,10 @@ import Route from "../route.js";
|
||||||
import auth from "../form/auth.js";
|
import auth from "../form/auth.js";
|
||||||
|
|
||||||
let main = new Route([auth], async function (req, res, input) {
|
let main = new Route([auth], async function (req, res, input) {
|
||||||
return res.render('404', {
|
res.render('404', {
|
||||||
...input
|
...input
|
||||||
});
|
});
|
||||||
|
return true;
|
||||||
});
|
});
|
||||||
|
|
||||||
export default main;
|
export default main;
|
|
@ -3,7 +3,7 @@ import auth from "../form/auth.js";
|
||||||
|
|
||||||
// TODO: rewrite
|
// TODO: rewrite
|
||||||
let main = new Route([auth], async function (req, res, input) {
|
let main = new Route([auth], async function (req, res, input) {
|
||||||
return res.render('form', {
|
res.render('form', {
|
||||||
data: [
|
data: [
|
||||||
{ label: "Username", type: "text", name: "user" },
|
{ label: "Username", type: "text", name: "user" },
|
||||||
{ label: "Password", type: "password", name: "pass" },
|
{ label: "Password", type: "password", name: "pass" },
|
||||||
|
@ -12,6 +12,7 @@ let main = new Route([auth], async function (req, res, input) {
|
||||||
'title': 'Login',
|
'title': 'Login',
|
||||||
...input
|
...input
|
||||||
});
|
});
|
||||||
|
return true;
|
||||||
});
|
});
|
||||||
|
|
||||||
export default main;
|
export default main;
|
|
@ -11,11 +11,12 @@ let main = new Route([auth], async function (req, res, input) {
|
||||||
let videosFollow = await db.all('SELECT * FROM video WHERE username IN (SELECT target FROM follow WHERE username = ?) ORDER BY date DESC LIMIT 20', [
|
let videosFollow = await db.all('SELECT * FROM video WHERE username IN (SELECT target FROM follow WHERE username = ?) ORDER BY date DESC LIMIT 20', [
|
||||||
username
|
username
|
||||||
]);
|
]);
|
||||||
return res.render('main', {
|
res.render('main', {
|
||||||
...input,
|
...input,
|
||||||
videos,
|
videos,
|
||||||
videosFollow
|
videosFollow
|
||||||
});
|
});
|
||||||
|
return true;
|
||||||
});
|
});
|
||||||
|
|
||||||
export default main;
|
export default main;
|
|
@ -16,10 +16,11 @@ let main = new Route([auth], async function (req, res, input) {
|
||||||
username
|
username
|
||||||
]);
|
]);
|
||||||
|
|
||||||
return res.render('messages', {
|
res.render('messages', {
|
||||||
...input,
|
...input,
|
||||||
msgs
|
msgs
|
||||||
});
|
});
|
||||||
|
return true;
|
||||||
});
|
});
|
||||||
|
|
||||||
export default main;
|
export default main;
|
|
@ -10,11 +10,12 @@ let main = new Route([comment], async function (req, res, input) {
|
||||||
]);
|
]);
|
||||||
if (videoData.length == 0) return;
|
if (videoData.length == 0) return;
|
||||||
videoData = videoData[0];
|
videoData = videoData[0];
|
||||||
return res.render('player', {
|
res.render('player', {
|
||||||
...input,
|
...input,
|
||||||
videoData,
|
videoData,
|
||||||
ogType: 'video'
|
ogType: 'video'
|
||||||
});
|
});
|
||||||
|
return true;
|
||||||
});
|
});
|
||||||
|
|
||||||
export default main;
|
export default main;
|
|
@ -3,7 +3,7 @@ import auth from "../form/auth.js";
|
||||||
|
|
||||||
// TODO: rewrite
|
// TODO: rewrite
|
||||||
let main = new Route([auth], async function (req, res, input) {
|
let main = new Route([auth], async function (req, res, input) {
|
||||||
return res.render('form', {
|
res.render('form', {
|
||||||
data: [
|
data: [
|
||||||
{ label: "Username", type: "text", name: "user" },
|
{ label: "Username", type: "text", name: "user" },
|
||||||
{ label: "Password", type: "password", name: "pass" },
|
{ label: "Password", type: "password", name: "pass" },
|
||||||
|
@ -13,6 +13,7 @@ let main = new Route([auth], async function (req, res, input) {
|
||||||
'title': 'Join',
|
'title': 'Join',
|
||||||
...input
|
...input
|
||||||
});
|
});
|
||||||
|
return true;
|
||||||
});
|
});
|
||||||
|
|
||||||
export default main;
|
export default main;
|
|
@ -3,7 +3,7 @@ import auth from "../form/auth.js";
|
||||||
|
|
||||||
// TODO: rewrite
|
// TODO: rewrite
|
||||||
let main = new Route([auth], async function (req, res, input) {
|
let main = new Route([auth], async function (req, res, input) {
|
||||||
return res.render('form', {
|
res.render('form', {
|
||||||
data: [
|
data: [
|
||||||
{ label: "Description", type: "textarea", name: "desc" },
|
{ label: "Description", type: "textarea", name: "desc" },
|
||||||
{ label: "Avatar", type: "file", name: "file" }
|
{ label: "Avatar", type: "file", name: "file" }
|
||||||
|
@ -11,7 +11,8 @@ let main = new Route([auth], async function (req, res, input) {
|
||||||
'route': '/api/upload/settings',
|
'route': '/api/upload/settings',
|
||||||
'title': 'User Settings',
|
'title': 'User Settings',
|
||||||
...input
|
...input
|
||||||
}); /* todo: form in not a file */
|
});
|
||||||
|
return true;
|
||||||
});
|
});
|
||||||
|
|
||||||
export default main;
|
export default main;
|
|
@ -2,9 +2,10 @@ import Route from "../route.js";
|
||||||
import auth from "../form/auth.js";
|
import auth from "../form/auth.js";
|
||||||
|
|
||||||
let main = new Route([auth], async function (req, res, input) {
|
let main = new Route([auth], async function (req, res, input) {
|
||||||
return res.render('guidelines', {
|
res.render('guidelines', {
|
||||||
...input
|
...input
|
||||||
});
|
});
|
||||||
|
return true;
|
||||||
});
|
});
|
||||||
|
|
||||||
export default main;
|
export default main;
|
|
@ -3,7 +3,7 @@ import auth from "../form/auth.js";
|
||||||
|
|
||||||
// TODO: rewrite
|
// TODO: rewrite
|
||||||
let main = new Route([auth], async function (req, res, input) {
|
let main = new Route([auth], async function (req, res, input) {
|
||||||
return res.render('form', {
|
res.render('form', {
|
||||||
data: [
|
data: [
|
||||||
{ label: "Video file", type: "file", name: "file" },
|
{ label: "Video file", type: "file", name: "file" },
|
||||||
{ label: "Name", type: "text", name: "title" },
|
{ label: "Name", type: "text", name: "title" },
|
||||||
|
@ -13,6 +13,7 @@ let main = new Route([auth], async function (req, res, input) {
|
||||||
'title': 'Upload Content',
|
'title': 'Upload Content',
|
||||||
...input
|
...input
|
||||||
});
|
});
|
||||||
|
return true;
|
||||||
});
|
});
|
||||||
|
|
||||||
export default main;
|
export default main;
|
|
@ -22,7 +22,7 @@ let main = new Route([comment], async function (req, res, input) {
|
||||||
req.query.id
|
req.query.id
|
||||||
]);
|
]);
|
||||||
|
|
||||||
return res.render('user', {
|
res.render('user', {
|
||||||
...input,
|
...input,
|
||||||
id,
|
id,
|
||||||
videos,
|
videos,
|
||||||
|
@ -31,6 +31,7 @@ let main = new Route([comment], async function (req, res, input) {
|
||||||
user,
|
user,
|
||||||
icon: `${process.env.URL}/pfp/${id}.png`
|
icon: `${process.env.URL}/pfp/${id}.png`
|
||||||
});
|
});
|
||||||
|
return true;
|
||||||
});
|
});
|
||||||
|
|
||||||
export default main;
|
export default main;
|
24
db.js
24
db.js
|
@ -3,6 +3,15 @@ import { open } from 'sqlite'
|
||||||
|
|
||||||
let db;
|
let db;
|
||||||
|
|
||||||
|
const sql = `CREATE TABLE IF NOT EXISTS auth (username TEXT, password TEXT);
|
||||||
|
CREATE TABLE IF NOT EXISTS token (username TEXT, token TEXT);
|
||||||
|
CREATE TABLE IF NOT EXISTS video (id TEXT, title TEXT, desc TEXT, username TEXT, date REAL);
|
||||||
|
CREATE TABLE IF NOT EXISTS comment (username TEXT, targetType TEXT, targetId TEXT, date REAL, content TEXT, id TEXT);
|
||||||
|
CREATE TABLE IF NOT EXISTS follow (username TEXT, target TEXT);
|
||||||
|
CREATE TABLE IF NOT EXISTS user (username TEXT, bio TEXT);
|
||||||
|
CREATE TABLE IF NOT EXISTS captcha (key TEXT, solution TEXT);
|
||||||
|
CREATE TABLE IF NOT EXISTS message (username TEXT, targetType TEXT, targetId TEXT, date REAL, content TEXT, read TEXT);`
|
||||||
|
|
||||||
async function initDb() {
|
async function initDb() {
|
||||||
if (db) return db;
|
if (db) return db;
|
||||||
|
|
||||||
|
@ -11,18 +20,11 @@ async function initDb() {
|
||||||
driver: sqlite3.Database
|
driver: sqlite3.Database
|
||||||
});
|
});
|
||||||
|
|
||||||
await db.run(`CREATE TABLE IF NOT EXISTS auth (username TEXT, password TEXT);`);
|
let sqlCmds = sql.split('\n');
|
||||||
await db.run(`CREATE TABLE IF NOT EXISTS token (username TEXT, token TEXT);`);
|
|
||||||
|
|
||||||
await db.run(`CREATE TABLE IF NOT EXISTS video (id TEXT, title TEXT, desc TEXT, username TEXT, date REAL);`);
|
for (let cmd of sqlCmds) {
|
||||||
await db.run('CREATE TABLE IF NOT EXISTS comment (username TEXT, targetType TEXT, targetId TEXT, date REAL, content TEXT, id TEXT);');
|
await db.run(cmd);
|
||||||
|
}
|
||||||
await db.run('CREATE TABLE IF NOT EXISTS follow (username TEXT, target TEXT);');
|
|
||||||
|
|
||||||
await db.run(`CREATE TABLE IF NOT EXISTS user (username TEXT, bio TEXT);`);
|
|
||||||
await db.run(`CREATE TABLE IF NOT EXISTS captcha (key TEXT, solution TEXT);`);
|
|
||||||
|
|
||||||
await db.run(`CREATE TABLE IF NOT EXISTS message (username TEXT, targetType TEXT, targetId TEXT, date REAL, content TEXT, read TEXT);`);
|
|
||||||
|
|
||||||
return db;
|
return db;
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,14 +5,13 @@ import auth from "../form/auth.js";
|
||||||
|
|
||||||
let db = await initDb();
|
let db = await initDb();
|
||||||
|
|
||||||
// TODO: rewrite
|
|
||||||
let main = new Route([auth], async function (req, res, input) {
|
let main = new Route([auth], async function (req, res, input) {
|
||||||
let { username } = input;
|
let { username } = input;
|
||||||
let id = randomUUID();
|
let id = randomUUID();
|
||||||
|
|
||||||
let { targetType, targetId, content } = req.body;
|
let { targetType, targetId, content } = req.body;
|
||||||
if (!targetType || !targetId || !content || username == '!nobody')
|
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)
|
if (content.length > 8192)
|
||||||
return { 'success': false, 'message': 'Comment is too long' };
|
return { 'success': false, 'message': 'Comment is too long' };
|
||||||
|
|
|
@ -4,12 +4,11 @@ import auth from "../form/auth.js";
|
||||||
|
|
||||||
let db = await initDb();
|
let db = await initDb();
|
||||||
|
|
||||||
// TODO: rewrite
|
|
||||||
let main = new Route([auth], async function (req, res, input) {
|
let main = new Route([auth], async function (req, res, input) {
|
||||||
let { username } = input;
|
let { username } = input;
|
||||||
|
|
||||||
let { target } = req.body;
|
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 = ?', [
|
await db.run('DELETE FROM video WHERE id = ? AND username = ?', [
|
||||||
target,
|
target,
|
||||||
|
|
|
@ -1,20 +1,18 @@
|
||||||
import Route from "../route.js";
|
import Route from "../route.js";
|
||||||
import initDb from "../db.js";
|
import initDb from "../db.js";
|
||||||
import { randomUUID } from 'node:crypto';
|
|
||||||
import auth from "../form/auth.js";
|
import auth from "../form/auth.js";
|
||||||
|
|
||||||
let db = await initDb();
|
let db = await initDb();
|
||||||
function isValid(user) {
|
function isValid(user) {
|
||||||
return user.search(/[^A-Za-z0-9\-\_]/g) == -1;
|
return user.search(/[^A-Za-z0-9\-\_]/g) == -1;
|
||||||
}
|
}
|
||||||
// TODO: rewrite
|
|
||||||
let main = new Route([auth], async function (req, res, input) {
|
let main = new Route([auth], async function (req, res, input) {
|
||||||
let { username } = input;
|
let { username } = input;
|
||||||
let id = randomUUID();
|
|
||||||
|
|
||||||
let { target } = req.body;
|
let { target } = req.body;
|
||||||
if (!isValid(target) || username == '!nobody')
|
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 = ?', [
|
let isFollowing = await db.all('SELECT * FROM follow WHERE username = ? AND target = ?', [
|
||||||
username,
|
username,
|
||||||
|
|
|
@ -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 Route from "../route.js";
|
||||||
import initDb from "../db.js";
|
import initDb from "../db.js";
|
||||||
import { compare } from "bcrypt";
|
import { compare } from "bcrypt";
|
||||||
|
@ -7,7 +6,6 @@ import captcha from "./captcha.js";
|
||||||
|
|
||||||
let db = await initDb();
|
let db = await initDb();
|
||||||
|
|
||||||
// TODO: rewrite
|
|
||||||
let main = new Route([captcha], async function (req, res, input) {
|
let main = new Route([captcha], async function (req, res, input) {
|
||||||
let { user, pass } = req.body;
|
let { user, pass } = req.body;
|
||||||
let { captchaMatch } = input;
|
let { captchaMatch } = input;
|
||||||
|
|
|
@ -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 Route from "../route.js";
|
||||||
import initDb from "../db.js";
|
import initDb from "../db.js";
|
||||||
import { hash } from "bcrypt";
|
import { hash } from "bcrypt";
|
||||||
|
@ -13,7 +12,6 @@ function isValid(user) {
|
||||||
return user.search(/[^A-Za-z0-9\-\_]/g) == -1;
|
return user.search(/[^A-Za-z0-9\-\_]/g) == -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: rewrite
|
|
||||||
let main = new Route([captcha], async function (req, res, input) {
|
let main = new Route([captcha], async function (req, res, input) {
|
||||||
let { user, pass, pass2 } = req.body;
|
let { user, pass, pass2 } = req.body;
|
||||||
let { captchaMatch } = input;
|
let { captchaMatch } = input;
|
||||||
|
|
|
@ -9,7 +9,6 @@ const execP = promisify(exec);
|
||||||
|
|
||||||
let db = await initDb();
|
let db = await initDb();
|
||||||
|
|
||||||
// TODO: rewrite
|
|
||||||
let main = new Route([auth, captcha], async function (req, res, input) {
|
let main = new Route([auth, captcha], async function (req, res, input) {
|
||||||
let { captchaMatch } = input;
|
let { captchaMatch } = input;
|
||||||
|
|
||||||
|
|
|
@ -10,7 +10,6 @@ const execP = promisify(exec);
|
||||||
|
|
||||||
let db = await initDb();
|
let db = await initDb();
|
||||||
|
|
||||||
// TODO: rewrite
|
|
||||||
let main = new Route([auth, captcha], async function (req, res, input) {
|
let main = new Route([auth, captcha], async function (req, res, input) {
|
||||||
let { captchaMatch } = input;
|
let { captchaMatch } = input;
|
||||||
|
|
||||||
|
@ -19,7 +18,7 @@ let main = new Route([auth,captcha], async function (req, res, input) {
|
||||||
let id = randomUUID();
|
let id = randomUUID();
|
||||||
|
|
||||||
let { title, desc } = req.body;
|
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;
|
||||||
|
|
||||||
|
|
|
@ -66,6 +66,7 @@ async function iterate(req, res, index) {
|
||||||
|
|
||||||
let dat = await routesI[cmd].run(req, res, {});
|
let dat = await routesI[cmd].run(req, res, {});
|
||||||
if (!dat && !res.headersSent) {
|
if (!dat && !res.headersSent) {
|
||||||
|
console.log(res)
|
||||||
return await routes.client['e404'].run(req, res, {});
|
return await routes.client['e404'].run(req, res, {});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue