Merge remote-tracking branch 'origin/main'

This commit is contained in:
jvyden 2022-01-31 22:52:45 -05:00
commit 2fee6c62e1
No known key found for this signature in database
GPG key ID: 18BCF2BE0262B278
11 changed files with 80 additions and 31 deletions

View file

@ -1,4 +1,5 @@
#nullable enable
using System;
using System.IO;
using System.Linq;
using System.Threading.Tasks;

View file

@ -7,7 +7,7 @@ namespace LBPUnion.ProjectLighthouse.Helpers;
public static class WebhookHelper
{
private static readonly DiscordWebhookClient client = new(ServerSettings.Instance.DiscordWebhookUrl);
private static readonly DiscordWebhookClient client = (ServerSettings.Instance.DiscordWebhookEnabled ? new DiscordWebhookClient(ServerSettings.Instance.DiscordWebhookUrl) : null);
public static readonly Color UnionColor = new(0, 140, 255);
public static Task SendWebhook(EmbedBuilder builder) => SendWebhook(builder.Build());

View file

@ -11,9 +11,10 @@
<script>
function onSubmit(form) {
const password = form['password'];
const passwordInput = document.getElementById("password");
const passwordSubmit = document.getElementById("password-submit");
password.value = sha256(password.value);
passwordSubmit.value = sha256(passwordInput.value);
return true;
}
@ -43,7 +44,8 @@
<div class="field">
<label>Password</label>
<div class="ui left icon input">
<input type="password" name="password" id="password" placeholder="Password">
<input type="password" id="password" placeholder="Password">
<input type="hidden" id="password-submit" name="password">
<i class="lock icon"></i>
</div>
</div>

View file

@ -9,6 +9,14 @@
<p>There are @Model.PhotoCount total photos!</p>
<form action="/photos/0">
<div class="ui icon input">
<input type="text" name="name" placeholder="Search photos..." value="@Model.SearchValue">
<i class="search icon"></i>
</div>
</form>
<div class="ui divider"></div>
@foreach (Photo photo in Model.Photos)
{
<div class="ui segment">
@ -18,10 +26,10 @@
@if (Model.PageNumber != 0)
{
<a href="/photos/@(Model.PageNumber - 1)">Previous Page</a>
<a href="/photos/@(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="/photos/@(Model.PageNumber + 1)">Next Page</a>
<a href="/photos/@(Model.PageNumber + 1)@(Model.SearchValue.Length == 0 ? "" : "?name=" + Model.SearchValue)">Next Page</a>
}

View file

@ -1,9 +1,9 @@
#nullable enable
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using JetBrains.Annotations;
using LBPUnion.ProjectLighthouse.Helpers;
using LBPUnion.ProjectLighthouse.Pages.Layouts;
using LBPUnion.ProjectLighthouse.Types;
using LBPUnion.ProjectLighthouse.Types.Settings;
@ -22,20 +22,26 @@ public class PhotosPage : BaseLayout
public int PhotoCount;
public List<Photo> Photos;
public string SearchValue;
public PhotosPage([NotNull] Database database) : base(database)
{}
public async Task<IActionResult> OnGet([FromRoute] int pageNumber)
public async Task<IActionResult> OnGet([FromRoute] int pageNumber, [FromQuery] string? name)
{
this.PhotoCount = await StatisticsHelper.PhotoCount();
if (string.IsNullOrWhiteSpace(name)) name = "";
this.PhotoCount = await this.Database.Photos.CountAsync(p => p.Creator.Username.Contains(name) || p.PhotoSubjectCollection.Contains(name));
this.SearchValue = name;
this.PageNumber = pageNumber;
this.PageAmount = (int)Math.Ceiling((double)this.PhotoCount / ServerStatics.PageSize);
this.PageAmount = Math.Max(1, (int)Math.Ceiling((double)this.PhotoCount / ServerStatics.PageSize));
if (this.PageNumber < 0 || this.PageNumber >= this.PageAmount) return this.Redirect($"/photos/{Math.Clamp(this.PageNumber, 0, this.PageAmount - 1)}");
this.Photos = await this.Database.Photos.Include
(p => p.Creator)
.Where(p => p.Creator.Username.Contains(name) || p.PhotoSubjectCollection.Contains(name))
.OrderByDescending(p => p.Timestamp)
.Skip(pageNumber * ServerStatics.PageSize)
.Take(ServerStatics.PageSize)

View file

@ -10,11 +10,12 @@
<script>
function onSubmit(form) {
const password = form['password'];
const confirmPassword = form['confirmPassword'];
password.value = sha256(password.value);
confirmPassword.value = sha256(confirmPassword.value);
const passwordInput = document.getElementById("password");
const confirmPasswordInput = document.getElementById("confirmPassword");
const passwordSubmit = document.getElementById("password-submit");
const confirmPasswordSubmit = document.getElementById("confirm-submit");
passwordSubmit.value = sha256(passwordInput.value);
confirmPasswordSubmit.value = sha256(confirmPasswordInput.value);
return true;
}
@ -44,7 +45,8 @@
<div class="field">
<label>Password</label>
<div class="ui left icon input">
<input type="password" name="password" id="password" placeholder="Password">
<input type="password" id="password" placeholder="Password">
<input type="hidden" name="password" id="password-submit">
<i class="lock icon"></i>
</div>
</div>
@ -52,7 +54,8 @@
<div class="field">
<label>Confirm Password</label>
<div class="ui left icon input">
<input type="password" name="confirmPassword" id="confirmPassword" placeholder="Confirm Password">
<input type="password" id="confirmPassword" placeholder="Confirm Password">
<input type="hidden" name="confirmPassword" id="confirm-submit">
<i class="lock icon"></i>
</div>
</div>

View file

@ -10,6 +10,14 @@
<p>There are @Model.SlotCount total levels!</p>
<form action="/slots/0">
<div class="ui icon input">
<input type="text" name="name" placeholder="Search levels..." value="@Model.SearchValue">
<i class="search icon"></i>
</div>
</form>
<div class="ui divider"></div>
@foreach (Slot slot in Model.Slots)
{
bool isMobile = Model.Request.IsMobile();
@ -34,10 +42,10 @@
@if (Model.PageNumber != 0)
{
<a href="/slots/@(Model.PageNumber - 1)">Previous Page</a>
<a href="/slots/@(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="/slots/@(Model.PageNumber + 1)">Next Page</a>
<a href="/slots/@(Model.PageNumber + 1)@(Model.SearchValue.Length == 0 ? "" : "?name=" + Model.SearchValue)">Next Page</a>
}

View file

@ -1,3 +1,4 @@
#nullable enable
using System;
using System.Collections.Generic;
using System.Linq;
@ -22,20 +23,26 @@ public class SlotsPage : BaseLayout
public int SlotCount;
public List<Slot> Slots;
public string SearchValue;
public SlotsPage([NotNull] Database database) : base(database)
{}
public async Task<IActionResult> OnGet([FromRoute] int pageNumber)
public async Task<IActionResult> OnGet([FromRoute] int pageNumber, [FromQuery] string? name)
{
this.SlotCount = await StatisticsHelper.SlotCount();
if (string.IsNullOrWhiteSpace(name)) name = "";
this.SlotCount = await this.Database.Slots.CountAsync(p => p.Name.Contains(name));
this.SearchValue = name;
this.PageNumber = pageNumber;
this.PageAmount = (int)Math.Ceiling((double)this.SlotCount / ServerStatics.PageSize);
this.PageAmount = Math.Max(1, (int) Math.Ceiling((double) this.SlotCount / ServerStatics.PageSize));
if (this.PageNumber < 0 || this.PageNumber >= this.PageAmount) return this.Redirect($"/slots/{Math.Clamp(this.PageNumber, 0, this.PageAmount - 1)}");
this.Slots = await this.Database.Slots.Include
(p => p.Creator)
this.Slots = await this.Database.Slots.Where
(p => p.Name.Contains(name))
.OrderByDescending(p => p.FirstUploaded)
.Skip(pageNumber * ServerStatics.PageSize)
.Take(ServerStatics.PageSize)

View file

@ -9,6 +9,14 @@
}
<p>There are @Model.UserCount total users.</p>
<form action="/users/0">
<div class="ui icon input">
<input type="text" name="name" placeholder="Search users..." value="@Model.SearchValue">
<i class="search icon"></i>
</div>
</form>
<div class="ui divider"></div>
@foreach (User user in Model.Users)
{
@ -28,10 +36,10 @@
@if (Model.PageNumber != 0)
{
<a href="/users/@(Model.PageNumber - 1)">Previous Page</a>
<a href="/users/@(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="/users/@(Model.PageNumber + 1)">Next Page</a>
<a href="/users/@(Model.PageNumber + 1)@(Model.SearchValue.Length == 0 ? "" : "?name=" + Model.SearchValue)">Next Page</a>
}

View file

@ -1,9 +1,9 @@
#nullable enable
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using JetBrains.Annotations;
using LBPUnion.ProjectLighthouse.Helpers;
using LBPUnion.ProjectLighthouse.Pages.Layouts;
using LBPUnion.ProjectLighthouse.Types;
using LBPUnion.ProjectLighthouse.Types.Settings;
@ -22,20 +22,25 @@ public class UsersPage : BaseLayout
public List<User> Users;
public string SearchValue;
public UsersPage([NotNull] Database database) : base(database)
{}
public async Task<IActionResult> OnGet([FromRoute] int pageNumber)
public async Task<IActionResult> OnGet([FromRoute] int pageNumber, [FromQuery] string? name)
{
this.UserCount = await StatisticsHelper.UserCount();
if (string.IsNullOrWhiteSpace(name)) name = "";
this.UserCount = await this.Database.Users.CountAsync(u => !u.Banned && u.Username.Contains(name));
this.SearchValue = name;
this.PageNumber = pageNumber;
this.PageAmount = (int)Math.Ceiling((double)this.UserCount / ServerStatics.PageSize);
this.PageAmount = Math.Max(1, (int)Math.Ceiling((double)this.UserCount / ServerStatics.PageSize));
if (this.PageNumber < 0 || this.PageNumber >= this.PageAmount) return this.Redirect($"/users/{Math.Clamp(this.PageNumber, 0, this.PageAmount - 1)}");
this.Users = await this.Database.Users.Where
(u => !u.Banned)
(u => !u.Banned && u.Username.Contains(name))
.OrderByDescending(b => b.UserId)
.Skip(pageNumber * ServerStatics.PageSize)
.Take(ServerStatics.PageSize)

View file

@ -82,6 +82,7 @@ public static class Program
return;
}
FileHelper.EnsureDirectoryCreated(Path.Combine(Environment.CurrentDirectory, "png"));
if (Directory.Exists("r"))
{
Logger.Log