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:
spiral 2021-08-25 21:43:31 -04:00
parent f912805ecc
commit 4b944e2b20
No known key found for this signature in database
GPG key ID: A6059F0CA0E1BD31
18 changed files with 619 additions and 694 deletions

View file

@ -80,7 +80,7 @@ namespace PluralKit.API
var members = _db.Execute(c => _repo.GetSystemMembers(c, system.Id));
return Ok(await members
.Where(m => m.MemberVisibility.CanAccess(User.ContextFor(system)))
.Select(m => m.ToJson(User.ContextFor(system)))
.Select(m => m.ToJson(User.ContextFor(system), needsLegacyProxyTags: true))
.ToListAsync());
}
@ -126,7 +126,7 @@ namespace PluralKit.API
return Ok(new FrontersReturn
{
Timestamp = sw.Timestamp,
Members = await members.Select(m => m.ToJson(User.ContextFor(system))).ToListAsync()
Members = await members.Select(m => m.ToJson(User.ContextFor(system), needsLegacyProxyTags: true)).ToListAsync()
});
}
@ -141,13 +141,13 @@ namespace PluralKit.API
try
{
patch = SystemPatch.FromJSON(changes);
patch.CheckIsValid();
patch.AssertIsValid();
}
catch (JsonModelParseError e)
catch (FieldTooLongError e)
{
return BadRequest(e.Message);
}
catch (InvalidPatchException e)
catch (ValidationError e)
{
return BadRequest($"Request field '{e.Message}' is invalid.");
}