dodo hold 1 year ago
parent
commit
b0eee71fc5

+ 36 - 0
molilian.api/Controllers/public/TaskController.cs

@@ -457,6 +457,8 @@ namespace molilian.api.Controllers
         public async Task<ActionResult> FastReport()
         {
             string message = string.Empty;
+
+
             var list = TkPoolCore.List();
             if (list != null)
             {
@@ -602,6 +604,40 @@ namespace molilian.api.Controllers
                 if (any_pdd_changed) PddPoolCore.Refresh();
             }
 
+
+
+            var cps_list = new DBContext.Table("cps_links")
+                .Where("status=@status", new { status = 1 })
+                .Select<CpsLinksDTO>();
+
+            if (cps_list != null)
+            {
+                bool any_cps_changed = false;
+                foreach (var link in cps_list)
+                {
+                    bool changed = false;
+                    try
+                    {
+                        link.current_daily_calls = RiskControlCore.GetAllNodesCalls(TkChannelEnum.cps, link.id, DateTime.Now.ToString("yyyyMMdd"));
+                        link.current_hourly_calls = RiskControlCore.GetAllNodesCalls(TkChannelEnum.cps, link.id, DateTime.Now.ToString("yyyyMMddHH"));
+                        changed = true;
+                        any_cps_changed = true;
+                    }
+                    catch (Exception ex)
+                    {
+                        message = $"【Cps计数异常】SaveCalls\n{ex.Message}\n{ex.StackTrace}";
+                        NotifyCore.Notify(new NifyMessage
+                        {
+                            message = message,
+                            priority = NifyMessagePriority.high,
+                            tags = ["red_circle"]
+                        });
+                        continue;
+                    }
+                    if (changed) CpsPoolCore.Update(link);
+                }
+                if (any_cps_changed) CpsPoolCore.Refresh();
+            }
             await EndPointCore.NotifyReload(true);
             return new APIResult(new { success = true, message = "ok" });
         }

File diff suppressed because it is too large
+ 0 - 0
molilian.api/Properties/PublishProfiles/https___ccr.ccs.tencentyun.com_shaobin.pubxml.user


+ 2 - 2
molilian.api/Properties/launchSettings.json

@@ -3,7 +3,7 @@
     "http": {
       "commandName": "Project",
       "launchUrl": "swagger",
-      "environmentVariables2": {
+      "environmentVariables": {
         "ASPNETCORE_ENVIRONMENT": "Development",
         "EndPoint": "admin",
         "NtfyServer": "https://ntfy.yunhui800.com/5Sq9BytXXM5WDY3G",
@@ -14,7 +14,7 @@
         "CenterDB": "",
         "CenterRedis": ""
       },
-      "environmentVariables": {
+      "environmentVariables2": {
         "ASPNETCORE_ENVIRONMENT": "Development",
         "EndPoint": "cadmin",
         "NtfyServer": "https://ntfy.yunhui800.com/5Sq9BytXXM5WDY3G",

+ 37 - 2
molilian.core/Core/cps/CpsPoolCore.cs

@@ -29,7 +29,10 @@ namespace molilian.core
             var links = LinksList();
             if (!links.Any()) return null;
 
-            return links.Where(e => IsEligible(e, channel)).OrderByDescending(e => e.priority_weight).FirstOrDefault();
+            return links.Where(e => IsEligible(e, channel))
+                .OrderByDescending(e => e.priority_weight)
+                .ThenBy(l => Guid.NewGuid())
+                .FirstOrDefault();
         }
 
 
@@ -42,6 +45,18 @@ namespace molilian.core
 
             var now = DateTime.Now;
             if (item.start_time > now || now > item.end_time) return false;
+
+
+            if (item.daily_calls_limit > 0)
+            {
+                int daily_num = RiskControlCore.GetCalls(TkChannelEnum.cps, item.id, DateTime.Now.ToString("yyyyMMdd"));
+                if (daily_num >= item.daily_calls_limit) return false;
+            }
+            if (item.hourly_calls_limit > 0)
+            {
+                int hourly_num = RiskControlCore.GetCalls(TkChannelEnum.cps, item.id, DateTime.Now.ToString("yyyyMMddHH"));
+                if (hourly_num >= item.hourly_calls_limit) return false;
+            }
             return true;
         }
 
@@ -76,9 +91,16 @@ namespace molilian.core
         public static IEnumerable<CpsLinksDTO> LinksList(bool force = false)
         {
 #if DEBUG
-            return new DBContext.Table("cps_links")
+            var list = new DBContext.Table("cps_links")
                         .Where("status=@status", new { status = 1 })
                         .Select<CpsLinksDTO>();
+            foreach (var item in list)
+            {
+                RiskControlCore.SetCalls(TkChannelEnum.cps, item.id, DateTime.Now.ToString("yyyyMMddHH"), item.current_hourly_calls);
+                RiskControlCore.SetCalls(TkChannelEnum.cps, item.id, DateTime.Now.ToString("yyyyMMdd"), item.current_daily_calls);
+            }
+            return list;
+
 #else
             if (!force && _links_cached != null) return _links_cached;
 
@@ -92,6 +114,11 @@ namespace molilian.core
                         .Where("status=@status", new { status = 1 })
                         .Select<CpsLinksDTO>();
                     if (list == null) return default;
+                    foreach (var item in list)
+                    {
+                        RiskControlCore.SetCalls(TkChannelEnum.cps, item.id, DateTime.Now.ToString("yyyyMMddHH"), item.current_hourly_calls);
+                        RiskControlCore.SetCalls(TkChannelEnum.cps, item.id, DateTime.Now.ToString("yyyyMMdd"), item.current_daily_calls);
+                    }
                     RedisHelper.Set(cache_key, list, 30 * 86400);
                 }
             }
@@ -99,6 +126,14 @@ namespace molilian.core
             return list;
 #endif
         }
