diff --git a/ProjectLighthouse/Controllers/PublishController.cs b/ProjectLighthouse/Controllers/PublishController.cs index 134521fa..42ff9ba8 100644 --- a/ProjectLighthouse/Controllers/PublishController.cs +++ b/ProjectLighthouse/Controllers/PublishController.cs @@ -1,8 +1,10 @@ using System.IO; +using System.Linq; using System.Threading.Tasks; using System.Xml.Serialization; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; +using ProjectLighthouse.Helpers; using ProjectLighthouse.Serialization; using ProjectLighthouse.Types; @@ -25,9 +27,12 @@ namespace ProjectLighthouse.Controllers { Slot slot = await this.GetSlotFromBody(); if(slot == null) return this.BadRequest(); // if the level cant be parsed then it obviously cant be uploaded - string resource = LbpSerializer.StringElement("resource", slot.Resources); + string resources = slot.Resources + .Where(hash => !FileHelper.ResourceExists(hash)) + .Aggregate("", (current, hash) => + current + LbpSerializer.StringElement("resource", hash)); - return this.Ok(LbpSerializer.TaggedStringElement("slot", resource, "type", "user")); + return this.Ok(LbpSerializer.TaggedStringElement("slot", resources, "type", "user")); } /// diff --git a/ProjectLighthouse/Types/Slot.cs b/ProjectLighthouse/Types/Slot.cs index 6217c9c3..5dbbf297 100644 --- a/ProjectLighthouse/Types/Slot.cs +++ b/ProjectLighthouse/Types/Slot.cs @@ -1,6 +1,7 @@ using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; +using System.Linq; using System.Xml.Serialization; using ProjectLighthouse.Serialization; @@ -83,6 +84,12 @@ namespace ProjectLighthouse.Types { [XmlElement("moveRequired")] public bool MoveRequired { get; set; } + public string SerializeResources() { + return this.Resources + .Aggregate("", (current, resource) => + current + LbpSerializer.StringElement("resource", resource)); + } + public string Serialize() { string slotData = LbpSerializer.StringElement("name", Name) + LbpSerializer.StringElement("id", SlotId) + @@ -91,7 +98,7 @@ namespace ProjectLighthouse.Types { LbpSerializer.StringElement("description", Description) + LbpSerializer.StringElement("icon", IconHash) + LbpSerializer.StringElement("rootLevel", RootLevel) + - LbpSerializer.StringElement("resource", this.Resources) + + this.SerializeResources() + LbpSerializer.StringElement("location", Location.Serialize()) + LbpSerializer.StringElement("initiallyLocked", InitiallyLocked) + LbpSerializer.StringElement("isSubLevel", SubLevel) +