From 4eddd1a0c7682b473ecffa8e8093adc131688cb3 Mon Sep 17 00:00:00 2001 From: biglyderv Date: Wed, 26 Feb 2025 22:12:46 -0500 Subject: [PATCH] some beta stuff --- public/index.css | 11 +++++++++++ routes/commenter.js | 7 ++++++- routes/init.js | 8 +++++--- routes/user.js | 15 +++++++++++++++ routes/youApi.js | 16 ++++++++++++++++ views/comment.ejs | 11 ++++++----- views/user.ejs | 23 +++++++++++++++++++++++ 7 files changed, 82 insertions(+), 9 deletions(-) create mode 100644 routes/user.js create mode 100644 views/user.ejs diff --git a/public/index.css b/public/index.css index d376c56..9290541 100644 --- a/public/index.css +++ b/public/index.css @@ -42,6 +42,9 @@ body { border-top-right-radius: 10px; max-width: calc(100vw - 40px); margin-bottom: 10px; + + display: flex; + align-items: center; } .scroller { @@ -199,4 +202,12 @@ h1 { .commentbox { white-space: pre-wrap; word-wrap: break-word; +} + +.avatar-img { + width: 50px; + height: 50px; + margin-right: 8px; + border-radius: 15px; + object-fit: cover; } \ No newline at end of file diff --git a/routes/commenter.js b/routes/commenter.js index 7b62d8e..142313f 100644 --- a/routes/commenter.js +++ b/routes/commenter.js @@ -14,7 +14,12 @@ router.post('/', async (req, res, next) => { let { username } = res.auth; let { post, type, id } = req.body; - if (!username || !post || !id || !type) { + if (!username) { + apiStat(res, next, 'Log in to chat with the community.') + return; + } + + if (!post || !id || !type) { apiStat(res, next, 'Fields are missing.') return; } diff --git a/routes/init.js b/routes/init.js index 893fe32..890bc46 100644 --- a/routes/init.js +++ b/routes/init.js @@ -26,9 +26,11 @@ const aliases = { const routers = { '/you': './routes/you.js', '/api/form/you': './routes/youApi.js', + '/api/file/you': './routes/youApi.js', '/api/file/comment': './routes/commenter.js', '/walls': './routes/walls.js', - '/comment': './routes/comment.js' + '/comment': './routes/comment.js', + '/users': './routes/user.js' } function doAliases(app) { @@ -74,14 +76,14 @@ async function auther(req, res, next) { function initr(req, res, next) { let headerCtx = [ - { link: '/walls/get/home/0', icon: '/icon.svg', name: 'DervNet' }, + { link: '/walls/get/hub/main/0', icon: '/icon.svg', name: 'DervNet' }, { link: '/walls/list', icon: '/walls.svg', name: 'Explore' }, { link: '/you/logout', icon: '/logout.svg', name: 'Leave' } // fix icon ]; if (!res.auth || !res.auth.valid) { headerCtx = [ - { link: '/walls/get/home/0', icon: '/icon.svg', name: 'DervNet' }, + { link: '/walls/get/hub/main/0', icon: '/icon.svg', name: 'DervNet' }, { link: '/walls/list', icon: '/walls.svg', name: 'Explore' }, { link: '/you/login', icon: '/login.svg', name: 'Log in' }, { link: '/you/new', icon: '/join.svg', name: 'Join' } diff --git a/routes/user.js b/routes/user.js new file mode 100644 index 0000000..caa9e96 --- /dev/null +++ b/routes/user.js @@ -0,0 +1,15 @@ +import { Router } from "express"; +const router = Router(); + +//todo: fix jank + +router.get('/:username', (req, res, next) => { + res.ctx.mainPage = 'user' + res.ctx.mainCtx = { + username: req.params.username, + isYou: res.auth && req.params.username == res.auth.username + } + next(); +}) + +export default router; \ No newline at end of file diff --git a/routes/youApi.js b/routes/youApi.js index ab6e2e1..49ae4a4 100644 --- a/routes/youApi.js +++ b/routes/youApi.js @@ -3,6 +3,7 @@ import { apiStat } from "../lib.js"; import { hash, compare } from "bcrypt"; import { initDb } from "../db.js"; import { randomBytes } from 'node:crypto'; +import { rename } from 'node:fs/promises'; let db = await initDb(); @@ -14,6 +15,21 @@ function legalName(user) { return user.search(/[^A-Za-z0-9\-\_]/g) == -1; } +router.post('/settings', async (req, res, next) => { + let {file} = req; + let {username, valid} = res.auth; + + console.log(file) + + if (!valid) return; + + if (file) { + await rename(file.path,`./uploads/pfp_${username}.png`); + } + + next(); +}); + router.post('/logout', (req, res, next) => { res.clearCookie('token'); apiStat(res, next, `Goodbye!`, '/'); diff --git a/views/comment.ejs b/views/comment.ejs index bc0ad73..696b836 100644 --- a/views/comment.ejs +++ b/views/comment.ejs @@ -1,17 +1,18 @@

<% if (username) { %> + <%= username %> <% } else { %> Context <% } %>

<% for (let contentN of content) { %> - <% if (contentN[0] == 'file' && contentN [1]) { %> - '> - <% } else { %> -
<%= contentN[0] %>
- <% } %> + <% if (contentN[0] == 'file' && contentN [1]) { %> + '> + <% } else { %> +
<%= contentN[0] %>
+ <% } %> <% } %> <% if (!isNaN(date * 1)) { %>
Posted on <%= new Date(date).toISOString() %>
diff --git a/views/user.ejs b/views/user.ejs new file mode 100644 index 0000000..bbd7108 --- /dev/null +++ b/views/user.ejs @@ -0,0 +1,23 @@ +
+

+ + <%= username %> +

+ A very cool person! +
+ +<% if (isYou) { %> + <%- include('form.ejs', { + title: "Your Settings", + message: 'Configure your profile.', + action: "/api/file/you/settings", + inputs: [ + { + "key": "Avatar", + "type": "file", + "name": "file", + "default": "" + } + ] + }) %> +<% } %> \ No newline at end of file