Ver Fonte

zlong转发增加bili
增加后台提醒异常忽略规则

dodo hold há 3 meses atrás
pai
commit
50015ac30e

+ 23 - 18
molilian.api/Controllers/admin/MessageController.cs

@@ -17,10 +17,11 @@ namespace molilian.api.Controllers
         {
             _accessor = accessor;
         }
-        [HttpGet]
-        public async Task<ActionResult> AccountWarning()
-        {
-            IEnumerable<TkPoolDTO> tb_list = await TkPoolCore.AllListAsync();
+        [HttpGet]
+        public async Task<ActionResult> AccountWarning()
+        {
+            var config = TkConfigCore.Get();
+            IEnumerable<TkPoolDTO> tb_list = await TkPoolCore.AllListAsync();
 
             List<string> typeKeys = new List<string>();
             List<string> riskStrategyKeys = new List<string>();
@@ -46,8 +47,8 @@ namespace molilian.api.Controllers
             }
 
             // 统计 riskStrategyKeys 的在线/离线状态
-            foreach (string riskStrategyKey in riskStrategyKeys)
-            {
+            foreach (string riskStrategyKey in riskStrategyKeys)
+            {
                 // riskStrategyKey 格式为 "riskStrategy-launchScene"
                 string[] parts = riskStrategyKey.Split('-');
                 if (parts.Length >= 2)
@@ -64,10 +65,12 @@ namespace molilian.api.Controllers
 
                         total[riskStrategyKey] = [totalCount, onlineCount];
                     }
-                }
-            }
-
-            IEnumerable<JdPoolDTO> jd_list = await JdPoolCore.AllListAsync();
+                }
+            }
+
+            total = AccountWarningConfigCore.FilterStats("tb", total, config?.account_warning_ignore_groups);
+
+            IEnumerable<JdPoolDTO> jd_list = await JdPoolCore.AllListAsync();
 
             List<string> jdTypeKeys = new List<string>();
             List<string> jdRiskStrategyKeys = new List<string>();
@@ -97,8 +100,8 @@ namespace molilian.api.Controllers
             }
 
             // 统计京东 riskStrategyKeys 的在线/离线状态
-            foreach (string riskStrategyKey in jdRiskStrategyKeys)
-            {
+            foreach (string riskStrategyKey in jdRiskStrategyKeys)
+            {
                 // riskStrategyKey 格式为 "riskStrategy-launchScene"
                 string[] parts = riskStrategyKey.Split('-');
                 if (parts.Length >= 2)
@@ -114,11 +117,13 @@ namespace molilian.api.Controllers
                         int onlineCount = riskAccounts.Count(jd => jd.status);
                         jdTotal[riskStrategyKey] = [totalCount, onlineCount];
                     }
-                }
-            }
-
-
-            return new APIResult(new
+                }
+            }
+
+            jdTotal = AccountWarningConfigCore.FilterStats("jd", jdTotal, config?.account_warning_ignore_groups);
+
+
+            return new APIResult(new
             {
                 data = new
                 {
@@ -134,4 +139,4 @@ namespace molilian.api.Controllers
             return new APIResult(new { data = string.Empty });
         }
     }
-}
+}

Diff do ficheiro suprimidas por serem muito extensas
+ 0 - 0
molilian.api/Properties/PublishProfiles/latest.pubxml.user


+ 55 - 0
molilian.core/Core/AccountWarningConfigCore.cs

