From 7e23c3173a249ee88e73da38bd18848d2b5d016b Mon Sep 17 00:00:00 2001 From: defautluser0 Date: Thu, 15 Jan 2026 18:58:34 +0100 Subject: [PATCH] smaller msgdb size --- serve.ts | 35 ++++++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 11 deletions(-) diff --git a/serve.ts b/serve.ts index a21e190..679ae87 100644 --- a/serve.ts +++ b/serve.ts @@ -2,7 +2,7 @@ import { SHA512_256, type ServerWebSocket } from "bun"; import { SnowflakeGenerator } from "./snowflake.ts"; function getContentType(path: string): string { - if (path.endsWith(".html")) return "text/html"; + if (path.endsWith(".html") || path.endsWith(".htm")) return "text/html"; if (path.endsWith(".css")) return "text/css"; if (path.endsWith(".js")) return "application/javascript"; if (path.endsWith(".json")) return "application/json"; @@ -32,19 +32,19 @@ enum OpcodesServerbound { } interface user { - name: string; + name?: string; username: string; - pfp: string; - id: number; - token: string; - password: string; - dev: boolean; - bot: boolean; + pfp?: string; + id: string; + token?: string; + password?: string; + dev?: boolean; + bot?: boolean; } interface message { id: string; - author: user; + author: string | user; // server sends the user object but stores only the id for easier user.json modification content: string; timestamp: number; editedTimestamp?: number; @@ -121,10 +121,15 @@ const server = Bun.serve({ data: user[0], }) ); + let msgs = JSON.parse(JSON.stringify(messages)); + for (const ms of msgs) { + const user = users.find(user => user.id === ms.author); + ms.author = user || { username: "unknown-user", id: "0" }; + } ws.send( JSON.stringify({ op: OpcodesClientbound.initMessages, - data: messages, + data: msgs, }) ); } else { @@ -144,6 +149,7 @@ const server = Bun.serve({ obj.data.author.dev = user[0].dev; ws.publish("messages", JSON.stringify(obj)); ws.send(JSON.stringify(obj)); + obj.data.author = obj.data.author.id; messages.push(obj.data); Bun.write("./db/messages.json", JSON.stringify(messages)); } else { @@ -187,7 +193,14 @@ const server = Bun.serve({ path = "/index.html"; } - if (url.pathname === "/ws") { + if (path === "/pfps/" || path === "/pfps") { + return new Response( + "

403 Forbidden


Bun

", + { status: 403, headers: { "Content-Type": "text/html" } } + ); + } + + if (path === "/ws") { const upgraded = server.upgrade(req, { // @ts-expect-error guhh whqt data: {