* Unified profiles, rather than instantiating profiles every time we want to access one

* Socket and live instance changes
* Possible problem with Deno's handling of sockets, compatibility issue with Node?
This commit is contained in:
2025-03-27 20:00:17 -04:00
parent dd7d929918
commit 492129df17
15 changed files with 147 additions and 82 deletions

View File

@@ -4,8 +4,9 @@ import Logging from "@proxnet/undead-logging";
import { decode } from "@gz/jwt";
import { Config } from "./config.ts";
import { AuthType, User, UserTokenFormat } from "./data/users.ts";
import Profile, { ProfileTokenFormat } from "./data/profiles.ts";
import UnifiedProfile, { ProfileTokenFormat } from "./data/profiles.ts";
import z from "zod";
import { IncomingMessage } from "node:http";
const config = Config.getConfig();
@@ -129,8 +130,16 @@ export function getSrcIpDefault(rq: express.Request): string {
const xrIp = rq.header("x-real-ip");
if (xrIp !== undefined) return xrIp;
const ip = typeof rq.ip === "undefined" ? "(unknown source)" : rq.ip;
return ip;
return typeof rq.ip === "undefined" ? "(unknown source)" : rq.ip;
}
export function getSrcIpDefaultRaw(rq: IncomingMessage) {
const cfIp = rq.headers['cf-connecting-ip'];
if (cfIp) return cfIp;
const xrIp = rq.headers['x-real-ip'];
if (xrIp) return xrIp;
return rq.socket.remoteAddress ? rq.socket.remoteAddress : "(unknown source)";
}
export function statusResponse(code: number) {
@@ -272,7 +281,7 @@ export async function Authentication(
].includes(false);
if (valid) {
if (decodedToken.typ == AuthType.Web) rs.locals.user = new User(decodedToken.sub);
else if (decodedToken.typ == AuthType.Game) rs.locals.profile = new Profile(decodedToken.sub);
else if (decodedToken.typ == AuthType.Game) rs.locals.profile = UnifiedProfile.get(decodedToken.sub);
nxt();
} else {