summary refs log tree commit diff
path: root/src/util
diff options
context:
space:
mode:
authorRory& <root@rory.gay>2025-12-17 09:58:25 +0100
committerRory& <root@rory.gay>2025-12-17 11:04:16 +0100
commit11973397c812da59c2d544047bbb2d2d9ae583a7 (patch)
tree3e2064c4f6ff306241910dbfb877c03f46f935aa /src/util
parentFix extension cleanup stuff from Mathium05 (diff)
downloadserver-ts-dev/emma-wip.tar.xz
Diffstat (limited to 'src/util')
-rw-r--r--src/util/automod/AutomodExecutor.ts4
-rw-r--r--src/util/automod/AutomodMessageExecutor.ts1
-rw-r--r--src/util/automod/index.ts2
-rw-r--r--src/util/config/envTypes/ConfigurationEnvConfiguration.ts33
-rw-r--r--src/util/config/envTypes/DatabaseEnvConfiguration.ts5
-rw-r--r--src/util/config/envTypes/LogEnvConfiguration.ts53
-rw-r--r--src/util/config/envTypes/WebRtcEnvConfiguration.ts19
-rw-r--r--src/util/index.ts2
-rw-r--r--src/util/util/Token.ts2
-rw-r--r--src/util/util/extensions/Array.ts3
10 files changed, 72 insertions, 52 deletions
diff --git a/src/util/automod/AutomodExecutor.ts b/src/util/automod/AutomodExecutor.ts

