refactor: Remove duplicated code

pull/336/head
Robert Dailey 6 months ago
parent 06b68772bd
commit ee425ff8e0

@ -1,21 +0,0 @@
namespace Recyclarr.Common.Extensions;
public static class ExceptionExtensions
{
public static string FullMessage(this Exception ex)
{
if (ex is AggregateException aex)
{
return aex.InnerExceptions.Aggregate("[ ", (total, next) => $"{total}[{next.FullMessage()}] ") + "]";
}
var msg = ex.Message.Replace(", see inner exception.", "").Trim();
var innerMsg = ex.InnerException?.FullMessage();
if (innerMsg != null && !innerMsg.ContainsIgnoreCase(msg) && !msg.ContainsIgnoreCase(innerMsg))
{
msg = $"{msg} [ {innerMsg} ]";
}
return msg;
}
}

@ -2,7 +2,7 @@
using AutoMapper;
using Recyclarr.Config.Models;
using Recyclarr.Config.Parsing.PostProcessing;
using Recyclarr.Platform;
using Recyclarr.Logging;
using Serilog.Context;
namespace Recyclarr.Config.Parsing;

@ -1,6 +1,6 @@
using Recyclarr.Config.Parsing.PostProcessing.ConfigMerging;
using Recyclarr.Config.Parsing.PostProcessing.Deprecations;
using Recyclarr.Platform;
using Recyclarr.Logging;
using Recyclarr.TrashGuide;
using Serilog.Context;

@ -10,6 +10,7 @@
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Recyclarr.Common\Recyclarr.Common.csproj" />
<ProjectReference Include="..\Recyclarr.Logging\Recyclarr.Logging.csproj" />
<ProjectReference Include="..\Recyclarr.Platform\Recyclarr.Platform.csproj" />
<ProjectReference Include="..\Recyclarr.TrashGuide\Recyclarr.TrashGuide.csproj" />
<ProjectReference Include="..\Recyclarr.Yaml\Recyclarr.Yaml.csproj" />

@ -1,4 +1,5 @@
@page "/"
@using Microsoft.AspNetCore.Mvc.TagHelpers
@namespace Recyclarr.Gui.Pages
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
@{

@ -1,4 +1,5 @@
@using Microsoft.AspNetCore.Components.Web
@using Microsoft.AspNetCore.Mvc.TagHelpers
@namespace Recyclarr.Gui.Pages
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers

@ -1,4 +1,5 @@
using Flurl.Http;
using Recyclarr.Logging;
using Serilog;
namespace Recyclarr.Http;

@ -6,5 +6,6 @@
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Recyclarr.Common\Recyclarr.Common.csproj" />
<ProjectReference Include="..\Recyclarr.Logging\Recyclarr.Logging.csproj" />
</ItemGroup>
</Project>

@ -1,41 +0,0 @@
using System.Text.RegularExpressions;
using Flurl;
using Recyclarr.Common.Extensions;
namespace Recyclarr.Http;
public static partial class Sanitize
{
public static string Message(string message)
{
// Replace full URLs
var result = UrlRegex().Replace(message, SanitizeMatch);
// There are sometimes parenthetical parts of the message that contain the host but are not
// detected as true URLs. Just strip those out completely.
return HostRegex().Replace(result, "");
}
public static string ExceptionMessage(Exception exception)
{
return Message(exception.FullMessage());
}
public static Url Url(Url url)
{
// Replace hostname for user privacy
url.Host = "REDACTED";
return url;
}
private static string SanitizeMatch(Match match)
{
return Url(match.Value).ToString() ?? match.Value;
}
[GeneratedRegex(@"\([-a-zA-Z0-9@:%._+~#=]{1,256}(?::[0-9]+)?\)")]
private static partial Regex HostRegex();
[GeneratedRegex(@"https?://(www\.)?[-a-zA-Z0-9@:%._+~#=]{1,256}(:[0-9]+)?\b([-a-zA-Z0-9()@:%_+.~#?&/=]*)")]
private static partial Regex UrlRegex();
}

@ -1,6 +0,0 @@
namespace Recyclarr.Platform;
public static class LogProperty
{
public static string Scope => nameof(Scope);
}

@ -1,4 +1,5 @@
using System.IO.Abstractions;
using Recyclarr.Logging;
using Recyclarr.Platform;
using Recyclarr.Settings;
using Serilog.Context;

@ -1,6 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<ItemGroup>
<ProjectReference Include="..\Recyclarr.Json\Recyclarr.Json.csproj" />
<ProjectReference Include="..\Recyclarr.Logging\Recyclarr.Logging.csproj" />
<ProjectReference Include="..\Recyclarr.Settings\Recyclarr.Settings.csproj" />
<ProjectReference Include="..\Recyclarr.VersionControl\Recyclarr.VersionControl.csproj" />
</ItemGroup>

@ -1,4 +1,5 @@
using System.IO.Abstractions;
using Recyclarr.Logging;
using Recyclarr.Platform;
using Recyclarr.Settings;
using Serilog.Context;

Loading…
Cancel
Save