From 0bc9af3b06775195f9ea50e04defde2fc10d7835 Mon Sep 17 00:00:00 2001 From: ewsgit Date: Tue, 23 Jun 2026 19:51:44 +0000 Subject: [PATCH] improve backend logging & system shutdown messages --- backend/src/index.ts | 11 ++++++----- backend/src/system.ts | 5 ++--- backend/src/systems/api.ts | 12 +++++++++--- backend/src/systems/filesystem.ts | 44 ++++++++------------------------------------ backend/src/systems/terminal.ts | 8 ++++---- backend/src/systems/trpc/coreRouter.ts | 3 +++ backend/src/systems/webFrontend.ts | 1 - 7 file(s) changed, 32 insertion(s)(+), 52 deletion(s)(-) diff --git a/backend/src/index.ts b/backend/src/index.ts --- a/backend/src/index.ts +++ b/backend/src/index.ts @@ -60,8 +60,8 @@ this.sys.api = new ApiSystem(this); this.status = InstanceStatus.Offline; - Deno.addSignalListener("SIGINT", () => { - this.shutdown(); + Deno.addSignalListener("SIGINT", async () => { + await this.shutdown("Console Admin Ctrl+C"); }); } @@ -108,18 +108,19 @@ this.log.system.warning(`Hey Server Admin, THE INSTANCE HAS BEEN PROMPTED FOR RESTART DUE TO '${reason}' please restart when possible.`); return this; } - async shutdown() { + async shutdown(cause?: string) { + this.log.system.info(`Shutting down... ${cause !== undefined ? `(Caused by: ${cause})` : ""}`); this.status = InstanceStatus.Stopping; - this.log.system.info("Shutting down..."); this.sys.event.invoke(WorkspacesEvent.BeforeShutdown); + this.status = InstanceStatus.Offline; for (const sys of Object.values(this.sys)) { const subSystemState = await sys.stop(); if (subSystemState) { - this.log.system.success(`System '${sys.id}' shutdown failed!`); + this.log.system.success(`System '${sys.id}' shutdown successfully!`); } else { this.log.system.error(`System '${sys.id}' shutdown failed! (Shutdown will still continue)`); } diff --git a/backend/src/system.ts b/backend/src/system.ts --- a/backend/src/system.ts +++ b/backend/src/system.ts @@ -53,8 +53,7 @@ async startup(): Promise { return true; } - stop(): this | Promise { - this.log.info(`Stopping System ${this.id}`); - return this; + stop(): boolean | Promise { + return true; } } diff --git a/backend/src/systems/api.ts b/backend/src/systems/api.ts --- a/backend/src/systems/api.ts +++ b/backend/src/systems/api.ts @@ -21,6 +21,13 @@ this.routes = [ { method: ["GET"], + pattern: new URLPattern({ pathname: "/api/teapot" }), + handler(req) { + return Response.json({ teapot: true, message: "This OnlineWorkspace (Teapot?) sadly does not support the Hyper Text Coffee Pot Control Protocol (HTCPCP) 😢"}, { status: 418 }) + }, + }, + { + method: ["GET"], pattern: new URLPattern({ pathname: "/api/instance/login/banner" }), handler(req) { return serveFile( @@ -48,11 +55,10 @@ }, { method: ["GET"], pattern: new URLPattern({ pathname: "/api/user/me/avatar/:size" }), - async handler(req, _, rawParams) { - // @ts-ignore this does exist + async handler(req, rawParams, _info) { const params = rawParams?.pathname.groups; - const size = params.size; + const size = params.size!; const cookies = getCookies(req.headers); diff --git a/backend/src/systems/filesystem.ts b/backend/src/systems/filesystem.ts --- a/backend/src/systems/filesystem.ts +++ b/backend/src/systems/filesystem.ts @@ -10,6 +10,7 @@ Video, ThreeDimensionalModel, Audio, Text, + Unknown } export default class FilesystemSystem extends System { @@ -70,45 +71,15 @@ return true; } - getFileType(path: string) { - const extension = path.split(".").pop(); + getFileType(path: string): FileMediaType { + const extension = "." + path.split(".").pop(); - switch (extension) { - case "avif": - case "webp": - case "jpg": - case "jpeg": - case "png": - case "gif": - return "image"; - case "txt": - case "json": - case "js": - case "ts": - case "tsx": - case "scss": - case "sass": - case "yml": - case "yaml": - case "xml": - case "py": - case "toml": - case "rs": - case "html": - case "htm": - case "css": - case "jsm": - case "tsm": - case "tsc": - case "jsc": - case "sql": - case "lock": - return "plaintext"; - } + const mediaType = this._internalFileExtensions.get(extension)?.type; - this.log.warning(`Unknown file format: '${path}' ext: '${extension}'`); + if (!mediaType) + this.log.warning(`Unknown file format: '${path}' ext: '${extension}'`); - return undefined; + return FileMediaType.Unknown; } // returns an endpoint where the asset located at the provided path can be loaded from on the client @@ -277,6 +248,7 @@ Deno.mkdirSync(path.join(this.SYSTEM_PATH, "fs_template_files")); fs.copySync( path.join(this.SRC_ROOT, "assets/fs_template_files/"), path.join(this.SYSTEM_PATH, "fs_template_files"), + { overwrite: true } ); }else this.log.debug( `FS_ROOT/assets/fs_template_files exists, (${ diff --git a/backend/src/systems/terminal.ts b/backend/src/systems/terminal.ts --- a/backend/src/systems/terminal.ts +++ b/backend/src/systems/terminal.ts @@ -144,11 +144,11 @@ this.instance.sys.consoleCommands.executeCommandFromString(data); }); this.readlineInterface.on("SIGINT", () => { - this.instance.shutdown(); + this.instance.shutdown("Console Admin Ctrl+C"); }); this.readlineInterface.on("SIGTERM", () => { - this.instance.shutdown(); + this.instance.shutdown("SIGTERM"); }); return true; @@ -337,10 +337,10 @@ return true; } - override stop(): this { + override stop(): boolean { this.renderer?.destroy?.(); this.readlineInterface?.close?.(); - return this; + return true; } } diff --git a/backend/src/systems/trpc/coreRouter.ts b/backend/src/systems/trpc/coreRouter.ts --- a/backend/src/systems/trpc/coreRouter.ts +++ b/backend/src/systems/trpc/coreRouter.ts @@ -298,6 +298,7 @@ name: "Authorization", value: session, secure: true, expires: new Date(Date.now() + 1000 * 60 * 60 * 24 * 14), + domain: opt.ctx.instance.sys.configuration.proxy.hostname }); return { @@ -463,6 +464,7 @@ name: "Authorization", value: session, secure: true, expires: new Date(Date.now() + 1000 * 60 * 60 * 24 * 14), + domain: opt.ctx.instance.sys.configuration.proxy.hostname }); return { @@ -529,6 +531,7 @@ name: "Authorization", value: session, secure: true, expires: new Date(Date.now() + 1000 * 60 * 60 * 24 * 14), + domain: opt.ctx.instance.sys.configuration.proxy.hostname }); return { diff --git a/backend/src/systems/webFrontend.ts b/backend/src/systems/webFrontend.ts --- a/backend/src/systems/webFrontend.ts +++ b/backend/src/systems/webFrontend.ts @@ -29,7 +29,6 @@ protocol: "wss", host: this.instance.sys.configuration.proxy.hostname, }, }, - forceOptimizeDeps: true, logger: { info(msg: string, options?: { clear?: boolean; timestamp?: boolean; environment?: string }) { self.log.info(msg, options); -- tangled.sh