Implement URL slugs (#931)

* Implement URL slugs for Users and Slots

* Fix extra spaces in slot slugs
This commit is contained in:
Josh 2023-10-29 15:30:43 -05:00 committed by GitHub
commit 1eb3bfa2ec
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 55 additions and 8 deletions

View file

@ -1,6 +1,7 @@
#nullable enable
using LBPUnion.ProjectLighthouse.Configuration;
using LBPUnion.ProjectLighthouse.Database;
using LBPUnion.ProjectLighthouse.Servers.Website.Extensions;
using LBPUnion.ProjectLighthouse.Servers.Website.Pages.Layouts;
using LBPUnion.ProjectLighthouse.Types.Entities.Interaction;
using LBPUnion.ProjectLighthouse.Types.Entities.Level;
@ -28,7 +29,7 @@ public class SlotPage : BaseLayout
public SlotPage(DatabaseContext database) : base(database)
{}
public async Task<IActionResult> OnGet([FromRoute] int id)
public async Task<IActionResult> OnGet([FromRoute] int id, string? slug)
{
SlotEntity? slot = await this.Database.Slots.Include(s => s.Creator)
.Where(s => s.Type == SlotType.User || (this.User != null && this.User.PermissionLevel >= PermissionLevel.Moderator))
@ -45,6 +46,12 @@ public class SlotPage : BaseLayout
if ((slot.Hidden || slot.SubLevel && (this.User == null && this.User != slot.Creator)) && !(this.User?.IsModerator ?? false))
return this.NotFound();
string slotSlug = slot.GenerateSlug();
if (slug == null || slotSlug != slug)
{
return this.Redirect($"~/slot/{id}/{slotSlug}");
}
this.Slot = slot;
List<int> blockedUsers = this.User == null