From 491ab12374b9f4ba190bde9b36d1ddb68ba37edc Mon Sep 17 00:00:00 2001 From: "k.mesniankin" Date: Sat, 2 Nov 2024 23:09:56 +0300 Subject: [PATCH] fix: refactoring configs --- src/config.ts | 38 ++++++++++++++++++++++++++++++++++++++ src/index.ts | 43 ++++++++++++------------------------------- 2 files changed, 50 insertions(+), 31 deletions(-) diff --git a/src/config.ts b/src/config.ts index 6677e10..4c3b703 100644 --- a/src/config.ts +++ b/src/config.ts @@ -11,3 +11,41 @@ dotenv.config({ }); export const config = new ConfigEnv(); + +export const botToken = config.get('BOT_TOKEN', { + required: true, +}); + +export const botApiAddress = config.get('BOT_API_ADDRESS', { + required: true, +}); + +export const botDataPath = config.get('BOT_DATA_PATH', { + default: '/data/bot', +}); + +export const botDataTorrentsPath = config.get('BOT_DATA_TORRENTS_PATH', { + default: '/data/torrents', +}); + +export const rutrackerUsername = config.get('RUTRACKER_USERNAME', { + required: true, +}); + +export const rutrackerPassword = config.get('RUTRACKER_PASSWORD', { + required: true, +}); + +export const qbtWebuiAddress = config.get('QBT_WEB_UI_ADDRESS', { + required: true, +}); + +export const qbtWebuiUsername = config.get('QBT_WEB_UI_USERNAME', { + required: true, +}); + +export const qbtWebuiPassword = config.get('QBT_WEB_UI_PASSWORD', { + required: true, +}); + +export const qbtSavePath = config.get('QBT_SAVE_PATH'); diff --git a/src/index.ts b/src/index.ts index 15254c1..9977168 100644 --- a/src/index.ts +++ b/src/index.ts @@ -6,7 +6,18 @@ import { useFluent } from '@grammyjs/fluent'; import { Bot, GrammyError, HttpError } from 'grammy'; import { TorrentsComposer } from './composers/TorrentsComposer.js'; -import { config } from './config.js'; +import { + botApiAddress, + botDataPath, + botDataTorrentsPath, + botToken, + qbtSavePath, + qbtWebuiAddress, + qbtWebuiPassword, + qbtWebuiUsername, + rutrackerPassword, + rutrackerUsername, +} from './config.js'; import { type MyContext } from './Context.js'; import { fluent } from './fluent.js'; import { logger } from './logger.js'; @@ -14,36 +25,6 @@ import { QBittorrentClient } from './qBittorrent/QBittorrentClient.js'; import { RutrackerSearchEngine } from './searchEngines/RutrackerSearchEngine.js'; import { CookieStorage } from './utils/CookieStorage.js'; -const botToken = config.get('BOT_TOKEN', { - required: true, -}); - -const botApiAddress = config.get('BOT_API_ADDRESS', { - required: true, -}); -const botDataPath = config.get('BOT_DATA_PATH', { - default: '/data/bot', -}); -const botDataTorrentsPath = config.get('BOT_DATA_TORRENTS_PATH', { - default: '/data/torrents', -}); -const rutrackerUsername = config.get('RUTRACKER_USERNAME', { - required: true, -}); -const rutrackerPassword = config.get('RUTRACKER_PASSWORD', { - required: true, -}); -const qbtWebuiAddress = config.get('QBT_WEB_UI_ADDRESS', { - required: true, -}); -const qbtWebuiUsername = config.get('QBT_WEB_UI_USERNAME', { - required: true, -}); -const qbtWebuiPassword = config.get('QBT_WEB_UI_PASSWORD', { - required: true, -}); -const qbtSavePath = config.get('QBT_SAVE_PATH'); - const bot = new Bot(botToken, { client: { apiRoot: botApiAddress,