Check for resources that are already uploaded in /filterResources

Consider a part 2 to closing #16.
This commit is contained in:
jvyden 2021-10-20 18:50:16 -04:00
commit 4368019fe7
No known key found for this signature in database
GPG key ID: 18BCF2BE0262B278
2 changed files with 25 additions and 1 deletions

View file

@ -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<IActionResult> 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}")]

View file

@ -0,0 +1,9 @@
using System.Xml.Serialization;
namespace ProjectLighthouse.Types {
[XmlRoot("resource"), XmlType("resources")]
public class ResourceList {
[XmlElement("resource")]
public string[] Resources;
}
}