summary refs log tree commit diff
path: root/src
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
parentFix extension cleanup stuff from Mathium05 (diff)
downloadserver-ts-dev/emma-wip.tar.xz
Diffstat (limited to 'src')
-rw-r--r--src/api/routes/channels/#channel_id/messages/index.ts17
-rw-r--r--src/api/routes/users/@me/settings-proto/1.ts3
-rw-r--r--src/api/routes/users/@me/settings-proto/2.ts3
-rw-r--r--src/cdn/util/Storage.ts2
-rw-r--r--src/gateway/events/Connection.ts17
-rw-r--r--src/gateway/opcodes/Identify.ts5
-rwxr-xr-xsrc/renderEnvConfigSchema.ts12
-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
-rw-r--r--src/webrtc/events/Connection.ts17
-rw-r--r--src/webrtc/util/Send.ts5
19 files changed, 106 insertions, 99 deletions
diff --git a/src/api/routes/channels/#channel_id/messages/index.ts b/src/api/routes/channels/#channel_id/messages/index.ts

index 0a84e6b0..edca59df 100644 --- a/src/api/routes/channels/#channel_id/messages/index.ts +++ b/src/api/routes/channels/#channel_id/messages/index.ts
@@ -19,7 +19,8 @@ import { handleMessage, postHandleMessage, route } from "@spacebar/api"; import { Attachment, - AutomodExecutor, AutomodInvocation, + AutomodExecutor, + AutomodInvocation, AutomodRule, AutomodTriggerTypes, Channel, @@ -443,13 +444,15 @@ router.post( // @ts-ignore message.member.roles = message.member.roles.filter((x) => x.id != x.guild_id).map((x) => x.id); - const automodResult = await AutomodExecutor.executeInvocation(new AutomodInvocation({ - eventType: AutomodRuleEventType.MESSAGE_SEND, - guildId: message.guild_id, - payload: message - })); + const automodResult = await AutomodExecutor.executeInvocation( + new AutomodInvocation({ + eventType: AutomodRuleEventType.MESSAGE_SEND, + guildId: message.guild_id, + payload: message, + }), + ); - if(automodResult.blocked) { + if (automodResult.blocked) { throw new HTTPError("Unhandled error sending message", 403); } } diff --git a/src/api/routes/users/@me/settings-proto/1.ts b/src/api/routes/users/@me/settings-proto/1.ts
index c4fde496..46b2f3b8 100644 --- a/src/api/routes/users/@me/settings-proto/1.ts +++ b/src/api/routes/users/@me/settings-proto/1.ts
@@ -137,8 +137,7 @@ async function patchUserSettings(userId: string, updatedSettings: PreloadedUserS }; } - if (EnvConfig.get().logging.logProtoUpdates.includes("SETTINGS")) - console.log(`Updating user settings for user ${userId} with atomic=${atomic}:`, updatedSettings); + if (EnvConfig.get().logging.logProtoUpdates.includes("SETTINGS")) console.log(`Updating user settings for user ${userId} with atomic=${atomic}:`, updatedSettings); if (!atomic) { settings = PreloadedUserSettings.fromJson( diff --git a/src/api/routes/users/@me/settings-proto/2.ts b/src/api/routes/users/@me/settings-proto/2.ts
index d162715d..efc92faa 100644 --- a/src/api/routes/users/@me/settings-proto/2.ts +++ b/src/api/routes/users/@me/settings-proto/2.ts
@@ -137,8 +137,7 @@ async function patchUserSettings(userId: string, updatedSettings: FrecencyUserSe }; } - if (EnvConfig.get().logging.logProtoUpdates.includes("FRECENCY")) - console.log(`Updating frecency settings for user ${userId} with atomic=${atomic}:`, updatedSettings); + if (EnvConfig.get().logging.logProtoUpdates.includes("FRECENCY")) console.log(`Updating frecency settings for user ${userId} with atomic=${atomic}:`, updatedSettings); if (!atomic) { settings = FrecencyUserSettings.fromJson( diff --git a/src/cdn/util/Storage.ts b/src/cdn/util/Storage.ts
index 1b02eb11..522a961d 100644 --- a/src/cdn/util/Storage.ts +++ b/src/cdn/util/Storage.ts
@@ -33,7 +33,7 @@ export interface Storage { let storage: Storage; -if (EnvConfig.get().cdn.storageProvider === "file" || !EnvConfig.get().cdn.storageProvider ) { +if (EnvConfig.get().cdn.storageProvider === "file" || !EnvConfig.get().cdn.storageProvider) { let location = EnvConfig.get().cdn.storageLocation; if (location) { location = path.resolve(location); diff --git a/src/gateway/events/Connection.ts b/src/gateway/events/Connection.ts
index 3e7e2f3a..ca4770b2 100644 --- a/src/gateway/events/Connection.ts +++ b/src/gateway/events/Connection.ts
@@ -79,18 +79,11 @@ export async function Connection(this: WS.Server, socket: WebSocket, request: In console.log(`[Gateway] New connection from ${ipAddress}, total ${this.clients.size}`); if (EnvConfig.get().logging.gatewayLogging.logHttp) - [ - "close", - "error", - "upgrade", - "open", - "ping", - "pong", - "unexpected-response", - ...(EnvConfig.get().logging.gatewayLogging.logHttpMessages ? ["message"] : []), - ].forEach((x) => { - socket.on(x, (y) => console.log(x, y)); - }); + ["close", "error", "upgrade", "open", "ping", "pong", "unexpected-response", ...(EnvConfig.get().logging.gatewayLogging.logHttpMessages ? ["message"] : [])].forEach( + (x) => { + socket.on(x, (y) => console.log(x, y)); + }, + ); const { searchParams } = new URL(`http://localhost${request.url}`); // @ts-ignore diff --git a/src/gateway/opcodes/Identify.ts b/src/gateway/opcodes/Identify.ts
index 86a41124..2e77c622 100644 --- a/src/gateway/opcodes/Identify.ts +++ b/src/gateway/opcodes/Identify.ts
@@ -728,5 +728,8 @@ export async function onIdentify(this: WebSocket, data: Payload) { const setupListenerTime = Date.now(); - console.log(`[Gateway] IDENTIFY ${this.user_id} in ${totalSw.elapsed().totalMilliseconds}ms`, EnvConfig.get().logging.gatewayLogging.logTraces ? JSON.stringify(d._trace, null, 2) : ""); + console.log( + `[Gateway] IDENTIFY ${this.user_id} in ${totalSw.elapsed().totalMilliseconds}ms`, + EnvConfig.get().logging.gatewayLogging.logTraces ? JSON.stringify(d._trace, null, 2) : "", + ); } diff --git a/src/renderEnvConfigSchema.ts b/src/renderEnvConfigSchema.ts
index e4d630e1..492e3774 100755 --- a/src/renderEnvConfigSchema.ts +++ b/src/renderEnvConfigSchema.ts
@@ -12,16 +12,16 @@ const schema = EnvConfig.schema(); const keyMap = [ { name: "Name", - selector: (v: {key: string}) => v.key + selector: (v: { key: string }) => v.key, }, { name: "Value", - selector: (v: {type: string}) => v.type + selector: (v: { type: string }) => v.type, }, { name: "Description", - selector: (v: {description: string}) => v.description - } + selector: (v: { description: string }) => v.description, + }, ]; // --- separators const startOfLine = dim("| "); // <tr> @@ -32,7 +32,7 @@ const headSeparator = dim("-"); const pad = true; // --- do not touch -const colWidths: {[key: string]: number} = {}; +const colWidths: { [key: string]: number } = {}; console.log(bgRedBright("Calculating column widths")); for (const key of keyMap) { @@ -72,4 +72,4 @@ for (const entry of schema) { process.stdout.write(cell); } process.stdout.write(endOfLine); -} \ No newline at end of file +} 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 +} diff --git a/src/webrtc/events/Connection.ts b/src/webrtc/events/Connection.ts
index d76b5bf0..27a8189f 100644 --- a/src/webrtc/events/Connection.ts +++ b/src/webrtc/events/Connection.ts
@@ -36,18 +36,11 @@ export async function Connection(this: WS.Server, socket: WebRtcWebSocket, reque console.log("[WebRTC] new connection", request.url); if (EnvConfig.get().logging.gatewayLogging.logHttp) { - [ - "close", - "error", - "upgrade", - "open", - "ping", - "pong", - "unexpected-response", - ...(EnvConfig.get().logging.gatewayLogging.logHttpMessages ? ["message"] : []), - ].forEach((x) => { - socket.on(x, (y) => console.log("[WebRTC]", x, y)); - }); + ["close", "error", "upgrade", "open", "ping", "pong", "unexpected-response", ...(EnvConfig.get().logging.gatewayLogging.logHttpMessages ? ["message"] : [])].forEach( + (x) => { + socket.on(x, (y) => console.log("[WebRTC]", x, y)); + }, + ); } const { searchParams } = new URL(`http://localhost${request.url}`); diff --git a/src/webrtc/util/Send.ts b/src/webrtc/util/Send.ts
index c97a2bdc..b3161f94 100644 --- a/src/webrtc/util/Send.ts +++ b/src/webrtc/util/Send.ts
@@ -24,10 +24,7 @@ export async function Send(socket: WebRtcWebSocket, data: VoicePayload) { await fs.mkdir(path.join(dumpPath!, id), { recursive: true, }); - await fs.writeFile( - path.join(dumpPath!, id, `${Date.now()}.out.json`), - JSON.stringify(data, null, 2), - ); + await fs.writeFile(path.join(dumpPath!, id, `${Date.now()}.out.json`), JSON.stringify(data, null, 2)); } let buffer: Buffer | string;