diff --git a/ProjectLighthouse/Controllers/PublishController.cs b/ProjectLighthouse/Controllers/PublishController.cs
index 8136e10a..508bbdec 100644
--- a/ProjectLighthouse/Controllers/PublishController.cs
+++ b/ProjectLighthouse/Controllers/PublishController.cs
@@ -22,13 +22,23 @@ namespace LBPUnion.ProjectLighthouse.Controllers {
}
///
- /// 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
///
[HttpPost("startPublish")]
public async Task 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,
diff --git a/ProjectLighthouse/Types/Levels/Slot.cs b/ProjectLighthouse/Types/Levels/Slot.cs
index c6fe9f43..92fd9701 100644
--- a/ProjectLighthouse/Types/Levels/Slot.cs
+++ b/ProjectLighthouse/Types/Levels/Slot.cs
@@ -16,7 +16,7 @@ namespace LBPUnion.ProjectLighthouse.Types.Levels {
public string Type { get; set; }
[Key]
- [XmlIgnore]
+ [XmlElement("id")]
public int SlotId { get; set; }