浏览代码

deeplink增加 slice_pattern参数

dodo hold 11 月之前
父节点
当前提交
bf8925faab

文件差异内容过多而无法显示
+ 0 - 0
molilian.api/Properties/PublishProfiles/latest.pubxml.user


+ 27 - 4
molilian.core/Core/ProxyNodesCore.cs

@@ -17,9 +17,10 @@ namespace molilian.core
 
         private static readonly object _lockObj = new();
         private static IEnumerable<ProxyNodesDTO> _cached;
-        public static string GetSelectOne(string node)
+        private static IEnumerable<ProxyNodesDTO> _all_cached;
+        public static string GetSelectOne(string node, bool all_node = false)
         {
-            var list = List();
+            var list = all_node ? AllList() : List();
             if (!list.Any()) return null;
             if (!node.Contains(",")) return node;
 
@@ -40,9 +41,9 @@ namespace molilian.core
         }
 
 
-        public static WebProxy? GetOne(string node)
+        public static WebProxy? GetOne(string node, bool all_node = false)
         {
-            var list = List();
+            var list = all_node ? AllList() : List();
             if (!list.Any()) return null;
 
             // 处理包含逗号的节点参数
@@ -158,9 +159,31 @@ namespace molilian.core
             _cached = list;
             return list;
         }
+
+        public static IEnumerable<ProxyNodesDTO> AllList(bool force = false)
+        {
+            if (!force && _all_cached != null) return _all_cached;
+
+            string cache_key = $"cache:all_proxy_nodes";
+            var list = RedisHelper.Get<IEnumerable<ProxyNodesDTO>>(cache_key);
+            if (force || list == null)
+            {
+                lock (_lockObj)
+                {
+                    list = new DBContext.Table("proxy_nodes")
+                        .Where("", new { status = 1 })
+                        .Select<ProxyNodesDTO>();
+                    if (list == null) return default;
+                    RedisHelper.Set(cache_key, list, 30 * 86400);
+                }
+            }
+            _all_cached = list;
+            return list;
+        }
         public static void Refresh()
         {
             _ = List(true);
+            _ = AllList(true);
         }
 
     }

+ 10 - 0
molilian.core/Core/tool/DeeplinkParseCore.cs

@@ -167,6 +167,7 @@ namespace molilian.core
                         }
                         break;
                     case UrlAction.Body:
+                    case UrlAction.JsonBody:
                         {
                             var client = new WebClientUtility
                             {
@@ -202,6 +203,7 @@ namespace molilian.core
 
                             content = response.Body();
                             if (string.IsNullOrEmpty(content)) return null;
+
                         }
                         break;
                     case UrlAction.None:
@@ -215,6 +217,13 @@ namespace molilian.core
             {
                 //Console.WriteLine($"{url}\t{rule.url_action}\t{ex.Message}");
             }
+            if (!string.IsNullOrEmpty(rule.slice_pattern))
+            {
+                var regex = new Regex(rule.slice_pattern);
+                var match = regex.Match(content);
+                if (!match.Success) return null;
+                content = match.Groups[1].Value;
+            }
 
             if (rule.childs.Count > 0)
             {
@@ -227,6 +236,7 @@ namespace molilian.core
             }
 
 
+
             if (!string.IsNullOrEmpty(rule.body_pattern))
             {
                 var regex = new Regex(rule.body_pattern);

+ 4 - 0
molilian.core/DTO/deeplink/DeeplinkParseRuleDTO.cs

@@ -51,6 +51,10 @@ namespace molilian.core
     public class DeeplinkParseRule
     {
         public UrlAction url_action { get; set; } = UrlAction.None;
+        /// <summary>
+        /// 如果url_atciton = 3 ,用来提取body中的json数据,确保输出的是json格式
+        /// </summary>
+        public string slice_pattern { get; set; } = string.Empty;
         public string body_pattern { get; set; } = string.Empty;
         public string url_pattern { get; set; } = string.Empty;
         public string pattern { get; set; } = string.Empty;

+ 6 - 0
molilian.core/Plus/pdd/PddUnionPlus.cs

@@ -155,6 +155,7 @@ namespace molilian.core
                 result.success = false;
                 result.link_type = LinkTypeEnum.unknown;
                 result.channel_type = ChannelTypeEnum.pdd;
+                result.deeplink_url = GetDeeplink(url);
                 result.message = "放弃转链";
                 result.reason = "其他推广链接";
                 result.accountId = 0;
@@ -233,6 +234,11 @@ namespace molilian.core
                     result = await transferUrl(result, url, cancellationToken);
                     break;
             }
+            if (!result.success)
+            {
+                result.shortLinkurl = shortLinkurl;
+                result.deeplink_url = GetDeeplink(shortLinkurl);
+            }
             stopwatch2.Stop();
             result.elapsedTime3 = (int)stopwatch2.ElapsedMilliseconds;
             return result;

+ 2 - 2
molilian.core/Plus/pdd/base.cs

@@ -46,8 +46,8 @@ namespace molilian.core
 
             if (!string.IsNullOrEmpty(account.nodeName))
             {
-                _proxyName = ProxyNodesCore.GetSelectOne(account.nodeName);
-                _proxy = ProxyNodesCore.GetOne(_proxyName);
+                _proxyName = ProxyNodesCore.GetSelectOne(account.nodeName, true);
+                _proxy = ProxyNodesCore.GetOne(_proxyName, true);
             }
         }
 

部分文件因为文件数量过多而无法显示