Radarr/src/Radarr.Api.V3/ProviderResource.cs

73 lines
2.7 KiB
C#
Raw Permalink Normal View History

2018-11-23 07:03:32 +00:00
using System.Collections.Generic;
using NzbDrone.Common.Reflection;
using NzbDrone.Core.ThingiProvider;
using Radarr.Http.ClientSchema;
using Radarr.Http.REST;
namespace Radarr.Api.V3
2018-11-23 07:03:32 +00:00
{
2021-02-04 21:14:52 +00:00
public class ProviderResource<T> : RestResource
2018-11-23 07:03:32 +00:00
{
public string Name { get; set; }
public List<Field> Fields { get; set; }
public string ImplementationName { get; set; }
public string Implementation { get; set; }
public string ConfigContract { get; set; }
public string InfoLink { get; set; }
public ProviderMessage Message { get; set; }
public HashSet<int> Tags { get; set; }
2021-02-04 21:14:52 +00:00
public List<T> Presets { get; set; }
2018-11-23 07:03:32 +00:00
}
public class ProviderResourceMapper<TProviderResource, TProviderDefinition>
2021-02-04 21:14:52 +00:00
where TProviderResource : ProviderResource<TProviderResource>, new()
2018-11-23 07:03:32 +00:00
where TProviderDefinition : ProviderDefinition, new()
{
public virtual TProviderResource ToResource(TProviderDefinition definition)
{
return new TProviderResource
{
Id = definition.Id,
Name = definition.Name,
ImplementationName = definition.ImplementationName,
Implementation = definition.Implementation,
ConfigContract = definition.ConfigContract,
Message = definition.Message,
Tags = definition.Tags,
Fields = SchemaBuilder.ToSchema(definition.Settings),
2022-11-20 18:27:45 +00:00
// radarr/supported is an disambagation page. the # should be a header on the page with appropiate details/link
InfoLink = string.Format("https://wiki.servarr.com/radarr/supported#{0}",
2018-11-23 07:03:32 +00:00
definition.Implementation.ToLower())
};
}
public virtual TProviderDefinition ToModel(TProviderResource resource, TProviderDefinition existingDefinition)
2018-11-23 07:03:32 +00:00
{
2019-12-22 22:08:53 +00:00
if (resource == null)
{
return default(TProviderDefinition);
}
2018-11-23 07:03:32 +00:00
var definition = new TProviderDefinition
{
Id = resource.Id,
Name = resource.Name,
ImplementationName = resource.ImplementationName,
Implementation = resource.Implementation,
ConfigContract = resource.ConfigContract,
Message = resource.Message,
Tags = resource.Tags
};
var configContract = ReflectionExtensions.CoreAssembly.FindTypeByName(definition.ConfigContract);
definition.Settings = (IProviderConfig)SchemaBuilder.ReadFromSchema(resource.Fields, configContract, existingDefinition?.Settings);
2018-11-23 07:03:32 +00:00
return definition;
}
}
}