From f5924011b5d658558808b5ae1ec4d49c2e18bbc8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=92=D0=B8=D0=BA=D1=82=D0=BE=D1=80?= <78488229+viktor138irk@users.noreply.github.com> Date: Mon, 11 May 2026 22:38:36 +0900 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D1=8B=20=D0=BD=D0=B0=D1=81=D1=82=D1=80=D0=BE=D0=B9=D0=BA?= =?UTF-8?q?=D0=B8=20SOCKS5=20proxy?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/config_store.py | 46 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/backend/config_store.py b/backend/config_store.py index d78ad91..284dc4d 100644 --- a/backend/config_store.py +++ b/backend/config_store.py @@ -55,3 +55,49 @@ def get_openai_key() -> Optional[str]: def get_openai_model() -> str: return get_setting('OPENAI_MODEL') or os.getenv('OPENAI_MODEL') or 'gpt-5' + + +def get_proxy_config() -> dict: + return { + 'enabled': (get_setting('PROXY_ENABLED') or os.getenv('PROXY_ENABLED') or '0') == '1', + 'host': get_setting('PROXY_HOST') or os.getenv('PROXY_HOST') or '', + 'port': get_setting('PROXY_PORT') or os.getenv('PROXY_PORT') or '', + 'username': get_setting('PROXY_USERNAME') or os.getenv('PROXY_USERNAME') or '', + 'password': get_setting('PROXY_PASSWORD') or os.getenv('PROXY_PASSWORD') or '', + } + + +def get_proxy_public_config() -> dict: + proxy = get_proxy_config() + return { + 'enabled': proxy['enabled'], + 'host': proxy['host'], + 'port': proxy['port'], + 'username': proxy['username'], + 'password_set': bool(proxy['password']), + } + + +def build_proxy_url() -> Optional[str]: + proxy = get_proxy_config() + + if not proxy['enabled']: + return None + + host = proxy['host'].strip() + port = str(proxy['port']).strip() + + if not host or not port: + return None + + username = proxy['username'].strip() + password = proxy['password'] + + auth = '' + if username: + auth = username + if password: + auth += f':{password}' + auth += '@' + + return f'socks5://{auth}{host}:{port}'