diff --git a/client/main.js b/client/main.js index 5578926..58fe4d8 100644 --- a/client/main.js +++ b/client/main.js @@ -6,7 +6,7 @@ let db = await initDb(); let main = new Route([auth], async function (req, res, input) { let { username } = input; - let videos = await db.all('SELECT * FROM video ORDER BY date DESC', [ + let videos = await db.all('SELECT * FROM video ORDER BY date DESC LIMIT 10', [ ]); return res.render('main', { username, diff --git a/client/user.js b/client/user.js index 99efc69..3a81382 100644 --- a/client/user.js +++ b/client/user.js @@ -9,10 +9,21 @@ let main = new Route([comment], async function (req, res, input) { let videos = await db.all('SELECT * FROM video WHERE username = ? ORDER BY date DESC', [ req.query.id ]); + + let followers = await db.all('SELECT * FROM follow WHERE target = ?', [ + req.query.id + ]); + + let following = await db.all('SELECT * FROM follow WHERE username = ?', [ + req.query.id + ]); + return res.render('user', { ...input, id, - videos + videos, + followers, + following }); }); diff --git a/db.js b/db.js index 5f0a8e1..e451ea8 100644 --- a/db.js +++ b/db.js @@ -17,6 +17,8 @@ async function initDb() { await db.run(`CREATE TABLE IF NOT EXISTS video (id TEXT, title TEXT, desc TEXT, username TEXT, date REAL);`); await db.run('CREATE TABLE IF NOT EXISTS comment (username TEXT, targetType TEXT, targetId TEXT, date REAL, content TEXT, id TEXT);'); + await db.run('CREATE TABLE IF NOT EXISTS follow (username TEXT, target TEXT);'); + return db; } diff --git a/form/comment.js b/form/comment.js index 71061e8..0be0bfe 100644 --- a/form/comment.js +++ b/form/comment.js @@ -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 diff --git a/form/follow.js b/form/follow.js new file mode 100644 index 0000000..3ce8943 --- /dev/null +++ b/form/follow.js @@ -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; \ No newline at end of file diff --git a/routes.js b/routes.js index 183a233..220e864 100644 --- a/routes.js +++ b/routes.js @@ -10,6 +10,7 @@ import registerB from "./form/register.js"; import uploadB from "./form/upload.js"; import auth from "./form/auth.js"; import commentB from "./form/comment.js"; +import follow from './form/follow.js'; const routes = { get: {}, @@ -32,7 +33,8 @@ routes.form = { register: registerB, upload: uploadB, auth, - comment: commentB + comment: commentB, + follow }; async function iterate(req, res, index) { diff --git a/views/main.ejs b/views/main.ejs index 799312a..872d9e1 100644 --- a/views/main.ejs +++ b/views/main.ejs @@ -1,24 +1,18 @@ <%- include('header.ejs') -%>
Collab on videos... make creative animations... and more!
-I am Onez, a self-taught developer from a young age. Following - the - unexpected growth - of Video Bot Thing, I made this as a home for the video editing community. View the source if you want to contribute or make a - fork.
-Express your niche...
+Build a video community...
+And more!
+ <%= following.length %> following +
++ <%= followers.length %> followers +
+ + +