New: Better interface for creating custom formats

This commit is contained in:
ta264
2020-02-18 21:03:05 +00:00
committed by Qstick
parent a5bac30ef3
commit 241bf85f15
74 changed files with 2259 additions and 1090 deletions
@@ -2,6 +2,7 @@ using System.Collections.Generic;
using System.Linq;
using Newtonsoft.Json;
using NzbDrone.Core.CustomFormats;
using Radarr.Http.ClientSchema;
using Radarr.Http.REST;
namespace Radarr.Api.V3.CustomFormats
@@ -11,8 +12,7 @@ namespace Radarr.Api.V3.CustomFormats
[JsonProperty(DefaultValueHandling = DefaultValueHandling.Include)]
public override int Id { get; set; }
public string Name { get; set; }
public string FormatTags { get; set; }
public string Simplicity { get; set; }
public List<CustomFormatSpecificationSchema> Specifications { get; set; }
}
public static class CustomFormatResourceMapper
@@ -23,7 +23,7 @@ namespace Radarr.Api.V3.CustomFormats
{
Id = model.Id,
Name = model.Name,
FormatTags = string.Join(",", model.FormatTags.Select(t => t.Raw.ToUpper()).ToList()),
Specifications = model.Specifications.Select(x => x.ToSchema()).ToList(),
};
}
@@ -32,7 +32,7 @@ namespace Radarr.Api.V3.CustomFormats
return models.Select(m => m.ToResource()).ToList();
}
public static CustomFormat ToModel(this CustomFormatResource resource)
public static CustomFormat ToModel(this CustomFormatResource resource, List<ICustomFormatSpecification> specifications)
{
if (resource.Id == 0 && resource.Name == "None")
{
@@ -43,8 +43,18 @@ namespace Radarr.Api.V3.CustomFormats
{
Id = resource.Id,
Name = resource.Name,
FormatTags = resource.FormatTags.Split(',').Select(s => new FormatTag(s)).ToList()
Specifications = resource.Specifications.Select(x => MapSpecification(x, specifications)).ToList()
};
}
private static ICustomFormatSpecification MapSpecification(CustomFormatSpecificationSchema resource, List<ICustomFormatSpecification> specifications)
{
var type = specifications.SingleOrDefault(x => x.GetType().Name == resource.Implementation).GetType();
var spec = (ICustomFormatSpecification)SchemaBuilder.ReadFromSchema(resource.Fields, type);
spec.Name = resource.Name;
spec.Negate = resource.Negate;
spec.Required = resource.Required;
return spec;
}
}
}