From 4368019fe7e60be41fb62a631f5e3068405a2a11 Mon Sep 17 00:00:00 2001 From: jvyden Date: Wed, 20 Oct 2021 18:50:16 -0400 Subject: [PATCH] Check for resources that are already uploaded in /filterResources Consider a part 2 to closing #16. --- .../Controllers/ResourcesController.cs | 17 ++++++++++++++++- ProjectLighthouse/Types/ResourceList.cs | 9 +++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 ProjectLighthouse/Types/ResourceList.cs 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