Log filter requests

This commit is contained in:
jvyden 2021-10-27 21:29:22 -04:00
parent 2647da0489
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.Threading.Tasks;
using Kettu;
using LBPUnion.ProjectLighthouse.Logging;
using LBPUnion.ProjectLighthouse.Types;
using Microsoft.AspNetCore.Mvc;
@ -32,10 +34,17 @@ namespace LBPUnion.ProjectLighthouse.Controllers {
}
/// <summary>
/// Filters chat messages sent by a user.
/// The reponse sent is the text that will appear in-game.
/// </summary>
[HttpPost("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

@ -16,6 +16,11 @@ namespace LBPUnion.ProjectLighthouse.Logging {
public override string Name => "HTTP";
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 override string Name => "AspNet";