+        public static int Update(CpsLinksDTO account)
+        {
+            return new DBContext.Table("cps_links")
+                .Add("current_hourly_calls", account.current_hourly_calls)
+                .Add("current_daily_calls", account.current_daily_calls)
+                .Where("id=@id", new { account.id })
+                .Update();
+        }
 
         public static void Refresh()
         {

+ 5 - 1
molilian.core/Core/log/cps.cs

@@ -88,7 +88,11 @@ namespace molilian.core
                 response.elapsedTime = (int)ts.TotalMilliseconds;
                 _ = RedisHelper.RPushAsync(queue_cps_key, response);
 
-                if (response.success) saveClientRequestTotal(response.channel, response.ip, response.oaid);
+                if (response.success)
+                {
+                    RiskControlCore.CallsIncrBy(TkChannelEnum.cps, response.accountId);
+                    saveClientRequestTotal(response.channel, response.ip, response.oaid);
+                }
 
                 if (!response.ip.Contains("127.0.0"))
                 {

+ 9 - 2
molilian.core/Core/tool/DeeplinkParseCore.cs

@@ -393,10 +393,17 @@ namespace molilian.core
                 var ts2 = now - result.create_time;
                 result.elapsedTime2 = (int)ts2.TotalMilliseconds;
                 result = await DyUnionPlus.DyParseAsync(account, matchText, result, cancellationToken);
-                if (!"3B191CFA4C6B48F9BA459E915B57743BEC7D424979CC9C51BCAD0C245B1C7BA2".Equals(oaid))
+                switch (oaid)
                 {
-                    result.deeplink_url = result.deeplink_url.Replace("snssdk1128://", "snssdk561124://");
+                    case "3B191CFA4C6B48F9BA459E915B57743BEC7D424979CC9C51BCAD0C245B1C7BA2":
+                    case "6D5D56F3073844F2912B4552CEDF9E3BEC7D424979CC9C51C5461106F1915660":
+                    case "4CA55979100C4B5BAAA2AF4ABE15C360602e915cedae5786405419ccc9f4e3f8":
+                        break;
+                    default:
+                        result.deeplink_url = result.deeplink_url.Replace("snssdk1128://", "snssdk561124://");
+                        break;
                 }
+
                 var ts3 = DateTime.Now - now;
                 result.elapsedTime3 = (int)ts3.TotalMilliseconds;
             }

+ 1 - 0
molilian.core/DTO/Emun/TkChannelEnum.cs

@@ -10,6 +10,7 @@
         tmall = 5,
         xhs = 6,
         ks = 7,
+        cps = 10,
 
 
 

+ 6 - 0
molilian.core/DTO/cps/CpsPoolDTO.cs

@@ -38,6 +38,12 @@ namespace molilian.core
         public DateTime start_time { get; set; }
         public DateTime end_time { get; set; }
         public int priority_weight { get; set; }
+        public int daily_calls_limit { get; set; }
+        public int hourly_calls_limit { get; set; }
+
+        public int current_hourly_calls { get; set; }
+        public int current_daily_calls { get; set; }
+
         public int time_range { get; set; }
         public string title { get; set; } = string.Empty;
     }

+ 1 - 1
molilian.core/Plus/Alimama/crawler.cs

@@ -350,7 +350,7 @@ namespace molilian.core
 
             var update = new DBContext.Table(center_conn, "api_call_report_dailys")
                 .Add("data_type", data_type)
-                .Add("is_show", 0)
+                .Add("is_show", 1)
                 .Add("report_date", log_date)
                 .Add("last_time", DateTime.Now);
 

Some files were not shown because too many files changed in this diff