[CHANGE] Reworked cipher stuff
This commit is contained in:
27
Manager.YouTube/Util/Converters/JsonUrlEscapeConverter.cs
Normal file
27
Manager.YouTube/Util/Converters/JsonUrlEscapeConverter.cs
Normal file
@@ -0,0 +1,27 @@
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace Manager.YouTube.Util.Converters;
|
||||
|
||||
public partial class JsonUrlEscapeConverter : JsonConverter<string>
|
||||
{
|
||||
public override string? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
|
||||
{
|
||||
var url = reader.GetString();
|
||||
if (string.IsNullOrWhiteSpace(url))
|
||||
{
|
||||
return url;
|
||||
}
|
||||
|
||||
return UrlPatternRegex().IsMatch(url) ? Uri.UnescapeDataString(url) : url;
|
||||
}
|
||||
|
||||
public override void Write(Utf8JsonWriter writer, string value, JsonSerializerOptions options)
|
||||
{
|
||||
writer.WriteStringValue(value);
|
||||
}
|
||||
|
||||
[GeneratedRegex("^(https?|ftp)://", RegexOptions.IgnoreCase | RegexOptions.Compiled, "nl-NL")]
|
||||
private static partial Regex UrlPatternRegex();
|
||||
}
|
||||
Reference in New Issue
Block a user