@@ -0,0 +1,55 @@
+using System.Collections.Generic;
+using System.Linq;
+
+namespace molilian.core
+{
+    public static class AccountWarningConfigCore
+    {
+        private static readonly char[] Separators = new[] { '\r', '\n', ',', ',', ';', ';' };
+
+        public static Dictionary<string, List<int>> FilterStats(
+            string platform,
+            Dictionary<string, List<int>> stats,
+            string? ignoredGroups)
+        {
+            if (stats == null || stats.Count == 0) return stats ?? new Dictionary<string, List<int>>();
+
+            HashSet<string> rules = ParseIgnoredGroups(ignoredGroups);
+            if (rules.Count == 0) return stats;
+
+            string normalizedPlatform = NormalizeToken(platform);
+            return stats
+                .Where(item => !ShouldIgnore(rules, normalizedPlatform, item.Key))
+                .ToDictionary(item => item.Key, item => item.Value);
+        }
+
+        private static bool ShouldIgnore(HashSet<string> rules, string platform, string groupKey)
+        {
+            string normalizedGroup = NormalizeToken(groupKey);
+            if (string.IsNullOrEmpty(normalizedGroup)) return false;
+
+            return rules.Contains(normalizedGroup) || rules.Contains($"{platform}:{normalizedGroup}");
+        }
+
+        private static HashSet<string> ParseIgnoredGroups(string? ignoredGroups)
+        {
+            if (string.IsNullOrWhiteSpace(ignoredGroups))
+            {
+                return new HashSet<string>(System.StringComparer.OrdinalIgnoreCase);
+            }
+
+            return ignoredGroups
+                .Split(Separators, System.StringSplitOptions.RemoveEmptyEntries | System.StringSplitOptions.TrimEntries)
+                .Select(NormalizeToken)
+                .Where(item => !string.IsNullOrEmpty(item) && !item.StartsWith("#"))
+                .ToHashSet(System.StringComparer.OrdinalIgnoreCase);
+        }
+
+        private static string NormalizeToken(string? value)
+        {
+            return string.IsNullOrWhiteSpace(value)
+                ? string.Empty
+                : value.Trim().ToLowerInvariant();
+        }
+    }
+}

+ 21 - 21
molilian.core/Core/ConfigCore.cs

@@ -1,20 +1,20 @@
-using Microsoft.AspNetCore.Http;
-using Microsoft.AspNetCore.Mvc.Controllers;
-using Microsoft.AspNetCore.Mvc.Filters;
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using dodohold.core;
-using System.Xml.Linq;
+using Microsoft.AspNetCore.Http;
+using Microsoft.AspNetCore.Mvc.Controllers;
+using Microsoft.AspNetCore.Mvc.Filters;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using dodohold.core;
+using System.Xml.Linq;
 
 
 namespace molilian.core
 {
-    public partial class TkConfigCore
-    {
-        private static readonly object _lockObj = new();
-        private static TkConfigDTO _cached;
+    public partial class TkConfigCore
+    {
+        private static readonly object _lockObj = new();
+        private static TkConfigDTO _cached;
 
 
         public static TkConfigDTO Get(bool force = false)
@@ -37,11 +37,11 @@ namespace molilian.core
             _cached = item;
             return item;
         }
-        public static void Refresh()
-        {
-            _ = Get(true);
-        }
-
-    }
-
-}
+        public static void Refresh()
+        {
+            _ = Get(true);
+        }
+
+    }
+
+}

+ 9 - 18
molilian.core/Core/taoke/UnionParseCore/UnionParseCore.cs

@@ -58,27 +58,18 @@ namespace molilian.core
                         "jd" => await GoodsJdParseAsync(request),
                         "pdd" => await GoodsPddParseAsync(request),
                     };
-            }
-
-            var config = TkConfigCore.Get();
-
-            string[] enabledForwardChannels = $"{config.webook_forward_zlong}".Split(',', StringSplitOptions.RemoveEmptyEntries);
+            }
 
-            switch (request.Channel)
+            var config = TkConfigCore.Get();
+
+            if (ZlongForwardChannels.IsEnabled($"{config.webook_forward_zlong}", request.Channel)
+                && !string.IsNullOrEmpty(request.Oaid))
             {
-                case "xhs":
-                case "ks":
-                    if (Array.Exists(enabledForwardChannels, item =>
-                            string.Equals(item.Trim(), request.Channel, StringComparison.OrdinalIgnoreCase))
-                        && !string.IsNullOrEmpty(request.Oaid))
-                    {
-                        _ = ZlongForwardCore.ForwardAsync(request.Channel, request.Oaid);
-                    }
-                    break;
+                _ = ZlongForwardCore.ForwardAsync(request.Channel, request.Oaid);
             }
