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 @@