refactor,feat: 批量代码重构与新增业务模块
1. 重命名枚举项与实体字段,修正类型引用 2. 新增IsNull扩展方法与多项字符串处理扩展 3. 新增大量业务DTO、服务接口与枚举定义 4. 重构RabbitMQ服务实现,替换旧版消息队列组件 5. 优化签到服务的宠物喂养事务逻辑 6. 移除冗余的项目引用与旧版消息队列代码 7. 新增Excel导出、导入模板相关工具方法
This commit is contained in:
@ -163,5 +163,55 @@ namespace QYZH.InteractiveMagazine.Common.Extensions
|
||||
// 匹配域名后的路径部分(包括第一个/)
|
||||
return Regex.Replace(str, @"https?://[^/]+/([^""\s<>]*)", "$1");
|
||||
}
|
||||
|
||||
public static string AddDomain(this string str, string domainUrl)
|
||||
{
|
||||
if (string.IsNullOrEmpty(str) || string.IsNullOrEmpty(domainUrl)) return str;
|
||||
|
||||
string pattern = @"src=""([^""]+)""";
|
||||
return Regex.Replace(str, pattern, match =>
|
||||
{
|
||||
string originalUrl = match.Groups[1].Value;
|
||||
// 忽略base64图片
|
||||
if (originalUrl.StartsWith("data:", StringComparison.OrdinalIgnoreCase)) return match.Value; // 返回原样
|
||||
// 如果已经是完整URL则不做处理
|
||||
if (Uri.IsWellFormedUriString(originalUrl, UriKind.Absolute)) return match.Value; // 返回原样
|
||||
|
||||
|
||||
// 处理URL开头可能存在的斜杠
|
||||
var trimmedUrl = originalUrl.StartsWith("/") ? originalUrl.Substring(1) : originalUrl;
|
||||
var trimmedDomain = domainUrl.EndsWith("/") ? domainUrl : domainUrl + "/";
|
||||
|
||||
string newUrl = $"{trimmedDomain}{trimmedUrl}";
|
||||
return $"src=\"{newUrl}\""; // 返回替换后的属性
|
||||
});
|
||||
}
|
||||
|
||||
public static string ToExtension(this string str)
|
||||
{
|
||||
return Regex.Match(str, @"(?<=\.)[a-zA-Z0-9]+$").Value;
|
||||
}
|
||||
|
||||
public static bool NotNull(this string s)
|
||||
{
|
||||
return !string.IsNullOrWhiteSpace(s);
|
||||
}
|
||||
|
||||
public static List<string> AllUrl(this string str, string url = null)
|
||||
{
|
||||
if (string.IsNullOrEmpty(str)) return new List<string>();
|
||||
|
||||
string pattern = @"src=""([^""]+)""";
|
||||
|
||||
var matches = Regex.Matches(str, pattern, RegexOptions.IgnoreCase);
|
||||
|
||||
return matches
|
||||
.Cast<Match>()
|
||||
.Select(m => m.Groups[1].Value)
|
||||
.Where(u => !string.IsNullOrEmpty(u) && !u.StartsWith("data:", StringComparison.OrdinalIgnoreCase)) // 排除base64
|
||||
.Where(url => !string.IsNullOrEmpty(url) && url.StartsWith(url, StringComparison.OrdinalIgnoreCase))
|
||||
//.Where(url => url.StartsWith("https://example.com")) // 二次验证
|
||||
.ToList();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user