index cf3d32eb..63267a3c 100644 --- a/src/util/automod/AutomodExecutor.ts +++ b/src/util/automod/AutomodExecutor.ts
@@ -55,7 +55,9 @@ export class AutomodExecutor { result = await this.executeMemberInvocation(); } else throw new Error("Unsupported automod invocation type"); - console.log(`[Automod] Executed automod invocation of type ${invocation.eventType} in ${Date.now() - startTime}ms with ${matchingRules.length} matching rules. Result: ${result.blocked ? "blocked" : "allowed"}`); + console.log( + `[Automod] Executed automod invocation of type ${invocation.eventType} in ${Date.now() - startTime}ms with ${matchingRules.length} matching rules. Result: ${result.blocked ? "blocked" : "allowed"}`, + ); return result; } diff --git a/src/util/automod/AutomodMessageExecutor.ts b/src/util/automod/AutomodMessageExecutor.ts
index b77a50a3..d53cbc6e 100644 --- a/src/util/automod/AutomodMessageExecutor.ts +++ b/src/util/automod/AutomodMessageExecutor.ts
@@ -19,7 +19,6 @@ export async function internalExecuteMessageAutomod(context: AutomodMessageInvoc } let triggered = false; // if (rule.trigger_type == AutomodRuleTriggerType.KEYWORD) - } return result; diff --git a/src/util/automod/index.ts b/src/util/automod/index.ts
index bc6cdcf0..4205761c 100644 --- a/src/util/automod/index.ts +++ b/src/util/automod/index.ts
@@ -1 +1 @@ -export * from './AutomodExecutor'; \ No newline at end of file +export * from "./AutomodExecutor"; diff --git a/src/util/config/envTypes/ConfigurationEnvConfiguration.ts b/src/util/config/envTypes/ConfigurationEnvConfiguration.ts
index 4f6918d9..fd25e408 100644 --- a/src/util/config/envTypes/ConfigurationEnvConfiguration.ts +++ b/src/util/config/envTypes/ConfigurationEnvConfiguration.ts
@@ -20,21 +20,24 @@ import { arrayOrderBy } from "@spacebar/util"; export class ConfigurationEnvConfiguration { static get schema() { - return arrayOrderBy([ - { key: "CONFIG_PATH", type: "string", description: "Path to a JSON file containing configuration data" }, - { key: "CONFIG_WRITEBACK", type: "boolean", description: "Whether to write back configuration changes to the specified JSON file" }, - { - key: "CONFIG_MODE", - type: "string", - description: - "How to treat the JSON config.<br/>" + - "<ul>" + - "<li>**`override`**: Apply overrides without saving</li>" + - "<li>**`overwrite`**: Apply overrides, saving changes to the database</li>" + - "<li>**`single`**: Ignore database config outright</li>" + - "</ul>", - }, - ], (e) => e.key); + return arrayOrderBy( + [ + { key: "CONFIG_PATH", type: "string", description: "Path to a JSON file containing configuration data" }, + { key: "CONFIG_WRITEBACK", type: "boolean", description: "Whether to write back configuration changes to the specified JSON file" }, + { + key: "CONFIG_MODE", + type: "string", + description: + "How to treat the JSON config.<br/>" + + "<ul>" + + "<li>**`override`**: Apply overrides without saving</li>" + + "<li>**`overwrite`**: Apply overrides, saving changes to the database</li>" + + "<li>**`single`**: Ignore database config outright</li>" + + "</ul>", + }, + ], + (e) => e.key, + ); } get enabled(): boolean { diff --git a/src/util/config/envTypes/DatabaseEnvConfiguration.ts b/src/util/config/envTypes/DatabaseEnvConfiguration.ts
index e4cfb5f0..8cb65e97 100644 --- a/src/util/config/envTypes/DatabaseEnvConfiguration.ts +++ b/src/util/config/envTypes/DatabaseEnvConfiguration.ts
@@ -27,7 +27,8 @@ export class DatabaseEnvConfiguration { { key: "DB_UNSAFE_SCHEMA_SYNC", type: "boolean", - description: "If true, the database schema will be forcibly synchronised. This is unsafe for production environments. **We claim no responsibility for data loss!**", + description: + "If true, the database schema will be forcibly synchronised. This is unsafe for production environments. **We claim no responsibility for data loss!**", }, { key: "DB_DISABLE_JOINS", @@ -37,7 +38,7 @@ export class DatabaseEnvConfiguration { ]; } - get url(): (string | undefined) { + get url(): string | undefined { return process.env.DATABASE; } diff --git a/src/util/config/envTypes/LogEnvConfiguration.ts b/src/util/config/envTypes/LogEnvConfiguration.ts
index ab97503c..68a70ded 100644 --- a/src/util/config/envTypes/LogEnvConfiguration.ts +++ b/src/util/config/envTypes/LogEnvConfiguration.ts
@@ -30,23 +30,34 @@ interface GatewayLoggingConfigValue { export class LogEnvConfiguration { static get schema() { - return arrayOrderBy([ - { key: "LOG_CDN_SIGNATURES", type: "boolean", description: "Log CDN attachment signature checks - very noisy!" }, - { key: "LOG_DATABASE_QUERIES", type: "boolean", description: "Enable logging of database queries." }, - { key: "LOG_GATEWAY_EVENTS", type: "boolean", description: "Comma-separated list of flags. Any of: `TRACES`, `USER_ID`, `SESSION_ID`, `PAYLOAD`, `HTTP`, `HTTP_MESSAGES`." }, - { key: "LOG_WEBRTC_EVENTS", type: "boolean", description: "Comma-separated list of flags. Any of: `TRACES`, `USER_ID`, `SESSION_ID`, `PAYLOAD`, `HTTP`, `HTTP_MESSAGES`." }, - { key: "DUMP_GATEWAY_EVENT_PATH", type: "string", description: "Path to dump gateway events." }, - { key: "DUMP_WEBRTC_EVENT_PATH", type: "string", description: "Path to dump gateway events." }, - { key: "LOG_PROTO_UPDATES", type: "boolean or string", description: "`true`, or a list of proto schemas to log (`SETTINGS`, `FRECENCY`)" }, - { - key: "LOG_REQUESTS", - type: "string", - description: "Comma-separated list of requests to log by status code. Negated with a leading `-`. Example: `-204` (log everything except 204 No Content)", - }, - { key: "LOG_AUTHENTICATION", type: "boolean", description: "Log authentication debug messages - very noisy!" }, - { key: "LOG_VALIDATION_ERRORS", type: "boolean", description: "Enable logging of validation errors." }, - { key: "LOG_IMPORT_ERRORS", type: "boolean", description: "Enable logging of import errors." }, - ], (e) => e.key); + return arrayOrderBy( + [ + { key: "LOG_CDN_SIGNATURES", type: "boolean", description: "Log CDN attachment signature checks - very noisy!" }, + { key: "LOG_DATABASE_QUERIES", type: "boolean", description: "Enable logging of database queries." }, + { + key: "LOG_GATEWAY_EVENTS", + type: "boolean", + description: "Comma-separated list of flags. Any of: `TRACES`, `USER_ID`, `SESSION_ID`, `PAYLOAD`, `HTTP`, `HTTP_MESSAGES`.", + }, + { + key: "LOG_WEBRTC_EVENTS", + type: "boolean", + description: "Comma-separated list of flags. Any of: `TRACES`, `USER_ID`, `SESSION_ID`, `PAYLOAD`, `HTTP`, `HTTP_MESSAGES`.", + }, + { key: "DUMP_GATEWAY_EVENT_PATH", type: "string", description: "Path to dump gateway events." }, + { key: "DUMP_WEBRTC_EVENT_PATH", type: "string", description: "Path to dump gateway events." }, + { key: "LOG_PROTO_UPDATES", type: "boolean or string", description: "`true`, or a list of proto schemas to log (`SETTINGS`, `FRECENCY`)" }, + { + key: "LOG_REQUESTS", + type: "string", + description: "Comma-separated list of requests to log by status code. Negated with a leading `-`. Example: `-204` (log everything except 204 No Content)", + }, + { key: "LOG_AUTHENTICATION", type: "boolean", description: "Log authentication debug messages - very noisy!" }, + { key: "LOG_VALIDATION_ERRORS", type: "boolean", description: "Enable logging of validation errors." }, + { key: "LOG_IMPORT_ERRORS", type: "boolean", description: "Enable logging of import errors." }, + ], + (e) => e.key, + ); } get gatewayLogging(): GatewayLoggingConfigValue { @@ -96,9 +107,7 @@ export class LogEnvConfiguration { logTraces: envVal?.includes("TRACES") || logDeprecated("LOG_WEBRTC_TRACES", "LOG_WEBRTC_EVENTS=TRACES") === "true", logUserId: envVal?.includes("USER_ID") ?? false, logSessionId: envVal?.includes("SESSION_ID") ?? false, - logPayload: - envVal?.includes("PAYLOAD") || - logDeprecated("WRTC_WS_VERBOSE", "LOG_WEBRTC_EVENTS=PAYLOAD") === "true", + logPayload: envVal?.includes("PAYLOAD") || logDeprecated("WRTC_WS_VERBOSE", "LOG_WEBRTC_EVENTS=PAYLOAD") === "true", logHttp: envVal?.includes("HTTP") ?? false, logHttpMessages: envVal?.includes("HTTP_MESSAGES") ?? false, }; @@ -111,7 +120,7 @@ export class LogEnvConfiguration { } get dumpGatewayEventPath(): string | undefined { - if(process.env.DUMP_GATEWAY_EVENT_PATH !== undefined) return process.env.DUMP_GATEWAY_EVENT_PATH; + if (process.env.DUMP_GATEWAY_EVENT_PATH !== undefined) return process.env.DUMP_GATEWAY_EVENT_PATH; if (process.env.WS_DUMP !== undefined) { console.warn("[EnvConfig] WS_DUMP is deprecated. Please use DUMP_GATEWAY_EVENT_PATH=./dump instead."); return process.env.WS_DUMP ? "dump" : undefined; @@ -119,7 +128,7 @@ export class LogEnvConfiguration { } get dumpWebrtcEventPath(): string | undefined { - if(process.env.DUMP_WEBRTC_EVENT_PATH !== undefined) return process.env.DUMP_WEBRTC_EVENT_PATH; + if (process.env.DUMP_WEBRTC_EVENT_PATH !== undefined) return process.env.DUMP_WEBRTC_EVENT_PATH; if (process.env.WRTC_DUMP !== undefined) { console.warn("[EnvConfig] WRTC_DUMP is deprecated. Please use DUMP_WEBRTC_EVENT_PATH=./dump_wrtc instead."); return process.env.WRTC_DUMP ? "dump_wrtc" : undefined; diff --git a/src/util/config/envTypes/WebRtcEnvConfiguration.ts b/src/util/config/envTypes/WebRtcEnvConfiguration.ts
index 2bcc28bf..6fb33b56 100644 --- a/src/util/config/envTypes/WebRtcEnvConfiguration.ts +++ b/src/util/config/envTypes/WebRtcEnvConfiguration.ts
@@ -20,12 +20,19 @@ import { arrayOrderBy } from "@spacebar/util"; export class WebRtcEnvConfiguration { static get schema() { - return arrayOrderBy([ - { key: "WRTC_PUBLIC_IP", type: "string", description: "Public IP of the server running the media server" }, - { key: "WRTC_PORT_MIN", type: "number", description: "Minimum port for WebRTC media server" }, - { key: "WRTC_PORT_MAX", type: "number", description: "Maximum port for WebRTC media server" }, - { key: "WRTC_LIBRARY", type: "string", description: "WebRTC library to use. One of `@spacebarchat/medooze-webrtc` (voice+video) or `@spacebarchat/mediasoup-webrtc` (voice only)" }, - ], (e) => e.key); + return arrayOrderBy( + [ + { key: "WRTC_PUBLIC_IP", type: "string", description: "Public IP of the server running the media server" }, + { key: "WRTC_PORT_MIN", type: "number", description: "Minimum port for WebRTC media server" }, + { key: "WRTC_PORT_MAX", type: "number", description: "Maximum port for WebRTC media server" }, + { + key: "WRTC_LIBRARY", + type: "string", + description: "WebRTC library to use. One of `@spacebarchat/medooze-webrtc` (voice+video) or `@spacebarchat/mediasoup-webrtc` (voice only)", + }, + ], + (e) => e.key, + ); } get publicIp(): string { diff --git a/src/util/index.ts b/src/util/index.ts
index 65305a5d..e0f83e06 100644 --- a/src/util/index.ts +++ b/src/util/index.ts
@@ -28,4 +28,4 @@ export * from "./imports"; export * from "./config"; export * from "./connections"; export * from "./Signing"; -export * from "./automod"; \ No newline at end of file +export * from "./automod"; diff --git a/src/util/util/Token.ts b/src/util/util/Token.ts
index a7c93648..580eef51 100644 --- a/src/util/util/Token.ts +++ b/src/util/util/Token.ts
@@ -49,7 +49,7 @@ export type UserTokenData = { }; function logAuth(text: string) { - if(!EnvConfig.get().logging.logAuthentication) return; + if (!EnvConfig.get().logging.logAuthentication) return; console.log(`[AUTH] ${text}`); } diff --git a/src/util/util/extensions/Array.ts b/src/util/util/extensions/Array.ts
index 355296b1..750e9ba5 100644 --- a/src/util/util/extensions/Array.ts +++ b/src/util/util/extensions/Array.ts
@@ -32,7 +32,6 @@ export function arrayPartition<T>(array: T[], filter: (elem: T) => boolean): [T[ return [pass, fail]; } - export function arrayRemove<T>(array: T[], item: T): void { const index = array.indexOf(item); if (index > -1) { @@ -62,4 +61,4 @@ export function arrayOrderByDescending<T>(array: T[], keySelector: (elem: T) => if (keyA < keyB) return 1; return 0; }); -} \ No newline at end of file +}