From 6122374e4d97b2db040e8a98e4187dd0a0bccf9e Mon Sep 17 00:00:00 2001 From: TheArcaneBrony Date: Thu, 12 Jan 2023 13:46:36 +0100 Subject: Dev/post refactor fixes (#927) * Re-introduce outgoing message logging Signed-off-by: TheArcaneBrony * Websocket dumping * Sentry user count on API * Generate session ID upon opening websocket, fix gateway dumps * Async file io in src/gateway/events/Message.ts Signed-off-by: TheArcaneBrony * Async file io in src/util/util/Config.ts Signed-off-by: TheArcaneBrony * Make pre-commit hook executable Signed-off-by: TheArcaneBrony * Fixed sync file io in src/util/util/Config.ts Signed-off-by: TheArcaneBrony * Fixed missing await call in src/util/util/AutoUpdate.ts Signed-off-by: TheArcaneBrony * Add comment to src/gateway/events/Connection.ts Signed-off-by: TheArcaneBrony * Clean up gateway dumping code Signed-off-by: TheArcaneBrony Co-authored-by: Madeline <46743919+MaddyUnderStars@users.noreply.github.com> --- src/gateway/events/Message.ts | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'src/gateway/events/Message.ts') diff --git a/src/gateway/events/Message.ts b/src/gateway/events/Message.ts index 6645dd22..97bbba83 100644 --- a/src/gateway/events/Message.ts +++ b/src/gateway/events/Message.ts @@ -5,6 +5,8 @@ import WS from "ws"; import { PayloadSchema } from "@fosscord/util"; import * as Sentry from "@sentry/node"; import BigIntJson from "json-bigint"; +import path from "path"; +import fs from "fs/promises"; const bigIntJson = BigIntJson({ storeAsString: true }); var erlpack: any; @@ -41,6 +43,21 @@ export async function Message(this: WebSocket, buffer: WS.Data) { if (process.env.WS_VERBOSE) console.log(`[Websocket] Incomming message: ${JSON.stringify(data)}`); + if (process.env.WS_DUMP) { + const id = this.session_id || "unknown"; + + await fs.mkdir(path.join("dump", this.session_id), { recursive: true }); + await fs.writeFile( + path.join("dump", this.session_id, `${Date.now()}.in.json`), + JSON.stringify(data, null, 2), + ); + + if (!this.session_id) + console.log( + "[Gateway] Unknown session id, dumping to unknown folder", + ); + } + check.call(this, PayloadSchema, data); // @ts-ignore -- cgit 1.4.1