diff --git a/backend/src/index.ts b/backend/src/index.ts index bf2e330..b6053ff 100644 --- a/backend/src/index.ts +++ b/backend/src/index.ts @@ -60,8 +60,8 @@ class Instance { this.status = InstanceStatus.Offline; - Deno.addSignalListener("SIGINT", () => { - this.shutdown(); + Deno.addSignalListener("SIGINT", async () => { + await this.shutdown("Console Admin Ctrl+C"); }); } @@ -108,18 +108,19 @@ class Instance { 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 index 3bacef7..948f059 100644 --- a/backend/src/system.ts +++ b/backend/src/system.ts @@ -53,8 +53,7 @@ export default abstract class System { 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 index bae5c11..0e16ba6 100644 --- a/backend/src/systems/api.ts +++ b/backend/src/systems/api.ts @@ -19,6 +19,13 @@ export default class ApiSystem extends System { const self = this; 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" }), @@ -48,11 +55,10 @@ export default class ApiSystem extends System { { 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 index 1c8b4a1..2511d65 100644 --- a/backend/src/systems/filesystem.ts +++ b/backend/src/systems/filesystem.ts @@ -10,6 +10,7 @@ export enum FileMediaType { ThreeDimensionalModel, Audio, Text, + Unknown } export default class FilesystemSystem extends System { @@ -70,45 +71,15 @@ export default class FilesystemSystem extends System { return true; } - getFileType(path: string) { - 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"; - } + getFileType(path: string): FileMediaType { + const extension = "." + path.split(".").pop(); + + 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 @@ export default class FilesystemSystem extends System { 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 index 31f0b83..2f0fad5 100644 --- a/backend/src/systems/terminal.ts +++ b/backend/src/systems/terminal.ts @@ -144,11 +144,11 @@ export default class TerminalUISystem extends System { }); 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 @@ export default class TerminalUISystem extends System { 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 index 8066e68..b173bbf 100644 --- a/backend/src/systems/trpc/coreRouter.ts +++ b/backend/src/systems/trpc/coreRouter.ts @@ -298,6 +298,7 @@ export const coreOnlineWorkspaceRouter = t.router({ 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 @@ export const coreOnlineWorkspaceRouter = t.router({ 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 @@ export const coreOnlineWorkspaceRouter = t.router({ 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 index cd5008e..967cd29 100644 --- a/backend/src/systems/webFrontend.ts +++ b/backend/src/systems/webFrontend.ts @@ -29,7 +29,6 @@ export default class WebFrontendSystem extends System { 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);