QChatGPT/pkg/utils/proxy.py

32 lines
910 B
Python
Raw Normal View History

2024-01-29 21:22:27 +08:00
from __future__ import annotations
2024-02-06 21:26:03 +08:00
import os
import sys
2024-01-29 21:22:27 +08:00
from ..core import app
class ProxyManager:
ap: app.Application
forward_proxies: dict[str, str]
def __init__(self, ap: app.Application):
self.ap = ap
self.forward_proxies = {}
async def initialize(self):
2024-02-06 21:26:03 +08:00
self.forward_proxies = {
2024-02-07 23:58:22 +08:00
"http://": os.getenv("HTTP_PROXY") or os.getenv("http_proxy"),
"https://": os.getenv("HTTPS_PROXY") or os.getenv("https_proxy"),
2024-02-06 21:26:03 +08:00
}
if 'http' in self.ap.system_cfg.data['network-proxies']:
2024-02-07 23:58:22 +08:00
self.forward_proxies['http://'] = self.ap.system_cfg.data['network-proxies']['http']
2024-02-06 21:26:03 +08:00
if 'https' in self.ap.system_cfg.data['network-proxies']:
2024-02-07 23:58:22 +08:00
self.forward_proxies['https://'] = self.ap.system_cfg.data['network-proxies']['https']
2024-02-06 21:26:03 +08:00
def get_forward_proxies(self) -> dict:
2024-02-07 23:58:22 +08:00
return self.forward_proxies.copy()