From 3269e840600191c0afc427892f3c2f26972bb329 Mon Sep 17 00:00:00 2001 From: Slendy Date: Sun, 13 Feb 2022 18:00:37 -0600 Subject: [PATCH] Make suggested changes --- .../GameApi/Resources/ResourcesController.cs | 2 +- .../Website/Admin/AdminReportController.cs | 10 ++--- .../Controllers/Website/SlotPageController.cs | 6 +-- .../Controllers/Website/UserPageController.cs | 2 +- ProjectLighthouse/Helpers/ImageHelper.cs | 2 +- ProjectLighthouse/Helpers/StatisticsHelper.cs | 2 + .../Pages/Admin/AdminPanelPage.cshtml.cs | 1 + .../Pages/Layouts/BaseLayout.cshtml | 1 - .../Pages/Partials/CommentsPartial.cshtml | 6 ++- ProjectLighthouse/Pages/ReportsPage.cshtml | 8 ++-- ProjectLighthouse/Pages/ReportsPage.cshtml.cs | 2 +- ProjectLighthouse/Pages/SlotPage.cshtml.cs | 24 +++++++----- ProjectLighthouse/Pages/UserPage.cshtml.cs | 37 ++++++++++--------- 13 files changed, 58 insertions(+), 45 deletions(-) diff --git a/ProjectLighthouse/Controllers/GameApi/Resources/ResourcesController.cs b/ProjectLighthouse/Controllers/GameApi/Resources/ResourcesController.cs index 36ec216e..63d30d9e 100644 --- a/ProjectLighthouse/Controllers/GameApi/Resources/ResourcesController.cs +++ b/ProjectLighthouse/Controllers/GameApi/Resources/ResourcesController.cs @@ -55,7 +55,7 @@ public class ResourcesController : ControllerBase [HttpGet("/gameAssets/{hash}")] public IActionResult GetGameImage(string hash) { - string path = $"png{Path.DirectorySeparatorChar}{hash}.png"; + string path = Path.Combine("png", $"{hash}.png"); if (IOFile.Exists(path)) { diff --git a/ProjectLighthouse/Controllers/Website/Admin/AdminReportController.cs b/ProjectLighthouse/Controllers/Website/Admin/AdminReportController.cs index cca8a86e..bc41b069 100644 --- a/ProjectLighthouse/Controllers/Website/Admin/AdminReportController.cs +++ b/ProjectLighthouse/Controllers/Website/Admin/AdminReportController.cs @@ -37,19 +37,19 @@ public class AdminReportController : ControllerBase }; foreach (string hash in hashes) { - if (System.IO.File.Exists($"png{Path.DirectorySeparatorChar}{hash}")) + if (System.IO.File.Exists(Path.Combine("png", $"{hash}.png"))) { - System.IO.File.Delete($"png{Path.DirectorySeparatorChar}{hash}"); + System.IO.File.Delete(Path.Combine("png", $"{hash}.png")); } - if (System.IO.File.Exists($"r{Path.DirectorySeparatorChar}{hash}")) + if (System.IO.File.Exists(Path.Combine("r", hash))) { - System.IO.File.Delete($"r{Path.DirectorySeparatorChar}{hash}"); + System.IO.File.Delete(Path.Combine("r", hash)); } } this.database.Reports.Remove(report); await this.database.SaveChangesAsync(); - return this.Redirect("~/reports/0"); + return this.Redirect("~/admin/reports/0"); } } \ No newline at end of file diff --git a/ProjectLighthouse/Controllers/Website/SlotPageController.cs b/ProjectLighthouse/Controllers/Website/SlotPageController.cs index 4c02a856..92edbb3e 100644 --- a/ProjectLighthouse/Controllers/Website/SlotPageController.cs +++ b/ProjectLighthouse/Controllers/Website/SlotPageController.cs @@ -29,11 +29,9 @@ public class SlotPageController : ControllerBase User? user = this.database.UserFromWebRequest(this.Request); if (user == null) return this.Redirect("~/login"); - await this.database.RateComment(user, - commentId, - rating); + await this.database.RateComment(user, commentId, rating); - return this.Redirect("~/slot/" + id + "#" + commentId); + return this.Redirect($"~/slot/{id}#{commentId}"); } [HttpGet("postComment")] diff --git a/ProjectLighthouse/Controllers/Website/UserPageController.cs b/ProjectLighthouse/Controllers/Website/UserPageController.cs index f3ace5eb..c22e1623 100644 --- a/ProjectLighthouse/Controllers/Website/UserPageController.cs +++ b/ProjectLighthouse/Controllers/Website/UserPageController.cs @@ -42,7 +42,7 @@ public class UserPageController : ControllerBase await this.database.RateComment(user, commentId.GetValueOrDefault(), rating.GetValueOrDefault()); - return this.Redirect("~/user/" + id + "#" + commentId); + return this.Redirect($"~/user/{id}#{commentId}"); } [HttpGet("postComment")] diff --git a/ProjectLighthouse/Helpers/ImageHelper.cs b/ProjectLighthouse/Helpers/ImageHelper.cs index 92684520..7801af3b 100644 --- a/ProjectLighthouse/Helpers/ImageHelper.cs +++ b/ProjectLighthouse/Helpers/ImageHelper.cs @@ -18,7 +18,7 @@ public static class ImageHelper { if (type != LbpFileType.Jpeg && type != LbpFileType.Png && type != LbpFileType.Texture) return false; - if (File.Exists($"png{Path.DirectorySeparatorChar}{hash}.png")) return true; + if (File.Exists(Path.Combine("png", $"{hash}.png"))) return true; using MemoryStream ms = new(data); using BinaryReader reader = new(ms); diff --git a/ProjectLighthouse/Helpers/StatisticsHelper.cs b/ProjectLighthouse/Helpers/StatisticsHelper.cs index 7051fda0..3cd876ba 100644 --- a/ProjectLighthouse/Helpers/StatisticsHelper.cs +++ b/ProjectLighthouse/Helpers/StatisticsHelper.cs @@ -17,4 +17,6 @@ public static class StatisticsHelper public static async Task TeamPickCount() => await database.Slots.CountAsync(s => s.TeamPick); public static async Task PhotoCount() => await database.Photos.CountAsync(); + + public static async Task ReportCount() => await database.Reports.CountAsync(); } \ No newline at end of file diff --git a/ProjectLighthouse/Pages/Admin/AdminPanelPage.cshtml.cs b/ProjectLighthouse/Pages/Admin/AdminPanelPage.cshtml.cs index 92e5a5b0..d78bdb33 100644 --- a/ProjectLighthouse/Pages/Admin/AdminPanelPage.cshtml.cs +++ b/ProjectLighthouse/Pages/Admin/AdminPanelPage.cshtml.cs @@ -26,6 +26,7 @@ public class AdminPanelPage : BaseLayout this.Statistics.Add(new AdminPanelStatistic("Users", await StatisticsHelper.UserCount(), "users")); this.Statistics.Add(new AdminPanelStatistic("Slots", await StatisticsHelper.SlotCount())); this.Statistics.Add(new AdminPanelStatistic("Photos", await StatisticsHelper.PhotoCount())); + this.Statistics.Add(new AdminPanelStatistic("Reports", await StatisticsHelper.ReportCount(), "reports/0")); if (!string.IsNullOrEmpty(command)) { diff --git a/ProjectLighthouse/Pages/Layouts/BaseLayout.cshtml b/ProjectLighthouse/Pages/Layouts/BaseLayout.cshtml index bfafbb1c..279ca575 100644 --- a/ProjectLighthouse/Pages/Layouts/BaseLayout.cshtml +++ b/ProjectLighthouse/Pages/Layouts/BaseLayout.cshtml @@ -19,7 +19,6 @@ @if (Model.User.IsAdmin) { - Model.NavigationItems.Add(new PageNavigationItem("Reports", "/reports/0", "exclamation circle")); Model.NavigationItemsRight.Add(new PageNavigationItem("Admin Panel", "/admin", "cogs")); } Model.NavigationItemsRight.Add(new PageNavigationItem("Log out", "/logout", "user alternate slash")); // should always be last diff --git a/ProjectLighthouse/Pages/Partials/CommentsPartial.cshtml b/ProjectLighthouse/Pages/Partials/CommentsPartial.cshtml index 3a4420ce..7d038558 100644 --- a/ProjectLighthouse/Pages/Partials/CommentsPartial.cshtml +++ b/ProjectLighthouse/Pages/Partials/CommentsPartial.cshtml @@ -17,10 +17,14 @@ }

Comments

- @if (Model.Comments.Count == 0) + @if (Model.Comments.Count == 0 && Model.CommentsEnabled) {

There are no comments.

} + else if (!Model.CommentsEnabled) + { + Comments are disabled + } @for (int i = 0; i < Model.Comments.Count; i++) { diff --git a/ProjectLighthouse/Pages/ReportsPage.cshtml b/ProjectLighthouse/Pages/ReportsPage.cshtml index eca106db..116debe3 100644 --- a/ProjectLighthouse/Pages/ReportsPage.cshtml +++ b/ProjectLighthouse/Pages/ReportsPage.cshtml @@ -1,4 +1,4 @@ -@page "/reports/{pageNumber:int}" +@page "/admin/reports/{pageNumber:int}" @using LBPUnion.ProjectLighthouse.Types.Reports @model LBPUnion.ProjectLighthouse.Pages.ReportsPage @@ -9,7 +9,7 @@

There are @Model.ReportCount total reports!

-
+
@@ -199,10 +199,10 @@ @if (Model.PageNumber != 0) { - Previous Page + Previous Page } @(Model.PageNumber + 1) / @(Model.PageAmount) @if (Model.PageNumber < Model.PageAmount - 1) { - Next Page + Next Page } \ No newline at end of file diff --git a/ProjectLighthouse/Pages/ReportsPage.cshtml.cs b/ProjectLighthouse/Pages/ReportsPage.cshtml.cs index e315caf4..54c7423d 100644 --- a/ProjectLighthouse/Pages/ReportsPage.cshtml.cs +++ b/ProjectLighthouse/Pages/ReportsPage.cshtml.cs @@ -46,7 +46,7 @@ public class ReportsPage : BaseLayout this.PageAmount = Math.Max(1, (int) Math.Ceiling((double) this.ReportCount / ServerStatics.PageSize)); if (this.PageNumber < 0 || this.PageNumber >= this.PageAmount) - return this.Redirect($"/reports/{Math.Clamp(this.PageNumber, 0, this.PageAmount - 1)}"); + return this.Redirect($"/admin/reports/{Math.Clamp(this.PageNumber, 0, this.PageAmount - 1)}"); this.Reports = await this.Database.Reports.Include(r => r.ReportingPlayer) .Where(r => r.ReportingPlayer.Username.Contains(this.SearchValue)) diff --git a/ProjectLighthouse/Pages/SlotPage.cshtml.cs b/ProjectLighthouse/Pages/SlotPage.cshtml.cs index 9476c3c6..4d7c780b 100644 --- a/ProjectLighthouse/Pages/SlotPage.cshtml.cs +++ b/ProjectLighthouse/Pages/SlotPage.cshtml.cs @@ -28,20 +28,26 @@ public class SlotPage : BaseLayout Slot? slot = await this.Database.Slots.Include(s => s.Creator).FirstOrDefaultAsync(s => s.SlotId == id); if (slot == null) return this.NotFound(); - this.Comments = await this.Database.Comments.Include(p => p.Poster) - .OrderByDescending(p => p.Timestamp) - .Where(c => c.TargetId == id && c.Type == CommentType.Level) - .Take(50) - .ToListAsync(); - this.Slot = slot; + if (this.CommentsEnabled) + { + this.Comments = await this.Database.Comments.Include(p => p.Poster) + .OrderByDescending(p => p.Timestamp) + .Where(c => c.TargetId == id && c.Type == CommentType.Level) + .Take(50) + .ToListAsync(); + } + else + { + this.Comments = new List(); + } + if (this.User == null) return this.Page(); - + foreach (Comment c in this.Comments) { - Reaction? reaction = await this.Database.Reactions.FirstOrDefaultAsync(r => - r.UserId == this.User.UserId && r.TargetId == c.CommentId); + Reaction? reaction = await this.Database.Reactions.FirstOrDefaultAsync(r => r.UserId == this.User.UserId && r.TargetId == c.CommentId); if (reaction != null) c.YourThumb = reaction.Rating; } diff --git a/ProjectLighthouse/Pages/UserPage.cshtml.cs b/ProjectLighthouse/Pages/UserPage.cshtml.cs index c10ab132..04562e55 100644 --- a/ProjectLighthouse/Pages/UserPage.cshtml.cs +++ b/ProjectLighthouse/Pages/UserPage.cshtml.cs @@ -31,25 +31,28 @@ public class UserPage : BaseLayout if (this.ProfileUser == null) return this.NotFound(); this.Photos = await this.Database.Photos.OrderByDescending(p => p.Timestamp).Where(p => p.CreatorId == userId).Take(6).ToListAsync(); - this.Comments = await this.Database.Comments.Include - (p => p.Poster) - .OrderByDescending(p => p.Timestamp) - .Where(p => p.TargetId == userId && p.Type == CommentType.Profile) - .Take(50) - .ToListAsync(); - if (this.User != null) + if (this.CommentsEnabled) { - foreach (Comment c in this.Comments) - { - Reaction? reaction = await this.Database.Reactions.FirstOrDefaultAsync(r => - r.UserId == this.User.UserId && r.TargetId == c.CommentId); - if (reaction != null) c.YourThumb = reaction.Rating; - } - this.IsProfileUserHearted = await this.Database.HeartedProfiles.FirstOrDefaultAsync(u => - u.UserId == this.User.UserId && - u.HeartedUserId == this.ProfileUser.UserId) != - null; + this.Comments = await this.Database.Comments.Include(p => p.Poster) + .OrderByDescending(p => p.Timestamp) + .Where(p => p.TargetId == userId && p.Type == CommentType.Profile) + .Take(50) + .ToListAsync(); } + else + { + this.Comments = new List(); + } + + if (this.User == null) return this.Page(); + + foreach (Comment c in this.Comments) + { + Reaction? reaction = await this.Database.Reactions.FirstOrDefaultAsync(r => r.UserId == this.User.UserId && r.TargetId == c.CommentId); + if (reaction != null) c.YourThumb = reaction.Rating; + } + this.IsProfileUserHearted = await this.Database.HeartedProfiles.FirstOrDefaultAsync + (u => u.UserId == this.User.UserId && u.HeartedUserId == this.ProfileUser.UserId) != null; return this.Page(); }