diff --git a/ProjectLighthouse/Controllers/ResourcesController.cs b/ProjectLighthouse/Controllers/ResourcesController.cs index 83a1ba41..615df77a 100644 --- a/ProjectLighthouse/Controllers/ResourcesController.cs +++ b/ProjectLighthouse/Controllers/ResourcesController.cs @@ -1,9 +1,12 @@ using System.IO; +using System.Linq; using System.Text; using System.Threading.Tasks; +using System.Xml.Serialization; using Microsoft.AspNetCore.Mvc; using ProjectLighthouse.Helpers; using ProjectLighthouse.Serialization; +using ProjectLighthouse.Types; using ProjectLighthouse.Types.Files; using IOFile = System.IO.File; @@ -20,7 +23,19 @@ namespace ProjectLighthouse.Controllers { [HttpPost("filterResources")] [HttpPost("showNotUploaded")] public async Task FilterResources() { - return this.Ok(await new StreamReader(Request.Body).ReadToEndAsync()); + string bodyString = await new StreamReader(Request.Body).ReadToEndAsync(); + + XmlSerializer serializer = new(typeof(ResourceList)); + ResourceList resourceList = (ResourceList)serializer.Deserialize(new StringReader(bodyString)); + + if(resourceList == null) return this.BadRequest(); + + string resources = resourceList.Resources + .Where(FileHelper.ResourceExists) + .Aggregate("", (current, hash) => + current + LbpSerializer.StringElement("resource", hash)); + + return this.Ok(resources); } [HttpGet("r/{hash}")] diff --git a/ProjectLighthouse/Types/ResourceList.cs b/ProjectLighthouse/Types/ResourceList.cs new file mode 100644 index 00000000..0f81e905 --- /dev/null +++ b/ProjectLighthouse/Types/ResourceList.cs @@ -0,0 +1,9 @@ +using System.Xml.Serialization; + +namespace ProjectLighthouse.Types { + [XmlRoot("resource"), XmlType("resources")] + public class ResourceList { + [XmlElement("resource")] + public string[] Resources; + } +} \ No newline at end of file