mirror of
https://github.com/LBPUnion/ProjectLighthouse.git
synced 2025-07-30 08:48:39 +00:00
Add ability to republish levels
This commit is contained in:
parent
33c961d481
commit
93a452814c
2 changed files with 29 additions and 2 deletions
|
@ -22,13 +22,23 @@ namespace LBPUnion.ProjectLighthouse.Controllers {
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// Endpoint the game uses to verify that the level is compatible (?)
|
||||
/// Endpoint the game uses to check what resources need to be uploaded and if the level can be uploaded
|
||||
/// </summary>
|
||||
[HttpPost("startPublish")]
|
||||
public async Task<IActionResult> StartPublish() {
|
||||
User user = await this.database.UserFromRequest(this.Request);
|
||||
if(user == null) return this.StatusCode(403, "");
|
||||
|
||||
Slot slot = await this.GetSlotFromBody();
|
||||
if(slot == null) return this.BadRequest(); // if the level cant be parsed then it obviously cant be uploaded
|
||||
|
||||
// Republish logic
|
||||
if(slot.SlotId != 0) {
|
||||
Slot oldSlot = await this.database.Slots.FirstOrDefaultAsync(s => s.SlotId == slot.SlotId);
|
||||
if(oldSlot == null) return this.NotFound();
|
||||
if(oldSlot.CreatorId != user.UserId) return this.BadRequest();
|
||||
}
|
||||
|
||||
string resources = slot.Resources
|
||||
.Where(hash => !FileHelper.ResourceExists(hash))
|
||||
.Aggregate("", (current, hash) =>
|
||||
|
@ -47,6 +57,23 @@ namespace LBPUnion.ProjectLighthouse.Controllers {
|
|||
|
||||
Slot slot = await this.GetSlotFromBody();
|
||||
|
||||
// Republish logic
|
||||
if(slot.SlotId != 0) {
|
||||
Slot oldSlot = await this.database.Slots
|
||||
.Include(s => s.Location)
|
||||
.FirstOrDefaultAsync(s => s.SlotId == slot.SlotId);
|
||||
if(oldSlot == null) return this.NotFound();
|
||||
if(oldSlot.CreatorId != user.UserId) return this.BadRequest();
|
||||
|
||||
slot.CreatorId = oldSlot.CreatorId;
|
||||
slot.LocationId = oldSlot.LocationId;
|
||||
slot.SlotId = oldSlot.SlotId;
|
||||
|
||||
this.database.Entry(oldSlot).CurrentValues.SetValues(slot);
|
||||
await this.database.SaveChangesAsync();
|
||||
return this.Ok(oldSlot.Serialize());
|
||||
}
|
||||
|
||||
//TODO: parse location in body
|
||||
Location l = new() {
|
||||
X = 0,
|
||||
|
|
|
@ -16,7 +16,7 @@ namespace LBPUnion.ProjectLighthouse.Types.Levels {
|
|||
public string Type { get; set; }
|
||||
|
||||
[Key]
|
||||
[XmlIgnore]
|
||||
[XmlElement("id")]
|
||||
public int SlotId { get; set; }
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue