diff --git a/.gitignore b/.gitignore index ad25643..4f941c6 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,5 @@ /db /package-lock.json /uploads -/videos \ No newline at end of file +/videos +/pfp \ No newline at end of file diff --git a/client/settings.js b/client/settings.js new file mode 100644 index 0000000..5a99989 --- /dev/null +++ b/client/settings.js @@ -0,0 +1,18 @@ +import Route from "../route.js"; +import auth from "../form/auth.js"; + +// TODO: rewrite +let main = new Route([auth], async function (req, res, input) { + let { username } = input; + return res.render('form', { + data: [ + { label: "Description", type: "textarea", name: "desc" }, + { label: "Avatar", type: "file", name: "file" } + ], + 'route': '/api/upload/settings', + 'title': 'User Settings', + username + }); /* todo: form in not a file */ +}); + +export default main; \ No newline at end of file diff --git a/client/user.js b/client/user.js index 3a81382..cceca23 100644 --- a/client/user.js +++ b/client/user.js @@ -18,12 +18,17 @@ let main = new Route([comment], async function (req, res, input) { req.query.id ]); + let user = await db.all('SELECT * FROM user WHERE username = ?', [ + req.query.id + ]); + return res.render('user', { ...input, id, videos, followers, - following + following, + user }); }); diff --git a/db.js b/db.js index e451ea8..66c1cd8 100644 --- a/db.js +++ b/db.js @@ -19,6 +19,8 @@ async function initDb() { 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);`); + return db; } diff --git a/form/settings.js b/form/settings.js new file mode 100644 index 0000000..b92927b --- /dev/null +++ b/form/settings.js @@ -0,0 +1,34 @@ +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; \ No newline at end of file diff --git a/index.js b/index.js index 4386d51..3cafab1 100644 --- a/index.js +++ b/index.js @@ -12,6 +12,7 @@ const upload = multer({ dest: 'uploads/' }); app.use(cookieParser()); app.use('/static', express.static('static')); app.use('/videos', express.static('videos')); +app.use('/pfp', express.static('pfp')); app.engine('.ejs', ejs.__express); app.set('views', './views'); app.set('view engine', 'ejs'); diff --git a/routes.js b/routes.js index 220e864..23366d4 100644 --- a/routes.js +++ b/routes.js @@ -4,12 +4,14 @@ import register from "./client/register.js"; import upload from "./client/upload.js"; import player from "./client/player.js"; import user from "./client/user.js"; +import settings from "./client/settings.js"; import loginB from "./form/login.js"; 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 settingsB from "./form/settings.js"; +import auth from "./form/auth.js"; import follow from './form/follow.js'; const routes = { @@ -24,17 +26,21 @@ routes.client = { register, upload, video: player, - user + user, + settings } + routes.get = { }; + routes.form = { login: loginB, register: registerB, upload: uploadB, auth, comment: commentB, - follow + follow, + settings: settingsB }; async function iterate(req, res, index) { diff --git a/static/img/channel.svg b/static/img/channel.svg deleted file mode 100644 index da65227..0000000 --- a/static/img/channel.svg +++ /dev/null @@ -1,46 +0,0 @@ - - - - - - - - - - diff --git a/static/img/chat.svg b/static/img/chat.svg deleted file mode 100644 index 0b4d95b..0000000 --- a/static/img/chat.svg +++ /dev/null @@ -1,47 +0,0 @@ - - - - - - - - - - diff --git a/static/img/extra.svg b/static/img/extra.svg deleted file mode 100644 index 2f393be..0000000 --- a/static/img/extra.svg +++ /dev/null @@ -1,50 +0,0 @@ - - - - - - - - - - - diff --git a/static/img/login.svg b/static/img/login.svg deleted file mode 100644 index 8173ed6..0000000 --- a/static/img/login.svg +++ /dev/null @@ -1,46 +0,0 @@ - - - - - - - - - - diff --git a/static/main.css b/static/main.css index 4d9245c..71f3b00 100644 --- a/static/main.css +++ b/static/main.css @@ -89,7 +89,7 @@ form { } -.form-entry { +.form-entry, textarea { display: block; } @@ -168,10 +168,6 @@ form { color: var(--dark-1); } -textarea { - display: block; -} - .progressbar { background-color: var(--light-1); border: solid var(--dark-2) 2px; @@ -216,4 +212,14 @@ img.dark { pre { white-space: pre-wrap; overflow-x: auto; +} + +.pfp-wrapper { + display: flex; +} + +.avatar { + width: 50px; + height: 50px; + margin-right: 15px; } \ No newline at end of file diff --git a/views/comments.ejs b/views/comments.ejs index 3bfcd87..3762ee7 100644 --- a/views/comments.ejs +++ b/views/comments.ejs @@ -1,6 +1,5 @@

Comments

-
@@ -9,13 +8,20 @@ <% for (let comment of comments) { %>
-
- <%= comment.username %> -
-
- <%= (new Date(comment.date)+'').split(/(GMT|UTC)/g)[0] %> -
-
<%= comment.content %>
+
+ +
+
+ + <%= comment.username %> + +
+
+ <%= (new Date(comment.date)+'').split(/(GMT|UTC)/g)[0] %> +
+
<%= comment.content %>
+
+
<% } %>
\ No newline at end of file diff --git a/views/header_block.ejs b/views/header_block.ejs index cf174b3..af8b1b0 100644 --- a/views/header_block.ejs +++ b/views/header_block.ejs @@ -10,5 +10,8 @@ Upload + + Settings + <% } %> \ No newline at end of file diff --git a/views/player.ejs b/views/player.ejs index 51cfbda..2d8e393 100644 --- a/views/player.ejs +++ b/views/player.ejs @@ -15,12 +15,17 @@ <%= videoData.title %> -
Created by - @<%= videoData.username %> - on - - <%= (new Date(videoData.date)+'').split(/(GMT|UTC)/g)[0] %> - + +
+ +
+ Created by + @<%= videoData.username %> + on + + <%= (new Date(videoData.date)+'').split(/(GMT|UTC)/g)[0] %> + +
<%= videoData.desc %>
diff --git a/views/user.ejs b/views/user.ejs index 5b58753..fe31e45 100644 --- a/views/user.ejs +++ b/views/user.ejs @@ -3,24 +3,38 @@

User

-

- @<%= id %> -

-
- <%= following.length %> following - <% for (let user of following) { %> - <%= user.target %> - <%} %> -
-
- <%= followers.length %> followers - <% for (let user of followers) { %> - <%= user.username %> - <%} %> -
- - +
+ +
+

+ @<%= id %> +

+
+ + <%= following.length %> following + + <% for (let user of following) { %> + + <%= user.target %> + + <%} %> +
+
+ + <%= followers.length %> followers + + <% for (let user of followers) { %> + + <%= user.username %> + + <%} %> +
+ + +
+
+
<%= user[0].bio %>

Uploaded Videos