mirror of
https://github.com/PluralKit/PluralKit.git
synced 2026-02-08 06:47:56 +00:00
feat: refactor external input handling code
- refactor import/export code - make import/export use the same JSON parsing as API - make Patch.AssertIsValid actually useful
This commit is contained in:
parent
f912805ecc
commit
4b944e2b20
18 changed files with 619 additions and 694 deletions
|
|
@ -1,5 +1,7 @@
|
|||
using System;
|
||||
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
namespace PluralKit.Core
|
||||
{
|
||||
public enum PrivacyLevel
|
||||
|
|
@ -41,13 +43,16 @@ namespace PluralKit.Core
|
|||
|
||||
public static string ToJsonString(this PrivacyLevel level) => level.LevelName();
|
||||
|
||||
public static PrivacyLevel ParsePrivacy(this string input, string errorName)
|
||||
public static PrivacyLevel ParsePrivacy(this JObject o, string propertyName)
|
||||
{
|
||||
var input = o.Value<string>(propertyName);
|
||||
|
||||
if (input == null) return PrivacyLevel.Public;
|
||||
if (input == "") return PrivacyLevel.Private;
|
||||
if (input == "private") return PrivacyLevel.Private;
|
||||
if (input == "public") return PrivacyLevel.Public;
|
||||
throw new JsonModelParseError($"Could not parse {errorName} privacy.");
|
||||
|
||||
throw new ValidationError(propertyName);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue