From a3d9669b281f1a2a8f3a9ae3fbb9fa01dee2a5bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patryk=20Kore=C5=84?= Date: Sun, 13 Sep 2026 18:08:37 +0200 Subject: [PATCH] Fix startup crash from a circular DATA_DIR import. Soundboard loaded main before DATA_DIR was initialized, so path.join got undefined and the container looped. Co-authored-by: Cursor --- src/config.ts | 5 +++++ src/main.ts | 4 ++-- src/soundboard.ts | 2 +- src/util/downloader.ts | 3 ++- src/util/history.ts | 2 +- 5 files changed, 11 insertions(+), 5 deletions(-) create mode 100644 src/config.ts diff --git a/src/config.ts b/src/config.ts new file mode 100644 index 0000000..068bf10 --- /dev/null +++ b/src/config.ts @@ -0,0 +1,5 @@ +import dotenv from "dotenv"; +dotenv.config(); + +export const DATA_DIR = process.env.DATA_DIR ?? "./data"; +export const HISTORY_DIR_PATH = process.env.HISTORY_DIR_PATH ?? "./history"; diff --git a/src/main.ts b/src/main.ts index 25bc100..ef81fdb 100644 --- a/src/main.ts +++ b/src/main.ts @@ -8,9 +8,9 @@ import { handleSoundboardButton } from "./soundboard"; import { AudioPlayerStatus, AudioPlayerState, createAudioPlayer } from '@discordjs/voice'; import { updatePlayer } from './playback'; import SpotifyWebApi from 'spotify-web-api-node'; +import { DATA_DIR, HISTORY_DIR_PATH } from './config'; -export const DATA_DIR = "./data"; -export const HISTORY_DIR_PATH = process.env.HISTORY_DIR_PATH ?? "./history"; +export { DATA_DIR, HISTORY_DIR_PATH }; // AUDIO export const player = createAudioPlayer(); diff --git a/src/soundboard.ts b/src/soundboard.ts index dd4bb38..6fec8e7 100644 --- a/src/soundboard.ts +++ b/src/soundboard.ts @@ -14,7 +14,7 @@ import { MessageFlags, parseEmoji, } from "discord.js"; -import { DATA_DIR } from "./main"; +import { DATA_DIR } from "./config"; import { connectToChannelByInteraction } from "./util/helpers"; import { playSoundboardFile } from "./playback"; import { PRIMARY_COLOR } from "./theme"; diff --git a/src/util/downloader.ts b/src/util/downloader.ts index f0969fd..17620b6 100644 --- a/src/util/downloader.ts +++ b/src/util/downloader.ts @@ -1,6 +1,7 @@ import { spawn } from "node:child_process"; import fs from "node:fs"; -import { DATA_DIR, spotify } from "../main"; +import { DATA_DIR } from "../config"; +import { spotify } from "../main"; import ytSearch from 'yt-search'; function ytDlpBin() { diff --git a/src/util/history.ts b/src/util/history.ts index b28ecef..bd8be26 100644 --- a/src/util/history.ts +++ b/src/util/history.ts @@ -1,6 +1,6 @@ import path from "node:path"; import fs from "node:fs"; -import { HISTORY_DIR_PATH } from "../main"; +import { HISTORY_DIR_PATH } from "../config"; export async function add_to_history(data: HistoryObject) { try {