-
-            return request.Channel switch
-            {
+
+            return request.Channel switch
+            {
                 //"wemeet" => await WemeetParseAsync(request),
                 //"bdpan" => await PanParseAsync(request),
                 "jd" => await JdParseAsync(request),

+ 70 - 0
molilian.core/Core/taoke/UnionParseCore/ZlongForwardChannels.cs

@@ -0,0 +1,70 @@
+namespace molilian.core
+{
+    internal static class ZlongForwardChannels
+    {
+        public const string LegacyChannel = "xhs";
+        public static readonly string[] Supported = new[] { "xhs", "ks", "bili" };
+
+        public static string NormalizeChannel(string channel)
+        {
+            if (string.IsNullOrWhiteSpace(channel)) return string.Empty;
+
+            string normalized = channel.Trim().ToLowerInvariant();
+            return Array.Exists(Supported, item => string.Equals(item, normalized, StringComparison.OrdinalIgnoreCase))
+                ? normalized
+                : string.Empty;
+        }
+
+        public static string[] NormalizeChannels(string channels, bool fallbackToAll = true)
+        {
+            if (string.IsNullOrWhiteSpace(channels))
+            {
+                return fallbackToAll ? Supported.ToArray() : Array.Empty<string>();
+            }
+
+            var list = new List<string>();
+            foreach (var item in channels.Split(',', StringSplitOptions.RemoveEmptyEntries))
+            {
+                string value = item.Trim();
+                if (string.Equals(value, "all", StringComparison.OrdinalIgnoreCase))
+                {
+                    return Supported.ToArray();
+                }
+
+                string normalized = NormalizeChannel(value);
+                if (string.IsNullOrEmpty(normalized) || list.Contains(normalized)) continue;
+
+                list.Add(normalized);
+            }
+
+            if (list.Count > 0) return list.ToArray();
+            return fallbackToAll ? Supported.ToArray() : Array.Empty<string>();
+        }
+
+        public static bool IsEnabled(string channels, string channel)
+        {
+            string normalizedChannel = NormalizeChannel(channel);
+            if (string.IsNullOrEmpty(normalizedChannel)) return false;
+
+            return Array.Exists(
+                NormalizeChannels(channels, fallbackToAll: false),
+                item => string.Equals(item, normalizedChannel, StringComparison.OrdinalIgnoreCase)
+            );
+        }
+
+        public static int GetSortOrder(string channel)
+        {
+            string normalizedChannel = NormalizeChannel(channel);
+            if (string.IsNullOrEmpty(normalizedChannel)) return Supported.Length;
+
+            int index = Array.IndexOf(Supported, normalizedChannel);
+            return index >= 0 ? index : Supported.Length;
+        }
+
+        public static bool UsesLegacyKeys(string channel)
+        {
+            string normalizedChannel = NormalizeChannel(channel);
+            return string.Equals(normalizedChannel, LegacyChannel, StringComparison.OrdinalIgnoreCase);
+        }
+    }
+}

+ 6 - 28
molilian.core/Core/taoke/UnionParseCore/ZlongForwardCore.cs

@@ -11,7 +11,6 @@ namespace molilian.core
         public const string ExceptionRedisPrefix = $"{RedisPrefix}:exception";
         private const string ExceptionAggregateType = "all";
         private const string ForwardUrlTemplate = "https://tracker.z-long.cn/ad/tracker/special/liutiyun/{0}";
-        private static readonly string[] SupportedChannels = new[] { "xhs", "ks" };
         private static readonly HttpClient HttpClient = new()
         {
             Timeout = TimeSpan.FromSeconds(10)
@@ -101,7 +100,7 @@ namespace molilian.core
                     list.Add(item);
                 }
 
-                if (!string.Equals(channel, "xhs", StringComparison.OrdinalIgnoreCase)) continue;
+                if (!ZlongForwardChannels.UsesLegacyKeys(channel)) continue;
 
                 string[] legacyKeys = await TkLogCore.GetTotalKeysAsync(GetLegacyIndexKey(normalizedBucketType)) ?? Array.Empty<string>();
                 foreach (var key in legacyKeys)
@@ -194,7 +193,7 @@ namespace molilian.core
 
                 tasks.Add(TkLogCore.GetTotalAsync(key));
 
-                if (!string.Equals(channel, "xhs", StringComparison.OrdinalIgnoreCase)) continue;
+                if (!ZlongForwardChannels.UsesLegacyKeys(channel)) continue;
 
                 string legacyKey = isException
                     ? GetLegacyExceptionCountKey(ExceptionAggregateType, bucketType, bucketValue)
@@ -251,38 +250,17 @@ namespace molilian.core
 
         private static string[] NormalizeChannels(string channels)
         {
-            if (string.IsNullOrWhiteSpace(channels)) return SupportedChannels;
-
-            var list = new List<string>();
-            foreach (var item in channels.Split(',', StringSplitOptions.RemoveEmptyEntries))
-            {
-                string normalized = item.Trim().ToLowerInvariant();
-                if (string.Equals(normalized, "all", StringComparison.OrdinalIgnoreCase))
-                {
-                    return SupportedChannels;
-                }
-
-                normalized = NormalizeChannel(normalized);
-                if (string.IsNullOrEmpty(normalized) || list.Contains(normalized)) continue;
-
-                list.Add(normalized);
-            }
-
-            return list.Count > 0 ? list.ToArray() : SupportedChannels;
+            return ZlongForwardChannels.NormalizeChannels(channels);
         }
 
         private static string NormalizeChannel(string channel)
         {
-            if (string.IsNullOrWhiteSpace(channel)) return string.Empty;
-
-            string normalized = channel.Trim().ToLowerInvariant();
-            return SupportedChannels.Contains(normalized) ? normalized : string.Empty;
+            return ZlongForwardChannels.NormalizeChannel(channel);
         }
 
         private static int GetChannelSortOrder(string channel)
         {
-            int index = Array.IndexOf(SupportedChannels, channel);
-            return index >= 0 ? index : SupportedChannels.Length;
+            return ZlongForwardChannels.GetSortOrder(channel);
         }
 
         private static string GetIndexKey(string channel, string bucketType)
@@ -375,7 +353,7 @@ namespace molilian.core
             var parts = key.Split(':', StringSplitOptions.RemoveEmptyEntries);
             if (parts.Length < 4) return false;
 
-            string channel = "xhs";
+            string channel = ZlongForwardChannels.LegacyChannel;
             string bucketType = parts[^2];
             string bucketValue = parts[^1];
             if (parts.Length >= 5)

+ 9 - 8
molilian.core/DTO/alimama/TkConfigDTO.cs

@@ -60,12 +60,13 @@ namespace molilian.core
         public string ksTestToken { get; set; } = string.Empty;
 
 
-        public int dyIgnorePercentage { get; set; } = 0;
-        public string dyIgnorePercentageCity { get; set; } = string.Empty;
-        public int dy_limit_per_ip_24h { get; set; } = 0;
-        public int dy_limit_per_oaid_24h { get; set; } = 0;
+        public int dyIgnorePercentage { get; set; } = 0;
+        public string dyIgnorePercentageCity { get; set; } = string.Empty;
+        public int dy_limit_per_ip_24h { get; set; } = 0;
+        public int dy_limit_per_oaid_24h { get; set; } = 0;
+        public string account_warning_ignore_groups { get; set; } = string.Empty;
         public string webook_forward_zlong { get; set; } = string.Empty;
-
-
-    }
-}
+
+
+    }
+}

Alguns ficheiros não foram mostrados porque muitos ficheiros mudaram neste diff