mirror of
https://github.com/JogmansonReal/Radicade.git
synced 2026-10-26 07:29:00 -07:00
50 lines
1.3 KiB
C#
50 lines
1.3 KiB
C#
using Microsoft.AspNetCore.Mvc;
|
|
using RadicadeServer.RecNet.Moderation;
|
|
using RadicadeServer.RecNet.Responses;
|
|
using RadicadeServer.Utils;
|
|
using System.Linq;
|
|
|
|
namespace RadicadeServer.API
|
|
{
|
|
[Route("api/sanitize")]
|
|
public class SanitizeAPI : Controller
|
|
{
|
|
[HttpPost("v1/isPure")]
|
|
public IsPureResponse GetIsPure([FromBody] IsPureRequest req)
|
|
{
|
|
if (req.Value == null) return new IsPureResponse { IsPure = false };
|
|
return new IsPureResponse { IsPure = req.Value.IsPure() };
|
|
}
|
|
|
|
[HttpPost("v1")]
|
|
public string GetSanitized([FromBody] SanitizeStringRequest req)
|
|
{
|
|
if (req.Value == null) return "";
|
|
return $"\"{req.Value.Sanitize()}\"";
|
|
}
|
|
|
|
[HttpPost("v2/isAllowed/bulk")]
|
|
public Success IsAllowedBulk()
|
|
{
|
|
var values = ReadBulkValues();
|
|
var arePure = values.Select(value => value.IsPure()).ToList();
|
|
|
|
return new Success(true, null, new { ArePure = arePure });
|
|
}
|
|
|
|
private List<string> ReadBulkValues()
|
|
{
|
|
if (Request.HasFormContentType)
|
|
{
|
|
var form = Request.Form["Values"];
|
|
if (form.Count > 0) return form.Where(value => value != null).Select(value => value!).ToList();
|
|
}
|
|
|
|
var query = Request.Query["Values"];
|
|
if (query.Count > 0) return query.Where(value => value != null).Select(value => value!).ToList();
|
|
|
|
return new List<string>();
|
|
}
|
|
}
|
|
}
|