File tree Expand file tree Collapse file tree 1 file changed +19
-2
lines changed
Expand file tree Collapse file tree 1 file changed +19
-2
lines changed Original file line number Diff line number Diff line change @@ -53,6 +53,10 @@ def __init__(self) -> None:
5353 self .global_proxy = copy .copy (global_proxy )
5454 self .global_proxy .pop ('enable' )
5555
56+ self ._proxies_path = get_homedir () / 'config' / 'proxies.json'
57+ self ._proxies : dict [str , Any ] = {}
58+ self ._proxies_last_change : float = 0
59+
5660 @property
5761 def redis (self ) -> Redis : # type: ignore[type-arg]
5862 return Redis (connection_pool = self .redis_pool )
@@ -104,5 +108,18 @@ def get_proxies(self) -> dict[str, Any]:
104108 """
105109 Get the pre-configured proxies from the configuration.
106110 """
107- with (get_homedir () / 'config' / 'proxies.json' ).open ('r' ) as f :
108- return json .load (f )
111+ if not self ._proxies_path .exists ():
112+ self .logger .info ('No proxies configured.' )
113+ return {}
114+ if self ._proxies_path .stat ().st_mtime != self ._proxies_last_change :
115+ self ._proxies_last_change = self ._proxies_path .stat ().st_mtime
116+ try :
117+ with self ._proxies_path .open ('r' ) as f :
118+ self ._proxies = json .load (f )
119+ except json .JSONDecodeError :
120+ self .logger .warning ('Proxies file is not valid JSON.' )
121+ self ._proxies = {}
122+ except Exception as e :
123+ self .logger .warning (f'Error loading proxies file: { e } ' )
124+ self ._proxies = {}
125+ return self ._proxies
You can’t perform that action at this time.
0 commit comments