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/util/util/AutoUpdate.ts | 2 +- src/util/util/Config.ts | 12 ++++++++---- 2 files changed, 9 insertions(+), 5 deletions(-) (limited to 'src/util') diff --git a/src/util/util/AutoUpdate.ts b/src/util/util/AutoUpdate.ts index 769d959f..6fbad63e 100644 --- a/src/util/util/AutoUpdate.ts +++ b/src/util/util/AutoUpdate.ts @@ -60,7 +60,7 @@ async function download(url: string, dir: string) { const response = await fetch(url, { agent }); const buffer = await response.buffer(); const tempDir = await fs.mkdtemp("fosscord"); - fs.writeFile(path.join(tempDir, "Fosscord.zip"), buffer); + await fs.writeFile(path.join(tempDir, "Fosscord.zip"), buffer); } catch (error) { console.error(`[Auto Update] download failed`, error); } diff --git a/src/util/util/Config.ts b/src/util/util/Config.ts index 5d98f5bc..149f3746 100644 --- a/src/util/util/Config.ts +++ b/src/util/util/Config.ts @@ -1,5 +1,6 @@ import { ConfigEntity } from "../entities/Config"; -import fs from "fs"; +import fs from "fs/promises"; +import syncFs from "fs"; import { ConfigValue } from "../config"; // TODO: yaml instead of json @@ -31,11 +32,14 @@ export const Config = { ); try { const overrideConfig = JSON.parse( - fs.readFileSync(overridePath, { encoding: "utf8" }), + await fs.readFile(overridePath, { encoding: "utf8" }), ); config = overrideConfig.merge(config); } catch (error) { - fs.writeFileSync(overridePath, JSON.stringify(config, null, 4)); + await fs.writeFile( + overridePath, + JSON.stringify(config, null, 4), + ); } } @@ -79,7 +83,7 @@ function applyConfig(val: ConfigValue) { } if (process.env.CONFIG_PATH) - fs.writeFileSync(overridePath, JSON.stringify(val, null, 4)); + syncFs.writeFileSync(overridePath, JSON.stringify(val, null, 4)); return apply(val); } -- cgit 1.5.1