Make suggested changes

This commit is contained in:
Slendy 2022-02-13 18:00:37 -06:00
commit 3269e84060
13 changed files with 58 additions and 45 deletions

View file

@ -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))
{

View file

@ -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");
}
}

View file

@ -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")]

View file

@ -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")]

View file

@ -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);

View file

@ -17,4 +17,6 @@ public static class StatisticsHelper
public static async Task<int> TeamPickCount() => await database.Slots.CountAsync(s => s.TeamPick);
public static async Task<int> PhotoCount() => await database.Photos.CountAsync();
public static async Task<int> ReportCount() => await database.Reports.CountAsync();
}

View file

@ -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))
{

View file

@ -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

View file

@ -17,10 +17,14 @@
}
</style>
<h1>Comments</h1>
@if (Model.Comments.Count == 0)
@if (Model.Comments.Count == 0 && Model.CommentsEnabled)
{
<p>There are no comments.</p>
}
else if (!Model.CommentsEnabled)
{
<b><i>Comments are disabled</i></b>
}
@for (int i = 0; i < Model.Comments.Count; i++)
{

View file

@ -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 @@
<p>There are @Model.ReportCount total reports!</p>
<form action="/reports/0">
<form action="/admin/reports/0">
<div class="ui icon input">
<input type="text" name="name" placeholder="Search reports..." value="@Model.SearchValue">
<i class="search icon"></i>
@ -199,10 +199,10 @@
@if (Model.PageNumber != 0)
{
<a href="/reports/@(Model.PageNumber - 1)@(Model.SearchValue.Length == 0 ? "" : "?name=" + Model.SearchValue)">Previous Page</a>
<a href="/admin/reports/@(Model.PageNumber - 1)@(Model.SearchValue.Length == 0 ? "" : "?name=" + Model.SearchValue)">Previous Page</a>
}
@(Model.PageNumber + 1) / @(Model.PageAmount)
@if (Model.PageNumber < Model.PageAmount - 1)
{
<a href="/reports/@(Model.PageNumber + 1)@(Model.SearchValue.Length == 0 ? "" : "?name=" + Model.SearchValue)">Next Page</a>
<a href="/admin/reports/@(Model.PageNumber + 1)@(Model.SearchValue.Length == 0 ? "" : "?name=" + Model.SearchValue)">Next Page</a>
}

View file

@ -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))

View file

@ -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<Comment>();
}
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;
}

View file

@ -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<Comment>();
}
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();
}