Log filter requests

This commit is contained in:
jvyden 2021-10-27 21:29:22 -04:00
commit f36106cc86
No known key found for this signature in database
GPG key ID: 18BCF2BE0262B278
2 changed files with 15 additions and 1 deletions

View file

@ -1,5 +1,7 @@
using System.IO; using System.IO;
using System.Threading.Tasks; using System.Threading.Tasks;
using Kettu;
using LBPUnion.ProjectLighthouse.Logging;
using LBPUnion.ProjectLighthouse.Types; using LBPUnion.ProjectLighthouse.Types;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
@ -32,10 +34,17 @@ namespace LBPUnion.ProjectLighthouse.Controllers {
} }
/// <summary> /// <summary>
/// Filters chat messages sent by a user. /// Filters chat messages sent by a user.
/// The reponse sent is the text that will appear in-game.
/// </summary> /// </summary>
[HttpPost("filter")] [HttpPost("filter")]
public async Task<IActionResult> Filter() { public async Task<IActionResult> Filter() {
return this.Ok(await new StreamReader(this.Request.Body).ReadToEndAsync()); User user = await this.database.UserFromRequest(this.Request);
if(user == null) return this.StatusCode(403, "");
string loggedText = await new StreamReader(this.Request.Body).ReadToEndAsync();
Logger.Log($"{user.Username}: {loggedText}", LoggerLevelFilter.Instance);
return this.Ok(loggedText);
} }
} }
} }

View file

@ -17,6 +17,11 @@ namespace LBPUnion.ProjectLighthouse.Logging {
public static readonly LoggerLevelHttp Instance = new(); public static readonly LoggerLevelHttp Instance = new();
} }
public class LoggerLevelFilter : LoggerLevel {
public override string Name => "Filter";
public static readonly LoggerLevelFilter Instance = new();
}
public class LoggerLevelAspNet : LoggerLevel { public class LoggerLevelAspNet : LoggerLevel {
public override string Name => "AspNet"; public override string Name => "AspNet";