switching networks works, established server functions
This commit is contained in:
@@ -29,7 +29,7 @@ export default class AuthHandler {
|
||||
}
|
||||
|
||||
getProfile(req, res) {
|
||||
const token = req.cookies.auth_token;
|
||||
const token = req.cookies?.auth_token;
|
||||
if (!token) return res.status(401).send({ error: "No auth token" });
|
||||
|
||||
try {
|
||||
@@ -42,7 +42,13 @@ export default class AuthHandler {
|
||||
return db.networks.get(c.to)
|
||||
})
|
||||
|
||||
res.send({ email: user.email, name: user.firstName + " " + user.lastName, networks: userOrgs});
|
||||
res.send({
|
||||
id: user.id,
|
||||
email: user.email,
|
||||
name: user.firstName + " " + user.lastName,
|
||||
networks: userOrgs,
|
||||
apps: user.apps
|
||||
});
|
||||
} catch (e) {
|
||||
console.error("Error getting profile: ", e)
|
||||
res.status(401).send({ error: "Invalid token" });
|
||||
|
||||
@@ -3,9 +3,13 @@ import chalk from 'chalk';
|
||||
import path from 'path';
|
||||
import {nodeModels, edgeModels} from './model/import.js'
|
||||
import Edge from "./model/edge.js"
|
||||
import { fileURLToPath } from "url"
|
||||
const __dirname = path.dirname(fileURLToPath(import.meta.url))
|
||||
|
||||
export default class Database {
|
||||
|
||||
PERSONAL_DATA_PATH = path.join(__dirname, '../../db/personal')
|
||||
|
||||
nodes = new Array(10000).fill(0);
|
||||
edges = new Array(10000).fill(0);
|
||||
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import path from 'path';
|
||||
import fs from 'fs';
|
||||
import argon2 from 'argon2';
|
||||
import { z } from 'zod';
|
||||
|
||||
@@ -15,6 +17,7 @@ export default class Member {
|
||||
firstName: z.string(),
|
||||
lastName: z.string(),
|
||||
password: z.string(),
|
||||
apps: z.array(z.string()),
|
||||
created: z.string()
|
||||
})
|
||||
|
||||
@@ -48,6 +51,17 @@ export default class Member {
|
||||
return members
|
||||
}
|
||||
|
||||
async getPersonalData(id) {
|
||||
const filePath = path.join(global.db.PERSONAL_DATA_PATH, id, "db.json");
|
||||
|
||||
const [raw] = await Promise.all([
|
||||
fs.promises.readFile(filePath, "utf8"),
|
||||
]);
|
||||
|
||||
const result = raw.trim() ? JSON.parse(raw) : [];
|
||||
return result
|
||||
}
|
||||
|
||||
getByID(id) {
|
||||
if(typeof id === 'string') {
|
||||
id = id.split("-")[1]
|
||||
|
||||
@@ -38,10 +38,25 @@ class Server {
|
||||
router.post('/free', this.newUserSubmission)
|
||||
router.get('/db/images/*', this.getUserImage)
|
||||
router.get('/app/orgdata/*', this.getOrgData)
|
||||
router.get('/app/mydata/*', this.getPersonalData)
|
||||
router.get('/*', this.get)
|
||||
return router
|
||||
}
|
||||
|
||||
getPersonalData = async (req, res, next) => {
|
||||
try {
|
||||
const memberId = req.params[0]
|
||||
|
||||
let data = await global.db.members.getPersonalData(memberId)
|
||||
|
||||
res.json({
|
||||
data
|
||||
});
|
||||
} catch (err) {
|
||||
next(err);
|
||||
}
|
||||
}
|
||||
|
||||
getOrgData = async (req, res, next) => {
|
||||
try {
|
||||
const networkId = req.params[0]
|
||||
|
||||
@@ -2,6 +2,7 @@ import { WebSocket, WebSocketServer } from 'ws';
|
||||
import { z } from 'zod';
|
||||
import jwt from 'jsonwebtoken';
|
||||
|
||||
import * as serverFunctions from "../../ui/_/code/bridge/serverFunctions.js"
|
||||
import ForumHandler from "./handlers/ForumHandler.js"
|
||||
import MessagesHandler from "./handlers/MessagesHandler.js"
|
||||
|
||||
@@ -9,7 +10,7 @@ export default class Socket {
|
||||
wss;
|
||||
messageSchema = z.object({
|
||||
id: z.string(),
|
||||
app: z.string(),
|
||||
app: z.string().optional(),
|
||||
operation: z.string().optional(),
|
||||
msg: z.union([
|
||||
z.object({}).passthrough(), // allows any object
|
||||
@@ -67,7 +68,7 @@ export default class Socket {
|
||||
const text = msg.toString();
|
||||
const req = JSON.parse(text);
|
||||
if(!this.messageSchema.safeParse(req).success) throw new Error("Socket.handleMessage: Incoming ws message has incorrect format!")
|
||||
|
||||
|
||||
let responseData;
|
||||
switch (req.app) {
|
||||
case "FORUM":
|
||||
@@ -79,7 +80,12 @@ export default class Socket {
|
||||
break;
|
||||
|
||||
default:
|
||||
console.error("unknown ws message")
|
||||
if(!req.app) {
|
||||
let func = req.msg
|
||||
responseData = serverFunctions[func.name](...args)
|
||||
} else {
|
||||
console.error("unknown ws message")
|
||||
}
|
||||
}
|
||||
|
||||
let response = {
|
||||
|
||||
Reference in New Issue
Block a user