diff --git a/ProjectLighthouse/Controllers/GameApi/ReportController.cs b/ProjectLighthouse/Controllers/GameApi/ReportController.cs index 4b0a37da..a7c482fb 100644 --- a/ProjectLighthouse/Controllers/GameApi/ReportController.cs +++ b/ProjectLighthouse/Controllers/GameApi/ReportController.cs @@ -43,7 +43,7 @@ public class ReportController : ControllerBase report.Bounds = JsonSerializer.Serialize(report.XmlBounds.Rect, typeof(Rectangle)); report.Players = JsonSerializer.Serialize(report.XmlPlayers, typeof(ReportPlayer[])); - report.VisiblePlayers = JsonSerializer.Serialize(report.XmlVisiblePlayers, typeof(VisiblePlayer[])); + // report.VisiblePlayers = JsonSerializer.Serialize(report.XmlVisiblePlayers, typeof(VisiblePlayer[])); report.Timestamp = TimeHelper.UnixTimeMilliseconds(); report.ReportingPlayerId = user.UserId; diff --git a/ProjectLighthouse/Controllers/Website/Admin/AdminReportController.cs b/ProjectLighthouse/Controllers/Website/Admin/AdminReportController.cs new file mode 100644 index 00000000..cca8a86e --- /dev/null +++ b/ProjectLighthouse/Controllers/Website/Admin/AdminReportController.cs @@ -0,0 +1,55 @@ +#nullable enable +using System.Collections.Generic; +using System.IO; +using System.Threading.Tasks; +using LBPUnion.ProjectLighthouse.Types; +using LBPUnion.ProjectLighthouse.Types.Reports; +using Microsoft.AspNetCore.Mvc; +using Microsoft.EntityFrameworkCore; + +namespace LBPUnion.ProjectLighthouse.Controllers.Website.Admin; + +[ApiController] +[Route("admin/report/{id:int}")] +public class AdminReportController : ControllerBase +{ + private readonly Database database; + + public AdminReportController(Database database) + { + this.database = database; + } + + [HttpGet("remove")] + public async Task DeleteReport([FromRoute] int id) + { + User? user = this.database.UserFromWebRequest(this.Request); + if (user == null || !user.IsAdmin) return this.StatusCode(403, ""); + + GriefReport? report = await this.database.Reports.FirstOrDefaultAsync(r => r.ReportId == id); + if (report == null) return this.NotFound(); + + List hashes = new() + { + report.JpegHash, + report.GriefStateHash, + report.InitialStateHash, + }; + foreach (string hash in hashes) + { + if (System.IO.File.Exists($"png{Path.DirectorySeparatorChar}{hash}")) + { + System.IO.File.Delete($"png{Path.DirectorySeparatorChar}{hash}"); + } + if (System.IO.File.Exists($"r{Path.DirectorySeparatorChar}{hash}")) + { + System.IO.File.Delete($"r{Path.DirectorySeparatorChar}{hash}"); + } + } + this.database.Reports.Remove(report); + + await this.database.SaveChangesAsync(); + + return this.Redirect("~/reports/0"); + } +} \ No newline at end of file diff --git a/ProjectLighthouse/Pages/ReportsPage.cshtml b/ProjectLighthouse/Pages/ReportsPage.cshtml index f2e8844e..d2693b79 100644 --- a/ProjectLighthouse/Pages/ReportsPage.cshtml +++ b/ProjectLighthouse/Pages/ReportsPage.cshtml @@ -46,6 +46,9 @@
Level type: @report.LevelType
Level owner: @report.LevelOwner
Hover to see reported region
+ + +