From b06f232e7bd5fe2584a1e3aff0a38dc8a00953db Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 5 Nov 2021 13:29:54 +0000 Subject: Bump axios from 0.21.1 to 0.21.2 in /src/web Bumps [axios](https://github.com/axios/axios) from 0.21.1 to 0.21.2. - [Release notes](https://github.com/axios/axios/releases) - [Changelog](https://github.com/axios/axios/blob/master/CHANGELOG.md) - [Commits](https://github.com/axios/axios/compare/v0.21.1...v0.21.2) --- updated-dependencies: - dependency-name: axios dependency-type: direct:production ... Signed-off-by: dependabot[bot] --- src/web/package-lock.json | 14 +++++++------- src/web/package.json | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/web/package-lock.json b/src/web/package-lock.json index 8232f422..8ca19195 100644 --- a/src/web/package-lock.json +++ b/src/web/package-lock.json @@ -3298,17 +3298,17 @@ "dev": true }, "axios": { - "version": "0.21.1", - "resolved": "https://registry.npmjs.org/axios/-/axios-0.21.1.tgz", - "integrity": "sha512-dKQiRHxGD9PPRIUNIWvZhPTPpl1rf/OxTYKsqKUDjBwYylTvV7SjSHJb9ratfyzM6wCdLCOYLzs73qpg5c4iGA==", + "version": "0.21.2", + "resolved": "https://registry.npmjs.org/axios/-/axios-0.21.2.tgz", + "integrity": "sha512-87otirqUw3e8CzHTMO+/9kh/FSgXt/eVDvipijwDtEuwbkySWZ9SBm6VEubmJ/kLKEoLQV/POhxXFb66bfekfg==", "requires": { - "follow-redirects": "^1.10.0" + "follow-redirects": "^1.14.0" }, "dependencies": { "follow-redirects": { - "version": "1.14.2", - "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.14.2.tgz", - "integrity": "sha512-yLR6WaE2lbF0x4K2qE2p9PEXKLDjUjnR/xmjS3wHAYxtlsI9MLLBJUZirAHKzUZDGLxje7w/cXR49WOUo4rbsA==" + "version": "1.14.5", + "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.14.5.tgz", + "integrity": "sha512-wtphSXy7d4/OR+MvIFbCVBDzZ5520qV8XfPklSN5QtxuMUJZ+b0Wnst1e1lCDocfzuCkHqj8k0FpZqO+UIaKNA==" } } }, diff --git a/src/web/package.json b/src/web/package.json index 067ebfd2..d20edaab 100644 --- a/src/web/package.json +++ b/src/web/package.json @@ -5,7 +5,7 @@ "homepage": ".", "dependencies": { "@microsoft/signalr": "^5.0.10", - "axios": "^0.21.1", + "axios": "^0.21.2", "react": "^16.8.6", "react-dom": "^16.8.6", "react-router-dom": "^5.0.0", -- cgit v1.2.3 From b30c0810b7396e5a4fb84e19f6ac27785d45a48c Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Fri, 5 Nov 2021 08:52:55 -0500 Subject: add serializer options --- src/slskd/Common/Extensions.cs | 221 +++++++++++++++++++++-------------------- 1 file changed, 116 insertions(+), 105 deletions(-) (limited to 'src') diff --git a/src/slskd/Common/Extensions.cs b/src/slskd/Common/Extensions.cs index 4f2cf29f..30b35d14 100644 --- a/src/slskd/Common/Extensions.cs +++ b/src/slskd/Common/Extensions.cs @@ -23,6 +23,7 @@ namespace slskd using System.Linq; using System.Reflection; using System.Text.Json; + using System.Text.Json.Serialization; using System.Text.RegularExpressions; /// @@ -30,88 +31,6 @@ namespace slskd /// public static class Extensions { - /// - /// Serializes this object to json. - /// - /// The object to serialize. - /// A string containing the serialized object. - public static string ToJson(this object obj) => JsonSerializer.Serialize(obj); - - /// - /// Deserializes this string from json to an object of type . - /// - /// The type to which to deserialize the string. - /// The string to deserialize. - /// The new object deserialzied from the string. - public static T ToObject(this string str) => JsonSerializer.Deserialize(str); - - /// - /// Recursively retrieves all properties. - /// - /// The type from which to retrieve properties. - /// The list of properties. - public static IEnumerable GetPropertiesRecursively(this Type type) - { - var props = new List(); - - foreach (var prop in type.GetProperties()) - { - if (prop.PropertyType.IsPrimitive || prop.PropertyType.IsArray || Nullable.GetUnderlyingType(prop.PropertyType) != null || new[] { typeof(string), typeof(decimal) }.Contains(prop.PropertyType)) - { - props.Add(prop); - } - else - { - props.AddRange(prop.PropertyType.GetPropertiesRecursively()); - } - } - - return props; - } - - /// - /// Replaces the first occurance of in the string with . - /// - /// The string on which to perform the replacement. - /// The phrase or substring to replace. - /// The replacement string. - /// The string, with the desired phrase replaced. - public static string ReplaceFirst(this string str, string phrase, string replacement) - { - int pos = str.IndexOf(phrase); - - if (pos < 0) - { - return str; - } - - return str.Substring(0, pos) + replacement + str.Substring(pos + phrase.Length); - } - - /// - /// Determines whether the string is a valid regular expression. - /// - /// The string to validate. - /// A value indicating whether the string is a valid regular expression. - public static bool IsValidRegex(this string pattern) - { - if (string.IsNullOrWhiteSpace(pattern)) - { - return false; - } - - try - { - Regex.Match(string.Empty, pattern); - } - catch (ArgumentException) - { - return false; - } - - return true; - } - /// /// Deeply compares this object with the specified object and returns a list of properties that are different. /// @@ -171,14 +90,70 @@ namespace slskd } /// - /// Returns a "pretty" string representation of the provided Type; specifically, corrects the naming of generic Types - /// and appends the type parameters for the type to the name as it appears in the code editor. + /// Recursively retrieves all properties. /// - /// The type for which the colloquial name should be created. - /// A "pretty" string representation of the provided Type. - public static string ToColloquialString(this Type type) + /// The type from which to retrieve properties. + /// The list of properties. + public static IEnumerable GetPropertiesRecursively(this Type type) { - return !type.IsGenericType ? type.Name : type.Name.Split('`')[0] + "<" + string.Join(", ", type.GetGenericArguments().Select(a => a.ToColloquialString())) + ">"; + var props = new List(); + + foreach (var prop in type.GetProperties()) + { + if (prop.PropertyType.IsPrimitive || prop.PropertyType.IsArray || Nullable.GetUnderlyingType(prop.PropertyType) != null || new[] { typeof(string), typeof(decimal) }.Contains(prop.PropertyType)) + { + props.Add(prop); + } + else + { + props.AddRange(prop.PropertyType.GetPropertiesRecursively()); + } + } + + return props; + } + + /// + /// Determines whether the string is a valid regular expression. + /// + /// The string to validate. + /// A value indicating whether the string is a valid regular expression. + public static bool IsValidRegex(this string pattern) + { + if (string.IsNullOrWhiteSpace(pattern)) + { + return false; + } + + try + { + Regex.Match(string.Empty, pattern); + } + catch (ArgumentException) + { + return false; + } + + return true; + } + + /// + /// Replaces the first occurance of in the string with . + /// + /// The string on which to perform the replacement. + /// The phrase or substring to replace. + /// The replacement string. + /// The string, with the desired phrase replaced. + public static string ReplaceFirst(this string str, string phrase, string replacement) + { + int pos = str.IndexOf(phrase); + + if (pos < 0) + { + return str; + } + + return str.Substring(0, pos) + replacement + str.Substring(pos + phrase.Length); } /// @@ -220,6 +195,48 @@ namespace slskd sizeSuffixes[mag]); } + /// + /// Returns a "pretty" string representation of the provided Type; specifically, corrects the naming of generic Types + /// and appends the type parameters for the type to the name as it appears in the code editor. + /// + /// The type for which the colloquial name should be created. + /// A "pretty" string representation of the provided Type. + public static string ToColloquialString(this Type type) + { + return !type.IsGenericType ? type.Name : type.Name.Split('`')[0] + "<" + string.Join(", ", type.GetGenericArguments().Select(a => a.ToColloquialString())) + ">"; + } + + /// + /// Serializes this object to json. + /// + /// The object to serialize. + /// A string containing the serialized object. + public static string ToJson(this object obj) => JsonSerializer.Serialize(obj, GetJsonSerializerOptions()); + + /// + /// Converts a fully qualified remote filename to a local filename based in the provided + /// , swapping directory characters for those specific to the local OS, removing any + /// characters that are invalid for the local OS, and making the path relative to the remote store (including the + /// filename and the parent folder). + /// + /// The fully qualified remote filename to convert. + /// The base directory for the local filename. + /// The converted filename. + public static string ToLocalFilename(this string remoteFilename, string baseDirectory) + { + return Path.Combine(baseDirectory, remoteFilename.ToLocalRelativeFilename()); + } + + /// + /// Converts the given path to the local format (normalizes path separators). + /// + /// The path to convert. + /// The converted path. + public static string ToLocalOSPath(this string path) + { + return path.Replace('\\', Path.DirectorySeparatorChar).Replace('/', Path.DirectorySeparatorChar); + } + /// /// Converts a fully qualified remote filename to a local filename, swapping directory characters for those specific /// to the local OS, removing any characters that are invalid for the local OS, and making the path relative to the @@ -243,26 +260,20 @@ namespace slskd } /// - /// Converts a fully qualified remote filename to a local filename based in the provided , swapping directory characters for those specific - /// to the local OS, removing any characters that are invalid for the local OS, and making the path relative to the - /// remote store (including the filename and the parent folder). + /// Deserializes this string from json to an object of type . /// - /// The fully qualified remote filename to convert. - /// The base directory for the local filename. - /// The converted filename. - public static string ToLocalFilename(this string remoteFilename, string baseDirectory) - { - return Path.Combine(baseDirectory, remoteFilename.ToLocalRelativeFilename()); - } + /// The type to which to deserialize the string. + /// The string to deserialize. + /// The new object deserialzied from the string. + public static T ToObject(this string str) => JsonSerializer.Deserialize(str, GetJsonSerializerOptions()); - /// - /// Converts the given path to the local format (normalizes path separators). - /// - /// The path to convert. - /// The converted path. - public static string ToLocalOSPath(this string path) + private static JsonSerializerOptions GetJsonSerializerOptions() { - return path.Replace('\\', Path.DirectorySeparatorChar).Replace('/', Path.DirectorySeparatorChar); + var options = new JsonSerializerOptions(); + options.Converters.Add(new IPAddressConverter()); + options.Converters.Add(new JsonStringEnumConverter()); + options.IgnoreNullValues = true; + return options; } } } \ No newline at end of file -- cgit v1.2.3