mirror of
https://github.com/LBPUnion/ProjectLighthouse.git
synced 2025-07-30 00:38:38 +00:00
Check for resources that are already uploaded in /filterResources
Consider a part 2 to closing #16.
This commit is contained in:
parent
5566a7d7f2
commit
4368019fe7
2 changed files with 25 additions and 1 deletions
|
@ -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}")]
|
||||
|
|
9
ProjectLighthouse/Types/ResourceList.cs
Normal file
9
ProjectLighthouse/Types/ResourceList.cs
Normal file
|
@ -0,0 +1,9 @@
|
|||
using System.Xml.Serialization;
|
||||
|
||||
namespace ProjectLighthouse.Types {
|
||||
[XmlRoot("resource"), XmlType("resources")]
|
||||
public class ResourceList {
|
||||
[XmlElement("resource")]
|
||||
public string[] Resources;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue