ソースを参照

brwsimilar输出图片增加图片压缩后缀

dodo hold 3 ヶ月 前
コミット
38f553fa18
1 ファイル変更46 行追加16 行削除
  1. 46 16
      molilian.core/Plus/Alimama/parse.cs

+ 46 - 16
molilian.core/Plus/Alimama/parse.cs

@@ -234,17 +234,25 @@ namespace molilian.core
             result.retry_count = try_count;
             result.commercial = result.success;
 
-            if (result.success && "brwsimilar".Equals(request.RiskStrategy))
-            {
-                // 需要搜同款才进入这个逻辑
-                result.PromotionImg = await InternalCallPromotionQuery(result.pic, request.Oaid, request.Ip);
-            }
-
-
-            if (!result.success)
-            {
-                result.itemName = "点击打开淘宝APP";
-            }
+            if (result.success && "brwsimilar".Equals(request.RiskStrategy))
+            {
+                // 需要搜同款才进入这个逻辑
+                result.PromotionImg = await InternalCallPromotionQuery(result.pic, request.Oaid, request.Ip);
+                //	"pic": "https://img.alicdn.com/i4/6000000004750/O1CN01w4wgqa1kxYS1BadZp_!!6000000004750-0-sm.jpg",
+                //result.pic
+                //result.PromotionImg[*].pic
+                foreach (var item in result.PromotionImg)
+                {
+                    item.pic = NormalizeAlicdnImageUrl(item.pic);
+                }
+            }
+
+            result.pic = NormalizeAlicdnImageUrl(result.pic);
+
+            if (!result.success)
+            {
+                result.itemName = "点击打开淘宝APP";
+            }
             if (string.IsNullOrEmpty(result.itemName) || result.link_type == LinkTypeEnum.profile)
             {
                 result.itemName = "点击打开淘宝APP";
@@ -348,11 +356,33 @@ namespace molilian.core
 
             return [];
         }
-
-        public static bool ContainsTaobaoId(string content, string rawContent)
-        {
-            var match = Regex.Match(content, @"(?<=[?&]id=)\d+(?=&|$)");
-            if (!match.Success) return false;
+
+        private static string NormalizeAlicdnImageUrl(string pic)
+        {
+            const string formatSuffix = "_400x400q90.jpg_.webp";
+
+            if (string.IsNullOrWhiteSpace(pic))
+            {
+                return pic;
+            }
+
+            if (!pic.Contains("img.alicdn.com", StringComparison.OrdinalIgnoreCase))
+            {
+                return pic;
+            }
+
+            if (pic.Contains(formatSuffix, StringComparison.OrdinalIgnoreCase))
+            {
+                return pic;
+            }
+
+            return $"{pic}{formatSuffix}";
+        }
+
+        public static bool ContainsTaobaoId(string content, string rawContent)
+        {
+            var match = Regex.Match(content, @"(?<=[?&]id=)\d+(?=&|$)");
+            if (!match.Success) return false;
 
             string id = match.Value;
             return Regex.IsMatch(rawContent, $@"(^|\D){id}($|\D)");