|
|
|
@ -1,5 +1,8 @@
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using Newtonsoft.Json;
|
|
|
|
|
using Newtonsoft.Json.Linq;
|
|
|
|
|
using NzbDrone.Core.Profiles.Releases;
|
|
|
|
|
using Sonarr.Http.REST;
|
|
|
|
|
|
|
|
|
@ -9,8 +12,9 @@ namespace Sonarr.Api.V3.Profiles.Release
|
|
|
|
|
{
|
|
|
|
|
public string Name { get; set; }
|
|
|
|
|
public bool Enabled { get; set; }
|
|
|
|
|
public List<string> Required { get; set; }
|
|
|
|
|
public List<string> Ignored { get; set; }
|
|
|
|
|
// Is List<string>, string or JArray, we accept 'string' with POST for backward compatibility
|
|
|
|
|
public object Required { get; set; }
|
|
|
|
|
public object Ignored { get; set; }
|
|
|
|
|
public List<KeyValuePair<string, int>> Preferred { get; set; }
|
|
|
|
|
public bool IncludePreferredWhenRenaming { get; set; }
|
|
|
|
|
public int IndexerId { get; set; }
|
|
|
|
@ -18,8 +22,6 @@ namespace Sonarr.Api.V3.Profiles.Release
|
|
|
|
|
|
|
|
|
|
public ReleaseProfileResource()
|
|
|
|
|
{
|
|
|
|
|
Required = new List<string>();
|
|
|
|
|
Ignored = new List<string>();
|
|
|
|
|
Preferred = new List<KeyValuePair<string, int>>();
|
|
|
|
|
Tags = new HashSet<int>();
|
|
|
|
|
}
|
|
|
|
@ -36,8 +38,8 @@ namespace Sonarr.Api.V3.Profiles.Release
|
|
|
|
|
Id = model.Id,
|
|
|
|
|
Name = model.Name,
|
|
|
|
|
Enabled = model.Enabled,
|
|
|
|
|
Required = model.Required,
|
|
|
|
|
Ignored = model.Ignored,
|
|
|
|
|
Required = model.Required ?? new List<string>(),
|
|
|
|
|
Ignored = model.Ignored ?? new List<string>(),
|
|
|
|
|
Preferred = model.Preferred,
|
|
|
|
|
IncludePreferredWhenRenaming = model.IncludePreferredWhenRenaming,
|
|
|
|
|
IndexerId = model.IndexerId,
|
|
|
|
@ -54,8 +56,8 @@ namespace Sonarr.Api.V3.Profiles.Release
|
|
|
|
|
Id = resource.Id,
|
|
|
|
|
Name = resource.Name,
|
|
|
|
|
Enabled = resource.Enabled,
|
|
|
|
|
Required = resource.Required,
|
|
|
|
|
Ignored = resource.Ignored,
|
|
|
|
|
Required = resource.MapRequired(),
|
|
|
|
|
Ignored = resource.MapIgnored(),
|
|
|
|
|
Preferred = resource.Preferred,
|
|
|
|
|
IncludePreferredWhenRenaming = resource.IncludePreferredWhenRenaming,
|
|
|
|
|
IndexerId = resource.IndexerId,
|
|
|
|
@ -67,5 +69,33 @@ namespace Sonarr.Api.V3.Profiles.Release
|
|
|
|
|
{
|
|
|
|
|
return models.Select(ToResource).ToList();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static List<string> MapRequired(this ReleaseProfileResource profile) => ParseArray(profile.Required, "required");
|
|
|
|
|
public static List<string> MapIgnored(this ReleaseProfileResource profile) => ParseArray(profile.Ignored, "ignored");
|
|
|
|
|
|
|
|
|
|
private static List<string> ParseArray(object resource, string title)
|
|
|
|
|
{
|
|
|
|
|
if (resource == null)
|
|
|
|
|
{
|
|
|
|
|
return new List<string>();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (resource is List<string> list)
|
|
|
|
|
{
|
|
|
|
|
return list;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (resource is JArray jarray)
|
|
|
|
|
{
|
|
|
|
|
return jarray.ToObject<List<string>>();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (resource is string str)
|
|
|
|
|
{
|
|
|
|
|
return str.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries).ToList();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
throw new BadRequestException($"Invalid field {title}, should be string or string array");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|