feat: upgrade to .NET 6, refactor everything

This commit is contained in:
spiral
2021-11-26 21:10:56 -05:00
parent d28e99ba43
commit 1918c56937
314 changed files with 27954 additions and 27966 deletions

View File

@@ -1,33 +1,33 @@
using System;
using System.Text.RegularExpressions;
namespace PluralKit.Core
namespace PluralKit.Core;
public static class MiscUtils
{
public static class MiscUtils
// discord mediaproxy URLs used to be stored directly in the database, so now we cleanup image urls before using them outside of proxying
private static readonly Regex MediaProxyUrl =
new(
@"^https?://media.discordapp.net/attachments/(\d{17,19})/(\d{17,19})/([^/\\&\?]+)\.(png|jpg|jpeg|webp)(\?.*)?$");
private static readonly string DiscordCdnReplacement = "https://cdn.discordapp.com/attachments/$1/$2/$3.$4";
public static bool TryMatchUri(string input, out Uri uri)
{
public static bool TryMatchUri(string input, out Uri uri)
try
{
try
{
uri = new Uri(input);
if (!uri.IsAbsoluteUri || (uri.Scheme != "http" && uri.Scheme != "https"))
return false;
}
catch (UriFormatException)
{
uri = null;
uri = new Uri(input);
if (!uri.IsAbsoluteUri || uri.Scheme != "http" && uri.Scheme != "https")
return false;
}
return true;
}
// discord mediaproxy URLs used to be stored directly in the database, so now we cleanup image urls before using them outside of proxying
private static readonly Regex MediaProxyUrl = new Regex(@"^https?://media.discordapp.net/attachments/(\d{17,19})/(\d{17,19})/([^/\\&\?]+)\.(png|jpg|jpeg|webp)(\?.*)?$");
private static readonly string DiscordCdnReplacement = "https://cdn.discordapp.com/attachments/$1/$2/$3.$4";
public static string? TryGetCleanCdnUrl(this string? url)
catch (UriFormatException)
{
return url == null ? null : MediaProxyUrl.Replace(url, DiscordCdnReplacement);
uri = null;
return false;
}
return true;
}
public static string? TryGetCleanCdnUrl(this string? url) =>
url == null ? null : MediaProxyUrl.Replace(url, DiscordCdnReplacement);
}