Allow uploading multiple resources for a level

Closes #16
This commit is contained in:
jvyden 2021-10-20 18:42:50 -04:00
commit 5566a7d7f2
No known key found for this signature in database
GPG key ID: 18BCF2BE0262B278
2 changed files with 15 additions and 3 deletions

View file

@ -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"));
}
/// <summary>

View file

@ -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) +