mirror of
https://github.com/LBPUnion/ProjectLighthouse.git
synced 2025-07-30 16:58:38 +00:00
Fix levels LBP2 levels showing in LBP1
This commit is contained in:
parent
85f3f3cd8d
commit
85c29eae81
2 changed files with 53 additions and 13 deletions
|
@ -1,7 +1,9 @@
|
||||||
|
#nullable enable
|
||||||
using System;
|
using System;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using LBPUnion.ProjectLighthouse.Serialization;
|
using LBPUnion.ProjectLighthouse.Serialization;
|
||||||
|
using LBPUnion.ProjectLighthouse.Types;
|
||||||
using LBPUnion.ProjectLighthouse.Types.Levels;
|
using LBPUnion.ProjectLighthouse.Types.Levels;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
@ -20,11 +22,19 @@ namespace LBPUnion.ProjectLighthouse.Controllers
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet("slots/by")]
|
[HttpGet("slots/by")]
|
||||||
public IActionResult SlotsBy([FromQuery] string u)
|
public async Task<IActionResult> SlotsBy([FromQuery] string u)
|
||||||
{
|
{
|
||||||
|
Token? token = await this.database.TokenFromRequest(this.Request);
|
||||||
|
if (token == null) return this.BadRequest();
|
||||||
|
|
||||||
|
GameVersion gameVersion = token.GameVersion;
|
||||||
|
|
||||||
string response = Enumerable.Aggregate
|
string response = Enumerable.Aggregate
|
||||||
(
|
(
|
||||||
this.database.Slots.Include(s => s.Creator).Include(s => s.Location).Where(s => s.Creator.Username == u),
|
this.database.Slots.Where(s => s.GameVersion <= gameVersion)
|
||||||
|
.Include(s => s.Creator)
|
||||||
|
.Include(s => s.Location)
|
||||||
|
.Where(s => s.Creator.Username == u),
|
||||||
string.Empty,
|
string.Empty,
|
||||||
(current, slot) => current + slot.Serialize()
|
(current, slot) => current + slot.Serialize()
|
||||||
);
|
);
|
||||||
|
@ -35,7 +45,15 @@ namespace LBPUnion.ProjectLighthouse.Controllers
|
||||||
[HttpGet("s/user/{id:int}")]
|
[HttpGet("s/user/{id:int}")]
|
||||||
public async Task<IActionResult> SUser(int id)
|
public async Task<IActionResult> SUser(int id)
|
||||||
{
|
{
|
||||||
Slot slot = await this.database.Slots.Include(s => s.Creator).Include(s => s.Location).FirstOrDefaultAsync(s => s.SlotId == id);
|
Token? token = await this.database.TokenFromRequest(this.Request);
|
||||||
|
if (token == null) return this.BadRequest();
|
||||||
|
|
||||||
|
GameVersion gameVersion = token.GameVersion;
|
||||||
|
|
||||||
|
Slot slot = await this.database.Slots.Where(s => s.GameVersion <= gameVersion)
|
||||||
|
.Include(s => s.Creator)
|
||||||
|
.Include(s => s.Location)
|
||||||
|
.FirstOrDefaultAsync(s => s.SlotId == id);
|
||||||
|
|
||||||
if (slot == null) return this.NotFound();
|
if (slot == null) return this.NotFound();
|
||||||
|
|
||||||
|
@ -43,13 +61,18 @@ namespace LBPUnion.ProjectLighthouse.Controllers
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet("slots/cool")]
|
[HttpGet("slots/cool")]
|
||||||
public IActionResult CoolSlots([FromQuery] int page) => NewestSlots(30 * page, 30);
|
public async Task<IActionResult> CoolSlots([FromQuery] int page) => await NewestSlots(30 * page, 30);
|
||||||
|
|
||||||
[HttpGet("slots")]
|
[HttpGet("slots")]
|
||||||
public IActionResult NewestSlots([FromQuery] int pageStart, [FromQuery] int pageSize)
|
public async Task<IActionResult> NewestSlots([FromQuery] int pageStart, [FromQuery] int pageSize)
|
||||||
{
|
{
|
||||||
IQueryable<Slot> slots = this.database.Slots.Include
|
Token? token = await this.database.TokenFromRequest(this.Request);
|
||||||
(s => s.Creator)
|
if (token == null) return this.BadRequest();
|
||||||
|
|
||||||
|
GameVersion gameVersion = token.GameVersion;
|
||||||
|
|
||||||
|
IQueryable<Slot> slots = this.database.Slots.Where(s => s.GameVersion <= gameVersion)
|
||||||
|
.Include(s => s.Creator)
|
||||||
.Include(s => s.Location)
|
.Include(s => s.Location)
|
||||||
.OrderByDescending(s => s.FirstUploaded)
|
.OrderByDescending(s => s.FirstUploaded)
|
||||||
.Skip(pageStart - 1)
|
.Skip(pageStart - 1)
|
||||||
|
@ -60,10 +83,15 @@ namespace LBPUnion.ProjectLighthouse.Controllers
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet("slots/mmpicks")]
|
[HttpGet("slots/mmpicks")]
|
||||||
public IActionResult TeamPickedSlots([FromQuery] int pageStart, [FromQuery] int pageSize)
|
public async Task<IActionResult> TeamPickedSlots([FromQuery] int pageStart, [FromQuery] int pageSize)
|
||||||
{
|
{
|
||||||
IQueryable<Slot> slots = this.database.Slots.Where
|
Token? token = await this.database.TokenFromRequest(this.Request);
|
||||||
(s => s.TeamPick)
|
if (token == null) return this.BadRequest();
|
||||||
|
|
||||||
|
GameVersion gameVersion = token.GameVersion;
|
||||||
|
|
||||||
|
IQueryable<Slot> slots = this.database.Slots.Where(s => s.GameVersion <= gameVersion)
|
||||||
|
.Where(s => s.TeamPick)
|
||||||
.Include(s => s.Creator)
|
.Include(s => s.Creator)
|
||||||
.Include(s => s.Location)
|
.Include(s => s.Location)
|
||||||
.OrderByDescending(s => s.LastUpdated)
|
.OrderByDescending(s => s.LastUpdated)
|
||||||
|
@ -75,11 +103,16 @@ namespace LBPUnion.ProjectLighthouse.Controllers
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet("slots/lbp2luckydip")]
|
[HttpGet("slots/lbp2luckydip")]
|
||||||
public IActionResult LuckyDipSlots([FromQuery] int pageStart, [FromQuery] int pageSize, [FromQuery] int seed)
|
public async Task<IActionResult> LuckyDipSlots([FromQuery] int pageStart, [FromQuery] int pageSize, [FromQuery] int seed)
|
||||||
{
|
{
|
||||||
|
Token? token = await this.database.TokenFromRequest(this.Request);
|
||||||
|
if (token == null) return this.BadRequest();
|
||||||
|
|
||||||
|
GameVersion gameVersion = token.GameVersion;
|
||||||
|
|
||||||
// TODO: Incorporate seed?
|
// TODO: Incorporate seed?
|
||||||
IQueryable<Slot> slots = this.database.Slots.OrderBy
|
IQueryable<Slot> slots = this.database.Slots.Where(s => s.GameVersion <= gameVersion)
|
||||||
(_ => Guid.NewGuid())
|
.OrderBy(_ => Guid.NewGuid())
|
||||||
.Include(s => s.Creator)
|
.Include(s => s.Creator)
|
||||||
.Include(s => s.Location)
|
.Include(s => s.Location)
|
||||||
.Skip(pageStart - 1)
|
.Skip(pageStart - 1)
|
||||||
|
|
|
@ -94,6 +94,13 @@ namespace LBPUnion.ProjectLighthouse
|
||||||
return await this.UserFromAuthToken(mmAuth);
|
return await this.UserFromAuthToken(mmAuth);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task<Token?> TokenFromRequest(HttpRequest request)
|
||||||
|
{
|
||||||
|
if (!request.Cookies.TryGetValue("MM_AUTH", out string? mmAuth) || mmAuth == null) return null;
|
||||||
|
|
||||||
|
return await this.Tokens.FirstOrDefaultAsync(t => t.UserToken == mmAuth);
|
||||||
|
}
|
||||||
|
|
||||||
public async Task<(User, Token)?> UserAndTokenFromRequest(HttpRequest request)
|
public async Task<(User, Token)?> UserAndTokenFromRequest(HttpRequest request)
|
||||||
{
|
{
|
||||||
if (!request.Cookies.TryGetValue("MM_AUTH", out string? mmAuth) || mmAuth == null) return null;
|
if (!request.Cookies.TryGetValue("MM_AUTH", out string? mmAuth) || mmAuth == null) return null;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue