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

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