some beta stuff

This commit is contained in:
biglyderv 2025-02-26 22:12:46 -05:00
parent 2c480909ee
commit 4eddd1a0c7
Signed by: biglyderv
GPG key ID: 0E2EB0B4CD7397B5
7 changed files with 82 additions and 9 deletions

View file

@ -42,6 +42,9 @@ body {
border-top-right-radius: 10px;
max-width: calc(100vw - 40px);
margin-bottom: 10px;
display: flex;
align-items: center;
}
.scroller {
@ -200,3 +203,11 @@ h1 {
white-space: pre-wrap;
word-wrap: break-word;
}
.avatar-img {
width: 50px;
height: 50px;
margin-right: 8px;
border-radius: 15px;
object-fit: cover;
}

View file

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

View file

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

15
routes/user.js Normal file
View file

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

View file

@ -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!`, '/');

View file

@ -1,6 +1,7 @@
<div class='main'>
<h1 class="header-big">
<% if (username) { %>
<img src="/uploads/pfp_<%= username %>.png" class="avatar-img">
<a class='link' href='/users/<%= username %>'><%= username %></a>
<% } else { %>
Context

23
views/user.ejs Normal file
View file

@ -0,0 +1,23 @@
<div class='main'>
<h1 class="header-big">
<img src="/uploads/pfp_<%= username %>.png" class="avatar-img">
<span><%= username %></span>
</h1>
<span>A very cool person!</span>
</div>
<% 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": ""
}
]
}) %>
<% } %>