From e0fd88f3c2801326fcc936b405b1041826e1c471 Mon Sep 17 00:00:00 2001 From: Anime-Manga <> Date: Sun, 1 Oct 2023 15:31:23 +0000 Subject: [PATCH] Update from https://github.com/Anime-Manga/references/commit/66bc0ca88e755478614941a6fb820f5bf899d503 --- .../Proxy/ProxyManagement.cs | 68 +++++-------------- 1 file changed, 18 insertions(+), 50 deletions(-) diff --git a/src/references/Cesxhin.AnimeManga.Modules/Proxy/ProxyManagement.cs b/src/references/Cesxhin.AnimeManga.Modules/Proxy/ProxyManagement.cs index 4179513..cb13ead 100644 --- a/src/references/Cesxhin.AnimeManga.Modules/Proxy/ProxyManagement.cs +++ b/src/references/Cesxhin.AnimeManga.Modules/Proxy/ProxyManagement.cs @@ -5,63 +5,35 @@ namespace Cesxhin.AnimeManga.Modules.Proxy { - public static class ProxyManagement + public class ProxyManagement { - private static List GetList(string name) - { - var env = Environment.GetEnvironmentVariable(name); - List listEnv = new(); - - if (!string.IsNullOrEmpty(env)) - listEnv.AddRange(env.Split(',')); - - return listEnv; - } - - private static JObject GetBlackList() - { - var blackList = Environment.GetEnvironmentVariable("BLACK_LIST_PROXY"); - var jsonBlackList = new JObject(); - - if (blackList != null) - jsonBlackList = JObject.Parse(blackList); + private string blackList = ""; + private List listProxy = new(); - return jsonBlackList; - } - public static void InitProxy() + public void InitProxy() { var enableProxy = Environment.GetEnvironmentVariable("PROXY_ENABLE") ?? "false"; if (enableProxy == "true") { - var listProxy = System.IO.File.ReadAllText("proxy.txt"); - - Environment.SetEnvironmentVariable("LIST_PROXY", listProxy); + listProxy = System.IO.File.ReadAllText("proxy.txt").Split(",").ToList(); } } - public static List GetAllIP() + public List GetAllIP() { - return GetList("LIST_PROXY"); + return listProxy; } - public static string GetIp(string id) + public string GetIp() { - var enableProxy = Environment.GetEnvironmentVariable("PROXY_ENABLE") ?? "false"; - - if(enableProxy == "true") + if(EnableProxy()) { - var listProxy = GetList("LIST_PROXY"); - var blackProxyJson = GetBlackList(); + var listBlackProxy = blackList.Split(",").ToList(); - if (blackProxyJson.ContainsKey(id)) + foreach (var blackProxy in listBlackProxy) { - var listBlackProxy = ((string)blackProxyJson[id]).Split(",").ToList(); - - foreach (var blackProxy in listBlackProxy) - { - listProxy = listProxy.Where(e => e != blackProxy).ToList(); - } + listProxy = listProxy.Where(e => e != blackProxy).ToList(); } if (listProxy.Count > 0) @@ -73,25 +45,21 @@ public static string GetIp(string id) return null; } - public static bool EnableProxy() + public bool EnableProxy() { var enableProxy = Environment.GetEnvironmentVariable("PROXY_ENABLE") ?? "false"; return enableProxy == "true"; } - public static void BlackListAdd(string ip, string id) + public void BlackListAdd(string ip) { - var jsonBlackList = GetBlackList(); - if (jsonBlackList.ContainsKey(id)) + var list = blackList.Split(",").ToList(); + + if(list.Find(e => e == ip) == null) { - var list = ((string)jsonBlackList[id]).Split(",").ToList(); list.Add(ip); - jsonBlackList[id] = string.Join(",", list); + blackList = string.Join(",", list); } - else - jsonBlackList[id] = ip; - - Environment.SetEnvironmentVariable("BLACK_LIST_PROXY", jsonBlackList.ToString()); } } }