parent
c14ef7bee7
commit
2d53ec24f8
@ -0,0 +1,26 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.Controllers;
|
||||
using NzbDrone.Common.Composition;
|
||||
|
||||
namespace NzbDrone.Host
|
||||
{
|
||||
public class ControllerActivator : IControllerActivator
|
||||
{
|
||||
private readonly IContainer _container;
|
||||
|
||||
public ControllerActivator(IContainer container)
|
||||
{
|
||||
_container = container;
|
||||
}
|
||||
|
||||
public object Create(ControllerContext context)
|
||||
{
|
||||
return _container.Resolve(context.ActionDescriptor.ControllerTypeInfo.AsType());
|
||||
}
|
||||
|
||||
public void Release(ControllerContext context, object controller)
|
||||
{
|
||||
// Nothing to do
|
||||
}
|
||||
}
|
||||
}
|
@ -1,10 +0,0 @@
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
|
||||
namespace Radarr.Host.Middleware
|
||||
{
|
||||
public interface IAspNetCoreMiddleware
|
||||
{
|
||||
int Order { get; }
|
||||
void Attach(IApplicationBuilder appBuilder);
|
||||
}
|
||||
}
|
@ -1,29 +0,0 @@
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Nancy.Bootstrapper;
|
||||
using Nancy.Owin;
|
||||
|
||||
namespace Radarr.Host.Middleware
|
||||
{
|
||||
public class NancyMiddleware : IAspNetCoreMiddleware
|
||||
{
|
||||
private readonly INancyBootstrapper _nancyBootstrapper;
|
||||
|
||||
public int Order => 2;
|
||||
|
||||
public NancyMiddleware(INancyBootstrapper nancyBootstrapper)
|
||||
{
|
||||
_nancyBootstrapper = nancyBootstrapper;
|
||||
}
|
||||
|
||||
public void Attach(IApplicationBuilder appBuilder)
|
||||
{
|
||||
var options = new NancyOptions
|
||||
{
|
||||
Bootstrapper = _nancyBootstrapper,
|
||||
PerformPassThrough = context => context.Request.Path.StartsWith("/signalr")
|
||||
};
|
||||
|
||||
appBuilder.UseOwin(x => x.UseNancy(options));
|
||||
}
|
||||
}
|
||||
}
|
@ -1,72 +0,0 @@
|
||||
using System;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.SignalR;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using NLog;
|
||||
using NzbDrone.Common.Composition;
|
||||
using NzbDrone.Core.Configuration;
|
||||
using NzbDrone.SignalR;
|
||||
|
||||
namespace Radarr.Host.Middleware
|
||||
{
|
||||
public class SignalRMiddleware : IAspNetCoreMiddleware
|
||||
{
|
||||
private readonly IContainer _container;
|
||||
private readonly Logger _logger;
|
||||
private static string API_KEY;
|
||||
private static string URL_BASE;
|
||||
public int Order => 1;
|
||||
|
||||
public SignalRMiddleware(IContainer container,
|
||||
IConfigFileProvider configFileProvider,
|
||||
Logger logger)
|
||||
{
|
||||
_container = container;
|
||||
_logger = logger;
|
||||
API_KEY = configFileProvider.ApiKey;
|
||||
URL_BASE = configFileProvider.UrlBase;
|
||||
}
|
||||
|
||||
public void Attach(IApplicationBuilder appBuilder)
|
||||
{
|
||||
appBuilder.UseWebSockets();
|
||||
|
||||
appBuilder.Use(async (context, next) =>
|
||||
{
|
||||
if (context.Request.Path.StartsWithSegments("/signalr") &&
|
||||
!context.Request.Path.Value.EndsWith("/negotiate"))
|
||||
{
|
||||
if (!context.Request.Query.ContainsKey("access_token") ||
|
||||
context.Request.Query["access_token"] != API_KEY)
|
||||
{
|
||||
context.Response.StatusCode = 401;
|
||||
await context.Response.WriteAsync("Unauthorized");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
await next();
|
||||
}
|
||||
catch (OperationCanceledException e)
|
||||
{
|
||||
// Demote the exception to trace logging so users don't worry (as much).
|
||||
_logger.Trace(e);
|
||||
}
|
||||
});
|
||||
|
||||
appBuilder.UseEndpoints(x =>
|
||||
{
|
||||
x.MapHub<MessageHub>(URL_BASE + "/signalr/messages");
|
||||
});
|
||||
|
||||
// This is a side effect of haing multiple IoC containers, TinyIoC and whatever
|
||||
// Kestrel/SignalR is using. Ideally we'd have one IoC container, but that's non-trivial with TinyIoC
|
||||
// TODO: Use a single IoC container if supported for TinyIoC or if we switch to another system (ie Autofac).
|
||||
var hubContext = appBuilder.ApplicationServices.GetService<IHubContext<MessageHub>>();
|
||||
_container.Register(hubContext);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,55 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using NzbDrone.Core.Blocklisting;
|
||||
using NzbDrone.Core.CustomFormats;
|
||||
using NzbDrone.Core.Datastore;
|
||||
using Radarr.Http;
|
||||
using Radarr.Http.Extensions;
|
||||
using Radarr.Http.REST.Attributes;
|
||||
|
||||
namespace Radarr.Api.V3.Blocklist
|
||||
{
|
||||
[V3ApiController]
|
||||
public class BlocklistController : Controller
|
||||
{
|
||||
private readonly IBlocklistService _blocklistService;
|
||||
private readonly ICustomFormatCalculationService _formatCalculator;
|
||||
|
||||
public BlocklistController(IBlocklistService blocklistService,
|
||||
ICustomFormatCalculationService formatCalculator)
|
||||
{
|
||||
_blocklistService = blocklistService;
|
||||
_formatCalculator = formatCalculator;
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public PagingResource<BlocklistResource> GetBlocklist()
|
||||
{
|
||||
var pagingResource = Request.ReadPagingResourceFromRequest<BlocklistResource>();
|
||||
var pagingSpec = pagingResource.MapToPagingSpec<BlocklistResource, NzbDrone.Core.Blocklisting.Blocklist>("date", SortDirection.Descending);
|
||||
|
||||
return pagingSpec.ApplyToPage(_blocklistService.Paged, model => BlocklistResourceMapper.MapToResource(model, _formatCalculator));
|
||||
}
|
||||
|
||||
[HttpGet("movie")]
|
||||
public List<BlocklistResource> GetMovieBlocklist(int movieId)
|
||||
{
|
||||
return _blocklistService.GetByMovieId(movieId).Select(h => BlocklistResourceMapper.MapToResource(h, _formatCalculator)).ToList();
|
||||
}
|
||||
|
||||
[RestDeleteById]
|
||||
public void DeleteBlocklist(int id)
|
||||
{
|
||||
_blocklistService.Delete(id);
|
||||
}
|
||||
|
||||
[HttpDelete("bulk")]
|
||||
public object Remove([FromBody] BlocklistBulkResource resource)
|
||||
{
|
||||
_blocklistService.Delete(resource.Ids);
|
||||
|
||||
return new object();
|
||||
}
|
||||
}
|
||||
}
|
@ -1,66 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using NzbDrone.Core.Blocklisting;
|
||||
using NzbDrone.Core.CustomFormats;
|
||||
using NzbDrone.Core.Datastore;
|
||||
using Radarr.Http;
|
||||
using Radarr.Http.Extensions;
|
||||
using Radarr.Http.REST;
|
||||
|
||||
namespace Radarr.Api.V3.Blocklist
|
||||
{
|
||||
public class BlocklistModule : RadarrRestModule<BlocklistResource>
|
||||
{
|
||||
private readonly IBlocklistService _blocklistService;
|
||||
private readonly ICustomFormatCalculationService _formatCalculator;
|
||||
|
||||
public BlocklistModule(IBlocklistService blocklistService,
|
||||
ICustomFormatCalculationService formatCalculator)
|
||||
{
|
||||
_blocklistService = blocklistService;
|
||||
_formatCalculator = formatCalculator;
|
||||
|
||||
GetResourcePaged = GetBlocklist;
|
||||
DeleteResource = DeleteBlocklist;
|
||||
|
||||
Get("/movie", x => GetMovieBlocklist());
|
||||
Delete("/bulk", x => Remove());
|
||||
}
|
||||
|
||||
private PagingResource<BlocklistResource> GetBlocklist(PagingResource<BlocklistResource> pagingResource)
|
||||
{
|
||||
var pagingSpec = pagingResource.MapToPagingSpec<BlocklistResource, NzbDrone.Core.Blocklisting.Blocklist>("date", SortDirection.Descending);
|
||||
|
||||
return ApplyToPage(_blocklistService.Paged, pagingSpec, (blocklist) => BlocklistResourceMapper.MapToResource(blocklist, _formatCalculator));
|
||||
}
|
||||
|
||||
private List<BlocklistResource> GetMovieBlocklist()
|
||||
{
|
||||
var queryMovieId = Request.Query.MovieId;
|
||||
|
||||
if (!queryMovieId.HasValue)
|
||||
{
|
||||
throw new BadRequestException("movieId is missing");
|
||||
}
|
||||
|
||||
int movieId = Convert.ToInt32(queryMovieId.Value);
|
||||
|
||||
return _blocklistService.GetByMovieId(movieId).Select(h => BlocklistResourceMapper.MapToResource(h, _formatCalculator)).ToList();
|
||||
}
|
||||
|
||||
private void DeleteBlocklist(int id)
|
||||
{
|
||||
_blocklistService.Delete(id);
|
||||
}
|
||||
|
||||
private object Remove()
|
||||
{
|
||||
var resource = Request.Body.FromJson<BlocklistBulkResource>();
|
||||
|
||||
_blocklistService.Delete(resource.Ids);
|
||||
|
||||
return new object();
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,48 @@
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using NzbDrone.Core.Configuration;
|
||||
using Radarr.Http.REST;
|
||||
using Radarr.Http.REST.Attributes;
|
||||
|
||||
namespace Radarr.Api.V3.Config
|
||||
{
|
||||
public abstract class ConfigController<TResource> : RestController<TResource>
|
||||
where TResource : RestResource, new()
|
||||
{
|
||||
private readonly IConfigService _configService;
|
||||
|
||||
protected ConfigController(IConfigService configService)
|
||||
{
|
||||
_configService = configService;
|
||||
}
|
||||
|
||||
public override TResource GetResourceById(int id)
|
||||
{
|
||||
return GetConfig();
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public TResource GetConfig()
|
||||
{
|
||||
var resource = ToResource(_configService);
|
||||
resource.Id = 1;
|
||||
|
||||
return resource;
|
||||
}
|
||||
|
||||
[RestPutById]
|
||||
public ActionResult<TResource> SaveConfig(TResource resource)
|
||||
{
|
||||
var dictionary = resource.GetType()
|
||||
.GetProperties(BindingFlags.Instance | BindingFlags.Public)
|
||||
.ToDictionary(prop => prop.Name, prop => prop.GetValue(resource, null));
|
||||
|
||||
_configService.SaveConfigDictionary(dictionary);
|
||||
|
||||
return Accepted(resource.Id);
|
||||
}
|
||||
|
||||
protected abstract TResource ToResource(IConfigService model);
|
||||
}
|
||||
}
|
@ -1,10 +1,12 @@
|
||||
using NzbDrone.Core.Configuration;
|
||||
using Radarr.Http;
|
||||
|
||||
namespace Radarr.Api.V3.Config
|
||||
{
|
||||
public class DownloadClientConfigModule : RadarrConfigModule<DownloadClientConfigResource>
|
||||
[V3ApiController("config/downloadclient")]
|
||||
public class DownloadClientConfigController : ConfigController<DownloadClientConfigResource>
|
||||
{
|
||||
public DownloadClientConfigModule(IConfigService configService)
|
||||
public DownloadClientConfigController(IConfigService configService)
|
||||
: base(configService)
|
||||
{
|
||||
}
|
@ -1,11 +1,14 @@
|
||||
using NzbDrone.Core.Configuration;
|
||||
using Radarr.Http;
|
||||
using Radarr.Http.Validation;
|
||||
|
||||
namespace Radarr.Api.V3.Config
|
||||
{
|
||||
public class ImportListConfigModule : RadarrConfigModule<ImportListConfigResource>
|
||||
[V3ApiController("config/importlist")]
|
||||
|
||||
public class ImportListConfigController : ConfigController<ImportListConfigResource>
|
||||
{
|
||||
public ImportListConfigModule(IConfigService configService)
|
||||
public ImportListConfigController(IConfigService configService)
|
||||
: base(configService)
|
||||
{
|
||||
SharedValidator.RuleFor(c => c.ImportListSyncInterval)
|
@ -1,12 +1,14 @@
|
||||
using FluentValidation;
|
||||
using NzbDrone.Core.Configuration;
|
||||
using Radarr.Http;
|
||||
using Radarr.Http.Validation;
|
||||
|
||||
namespace Radarr.Api.V3.Config
|
||||
{
|
||||
public class IndexerConfigModule : RadarrConfigModule<IndexerConfigResource>
|
||||
[V3ApiController("config/indexer")]
|
||||
public class IndexerConfigController : ConfigController<IndexerConfigResource>
|
||||
{
|
||||
public IndexerConfigModule(IConfigService configService)
|
||||
public IndexerConfigController(IConfigService configService)
|
||||
: base(configService)
|
||||
{
|
||||
SharedValidator.RuleFor(c => c.MinimumAge)
|
@ -1,10 +1,12 @@
|
||||
using NzbDrone.Core.Configuration;
|
||||
using Radarr.Http;
|
||||
|
||||
namespace Radarr.Api.V3.Config
|
||||
{
|
||||
public class MetadataConfigModule : RadarrConfigModule<MetadataConfigResource>
|
||||
[V3ApiController("config/metadata")]
|
||||
public class MetadataConfigController : ConfigController<MetadataConfigResource>
|
||||
{
|
||||
public MetadataConfigModule(IConfigService configService)
|
||||
public MetadataConfigController(IConfigService configService)
|
||||
: base(configService)
|
||||
{
|
||||
}
|
@ -1,53 +0,0 @@
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using NzbDrone.Core.Configuration;
|
||||
using Radarr.Http;
|
||||
using Radarr.Http.REST;
|
||||
|
||||
namespace Radarr.Api.V3.Config
|
||||
{
|
||||
public abstract class RadarrConfigModule<TResource> : RadarrRestModule<TResource>
|
||||
where TResource : RestResource, new()
|
||||
{
|
||||
private readonly IConfigService _configService;
|
||||
|
||||
protected RadarrConfigModule(IConfigService configService)
|
||||
: this(new TResource().ResourceName.Replace("config", ""), configService)
|
||||
{
|
||||
}
|
||||
|
||||
protected RadarrConfigModule(string resource, IConfigService configService)
|
||||
: base("config/" + resource.Trim('/'))
|
||||
{
|
||||
_configService = configService;
|
||||
|
||||
GetResourceSingle = GetConfig;
|
||||
GetResourceById = GetConfig;
|
||||
UpdateResource = SaveConfig;
|
||||
}
|
||||
|
||||
private TResource GetConfig()
|
||||
{
|
||||
var resource = ToResource(_configService);
|
||||
resource.Id = 1;
|
||||
|
||||
return resource;
|
||||
}
|
||||
|
||||
protected abstract TResource ToResource(IConfigService model);
|
||||
|
||||
private TResource GetConfig(int id)
|
||||
{
|
||||
return GetConfig();
|
||||
}
|
||||
|
||||
private void SaveConfig(TResource resource)
|
||||
{
|
||||
var dictionary = resource.GetType()
|
||||
.GetProperties(BindingFlags.Instance | BindingFlags.Public)
|
||||
.ToDictionary(prop => prop.Name, prop => prop.GetValue(resource, null));
|
||||
|
||||
_configService.SaveConfigDictionary(dictionary);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,10 +1,12 @@
|
||||
using NzbDrone.Core.Configuration;
|
||||
using Radarr.Http;
|
||||
|
||||
namespace Radarr.Api.V3.Config
|
||||
{
|
||||
public class UiConfigModule : RadarrConfigModule<UiConfigResource>
|
||||
[V3ApiController("config/ui")]
|
||||
public class UiConfigController : ConfigController<UiConfigResource>
|
||||
{
|
||||
public UiConfigModule(IConfigService configService)
|
||||
public UiConfigController(IConfigService configService)
|
||||
: base(configService)
|
||||
{
|
||||
}
|
@ -1,36 +1,32 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using NzbDrone.Core.Movies.Credits;
|
||||
using Radarr.Http;
|
||||
using Radarr.Http.REST;
|
||||
|
||||
namespace Radarr.Api.V3.Credits
|
||||
{
|
||||
public class CreditModule : RadarrRestModule<CreditResource>
|
||||
[V3ApiController]
|
||||
public class CreditController : RestController<CreditResource>
|
||||
{
|
||||
private readonly ICreditService _creditService;
|
||||
|
||||
public CreditModule(ICreditService creditService)
|
||||
public CreditController(ICreditService creditService)
|
||||
{
|
||||
_creditService = creditService;
|
||||
|
||||
GetResourceById = GetCredit;
|
||||
GetResourceAll = GetCredits;
|
||||
}
|
||||
|
||||
private CreditResource GetCredit(int id)
|
||||
public override CreditResource GetResourceById(int id)
|
||||
{
|
||||
return _creditService.GetById(id).ToResource();
|
||||
}
|
||||
|
||||
private List<CreditResource> GetCredits()
|
||||
[HttpGet]
|
||||
public List<CreditResource> GetCredits(int? movieId)
|
||||
{
|
||||
var movieIdQuery = Request.Query.MovieId;
|
||||
|
||||
if (movieIdQuery.HasValue)
|
||||
if (movieId.HasValue)
|
||||
{
|
||||
int movieId = Convert.ToInt32(movieIdQuery.Value);
|
||||
|
||||
return _creditService.GetAllCreditsForMovie(movieId).ToResource();
|
||||
return _creditService.GetAllCreditsForMovie(movieId.Value).ToResource();
|
||||
}
|
||||
|
||||
return _creditService.GetAllCredits().ToResource();
|
@ -0,0 +1,52 @@
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using NzbDrone.Core.CustomFilters;
|
||||
using Radarr.Http;
|
||||
using Radarr.Http.REST;
|
||||
using Radarr.Http.REST.Attributes;
|
||||
|
||||
namespace Radarr.Api.V3.CustomFilters
|
||||
{
|
||||
[V3ApiController]
|
||||
public class CustomFilterController : RestController<CustomFilterResource>
|
||||
{
|
||||
private readonly ICustomFilterService _customFilterService;
|
||||
|
||||
public CustomFilterController(ICustomFilterService customFilterService)
|
||||
{
|
||||
_customFilterService = customFilterService;
|
||||
}
|
||||
|
||||
public override CustomFilterResource GetResourceById(int id)
|
||||
{
|
||||
return _customFilterService.Get(id).ToResource();
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public List<CustomFilterResource> GetCustomFilters()
|
||||
{
|
||||
return _customFilterService.All().ToResource();
|
||||
}
|
||||
|
||||
[RestPostById]
|
||||
public ActionResult<CustomFilterResource> AddCustomFilter(CustomFilterResource resource)
|
||||
{
|
||||
var customFilter = _customFilterService.Add(resource.ToModel());
|
||||
|
||||
return Created(customFilter.Id);
|
||||
}
|
||||
|
||||
[RestPutById]
|
||||
public ActionResult<CustomFilterResource> UpdateCustomFilter(CustomFilterResource resource)
|
||||
{
|
||||
_customFilterService.Update(resource.ToModel());
|
||||
return Accepted(resource.Id);
|
||||
}
|
||||
|
||||
[RestDeleteById]
|
||||
public void DeleteCustomResource(int id)
|
||||
{
|
||||
_customFilterService.Delete(id);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,49 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
using NzbDrone.Core.CustomFilters;
|
||||
using Radarr.Http;
|
||||
|
||||
namespace Radarr.Api.V3.CustomFilters
|
||||
{
|
||||
public class CustomFilterModule : RadarrRestModule<CustomFilterResource>
|
||||
{
|
||||
private readonly ICustomFilterService _customFilterService;
|
||||
|
||||
public CustomFilterModule(ICustomFilterService customFilterService)
|
||||
{
|
||||
_customFilterService = customFilterService;
|
||||
|
||||
GetResourceById = GetCustomFilter;
|
||||
GetResourceAll = GetCustomFilters;
|
||||
CreateResource = AddCustomFilter;
|
||||
UpdateResource = UpdateCustomFilter;
|
||||
DeleteResource = DeleteCustomResource;
|
||||
}
|
||||
|
||||
private CustomFilterResource GetCustomFilter(int id)
|
||||
{
|
||||
return _customFilterService.Get(id).ToResource();
|
||||
}
|
||||
|
||||
private List<CustomFilterResource> GetCustomFilters()
|
||||
{
|
||||
return _customFilterService.All().ToResource();
|
||||
}
|
||||
|
||||
private int AddCustomFilter(CustomFilterResource resource)
|
||||
{
|
||||
var customFilter = _customFilterService.Add(resource.ToModel());
|
||||
|
||||
return customFilter.Id;
|
||||
}
|
||||
|
||||
private void UpdateCustomFilter(CustomFilterResource resource)
|
||||
{
|
||||
_customFilterService.Update(resource.ToModel());
|
||||
}
|
||||
|
||||
private void DeleteCustomResource(int id)
|
||||
{
|
||||
_customFilterService.Delete(id);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,20 +1,21 @@
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using NzbDrone.Core.DiskSpace;
|
||||
using Radarr.Http;
|
||||
|
||||
namespace Radarr.Api.V3.DiskSpace
|
||||
{
|
||||
public class DiskSpaceModule : RadarrRestModule<DiskSpaceResource>
|
||||
[V3ApiController("diskspace")]
|
||||
public class DiskSpaceController : Controller
|
||||
{
|
||||
private readonly IDiskSpaceService _diskSpaceService;
|
||||
|
||||
public DiskSpaceModule(IDiskSpaceService diskSpaceService)
|
||||
: base("diskspace")
|
||||
public DiskSpaceController(IDiskSpaceService diskSpaceService)
|
||||
{
|
||||
_diskSpaceService = diskSpaceService;
|
||||
GetResourceAll = GetFreeSpace;
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public List<DiskSpaceResource> GetFreeSpace()
|
||||
{
|
||||
return _diskSpaceService.GetFreeSpace().ConvertAll(DiskSpaceResourceMapper.MapToResource);
|
@ -1,12 +1,14 @@
|
||||
using NzbDrone.Core.Download;
|
||||
using Radarr.Http;
|
||||
|
||||
namespace Radarr.Api.V3.DownloadClient
|
||||
{
|
||||
public class DownloadClientModule : ProviderModuleBase<DownloadClientResource, IDownloadClient, DownloadClientDefinition>
|
||||
[V3ApiController]
|
||||
public class DownloadClientController : ProviderControllerBase<DownloadClientResource, IDownloadClient, DownloadClientDefinition>
|
||||
{
|
||||
public static readonly DownloadClientResourceMapper ResourceMapper = new DownloadClientResourceMapper();
|
||||
|
||||
public DownloadClientModule(IDownloadClientFactory downloadClientFactory)
|
||||
public DownloadClientController(IDownloadClientFactory downloadClientFactory)
|
||||
: base(downloadClientFactory, "downloadclient", ResourceMapper)
|
||||
{
|
||||
}
|
@ -1,40 +1,35 @@
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using NzbDrone.Core.Extras.Files;
|
||||
using NzbDrone.Core.Extras.Metadata.Files;
|
||||
using NzbDrone.Core.Extras.Others;
|
||||
using NzbDrone.Core.Extras.Subtitles;
|
||||
using Radarr.Http;
|
||||
using Radarr.Http.REST;
|
||||
|
||||
namespace Radarr.Api.V3.ExtraFiles
|
||||
{
|
||||
public class ExtraFileModule : RadarrRestModule<ExtraFileResource>
|
||||
[V3ApiController("extrafile")]
|
||||
public class ExtraFileController : Controller
|
||||
{
|
||||
private readonly IExtraFileService<SubtitleFile> _subtitleFileService;
|
||||
private readonly IExtraFileService<MetadataFile> _metadataFileService;
|
||||
private readonly IExtraFileService<OtherExtraFile> _otherFileService;
|
||||
|
||||
public ExtraFileModule(IExtraFileService<SubtitleFile> subtitleFileService, IExtraFileService<MetadataFile> metadataFileService, IExtraFileService<OtherExtraFile> otherExtraFileService)
|
||||
: base("/extrafile")
|
||||
public ExtraFileController(IExtraFileService<SubtitleFile> subtitleFileService, IExtraFileService<MetadataFile> metadataFileService, IExtraFileService<OtherExtraFile> otherExtraFileService)
|
||||
{
|
||||
_subtitleFileService = subtitleFileService;
|
||||
_metadataFileService = metadataFileService;
|
||||
_otherFileService = otherExtraFileService;
|
||||
GetResourceAll = GetFiles;
|
||||
}
|
||||
|
||||
private List<ExtraFileResource> GetFiles()
|
||||
[HttpGet]
|
||||
public List<ExtraFileResource> GetFiles(int movieId)
|
||||
{
|
||||
if (!Request.Query.MovieId.HasValue)
|
||||
{
|
||||
throw new BadRequestException("MovieId is missing");
|
||||
}
|
||||
|
||||
var extraFiles = new List<ExtraFileResource>();
|
||||
|
||||
List<SubtitleFile> subtitleFiles = _subtitleFileService.GetFilesByMovie(Request.Query.MovieId);
|
||||
List<MetadataFile> metadataFiles = _metadataFileService.GetFilesByMovie(Request.Query.MovieId);
|
||||
List<OtherExtraFile> otherExtraFiles = _otherFileService.GetFilesByMovie(Request.Query.MovieId);
|
||||
List<SubtitleFile> subtitleFiles = _subtitleFileService.GetFilesByMovie(movieId);
|
||||
List<MetadataFile> metadataFiles = _metadataFileService.GetFilesByMovie(movieId);
|
||||
List<OtherExtraFile> otherExtraFiles = _otherFileService.GetFilesByMovie(movieId);
|
||||
|
||||
extraFiles.AddRange(subtitleFiles.ToResource());
|
||||
extraFiles.AddRange(metadataFiles.ToResource());
|
@ -1,29 +1,39 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using NzbDrone.Core.Datastore.Events;
|
||||
using NzbDrone.Core.HealthCheck;
|
||||
using NzbDrone.Core.Messaging.Events;
|
||||
using NzbDrone.SignalR;
|
||||
using Radarr.Http;
|
||||
using Radarr.Http.REST;
|
||||
|
||||
namespace Radarr.Api.V3.Health
|
||||
{
|
||||
public class HealthModule : RadarrRestModuleWithSignalR<HealthResource, HealthCheck>,
|
||||
[V3ApiController]
|
||||
public class HealthController : RestControllerWithSignalR<HealthResource, HealthCheck>,
|
||||
IHandle<HealthCheckCompleteEvent>
|
||||
{
|
||||
private readonly IHealthCheckService _healthCheckService;
|
||||
|
||||
public HealthModule(IBroadcastSignalRMessage signalRBroadcaster, IHealthCheckService healthCheckService)
|
||||
public HealthController(IBroadcastSignalRMessage signalRBroadcaster, IHealthCheckService healthCheckService)
|
||||
: base(signalRBroadcaster)
|
||||
{
|
||||
_healthCheckService = healthCheckService;
|
||||
GetResourceAll = GetHealth;
|
||||
}
|
||||
|
||||
private List<HealthResource> GetHealth()
|
||||
public override HealthResource GetResourceById(int id)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public List<HealthResource> GetHealth()
|
||||
{
|
||||
return _healthCheckService.Results().ToResource();
|
||||
}
|
||||
|
||||
[NonAction]
|
||||
public void Handle(HealthCheckCompleteEvent message)
|
||||
{
|
||||
BroadcastResourceChange(ModelAction.Sync);
|
@ -1,63 +1,62 @@
|
||||
using System.Collections.Generic;
|
||||
using FluentValidation;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using NzbDrone.Core.ImportLists.ImportExclusions;
|
||||
using Radarr.Http;
|
||||
using Radarr.Http.Extensions;
|
||||
using Radarr.Http.REST;
|
||||
using Radarr.Http.REST.Attributes;
|
||||
|
||||
namespace Radarr.Api.V3.ImportLists
|
||||
{
|
||||
public class ImportExclusionsModule : RadarrRestModule<ImportExclusionsResource>
|
||||
[V3ApiController("exclusions")]
|
||||
public class ImportExclusionsController : RestController<ImportExclusionsResource>
|
||||
{
|
||||
private readonly IImportExclusionsService _exclusionService;
|
||||
|
||||
public ImportExclusionsModule(IImportExclusionsService exclusionService)
|
||||
: base("exclusions")
|
||||
public ImportExclusionsController(IImportExclusionsService exclusionService)
|
||||
{
|
||||
_exclusionService = exclusionService;
|
||||
|
||||
GetResourceAll = GetAll;
|
||||
DeleteResource = RemoveExclusion;
|
||||
CreateResource = AddExclusion;
|
||||
GetResourceById = GetById;
|
||||
UpdateResource = UpdateExclusion;
|
||||
Post("/bulk", x => AddExclusions());
|
||||
|
||||
SharedValidator.RuleFor(c => c.TmdbId).GreaterThan(0);
|
||||
SharedValidator.RuleFor(c => c.MovieTitle).NotEmpty();
|
||||
SharedValidator.RuleFor(c => c.MovieYear).GreaterThan(0);
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public List<ImportExclusionsResource> GetAll()
|
||||
{
|
||||
return _exclusionService.GetAllExclusions().ToResource();
|
||||
}
|
||||
|
||||
public ImportExclusionsResource GetById(int id)
|
||||
public override ImportExclusionsResource GetResourceById(int id)
|
||||
{
|
||||
return _exclusionService.GetById(id).ToResource();
|
||||
}
|
||||
|
||||
private void UpdateExclusion(ImportExclusionsResource exclusionResource)
|
||||
[RestPutById]
|
||||
public ActionResult<ImportExclusionsResource> UpdateExclusion(ImportExclusionsResource exclusionResource)
|
||||
{
|
||||
var model = exclusionResource.ToModel();
|
||||
_exclusionService.Update(model);
|
||||
return Accepted(_exclusionService.Update(model));
|
||||
}
|
||||
|
||||
public int AddExclusion(ImportExclusionsResource exclusionResource)
|
||||
[RestPostById]
|
||||
public ActionResult<ImportExclusionsResource> AddExclusion(ImportExclusionsResource exclusionResource)
|
||||
{
|
||||
var model = exclusionResource.ToModel();
|
||||
|
||||
return _exclusionService.AddExclusion(model).Id;
|
||||
return Created(_exclusionService.AddExclusion(model).Id);
|
||||
}
|
||||
|
||||
public object AddExclusions()
|
||||
[HttpPost("bulk")]
|
||||
public object AddExclusions([FromBody] List<ImportExclusionsResource> resource)
|
||||
{
|
||||
var resource = Request.Body.FromJson<List<ImportExclusionsResource>>();
|
||||
var newMovies = resource.ToModel();
|
||||
|
||||
return _exclusionService.AddExclusions(newMovies).ToResource();
|
||||
}
|
||||
|
||||
[RestDeleteById]
|
||||
public void RemoveExclusion(int id)
|
||||
{
|
||||
_exclusionService.RemoveExclusion(new ImportExclusion { Id = id });
|
@ -1,12 +1,14 @@
|
||||
using NzbDrone.Core.Indexers;
|
||||
using Radarr.Http;
|
||||
|
||||
namespace Radarr.Api.V3.Indexers
|
||||
{
|
||||
public class IndexerModule : ProviderModuleBase<IndexerResource, IIndexer, IndexerDefinition>
|
||||
[V3ApiController]
|
||||
public class IndexerController : ProviderControllerBase<IndexerResource, IIndexer, IndexerDefinition>
|
||||
{
|
||||
public static readonly IndexerResourceMapper ResourceMapper = new IndexerResourceMapper();
|
||||
|
||||
public IndexerModule(IndexerFactory indexerFactory)
|
||||
public IndexerController(IndexerFactory indexerFactory)
|
||||
: base(indexerFactory, "indexer", ResourceMapper)
|
||||
{
|
||||
}
|
@ -1,19 +1,17 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using NzbDrone.Core.Parser.Model;
|
||||
using Radarr.Http;
|
||||
|
||||
namespace Radarr.Api.V3.Indexers
|
||||
{
|
||||
public class IndexerFlagModule : RadarrRestModule<IndexerFlagResource>
|
||||
[V3ApiController]
|
||||
public class IndexerFlagController : Controller
|
||||
{
|
||||
public IndexerFlagModule()
|
||||
{
|
||||
GetResourceAll = GetAll;
|
||||
}
|
||||
|
||||
private List<IndexerFlagResource> GetAll()
|
||||
[HttpGet]
|
||||
public List<IndexerFlagResource> GetAll()
|
||||
{
|
||||
return Enum.GetValues(typeof(IndexerFlags)).Cast<IndexerFlags>().Select(f => new IndexerFlagResource
|
||||
{
|
@ -1,26 +1,27 @@
|
||||
using System.Text.Json;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using NzbDrone.Common.Serializer;
|
||||
using NzbDrone.Core.Localization;
|
||||
using Radarr.Http;
|
||||
|
||||
namespace Radarr.Api.V3.Localization
|
||||
{
|
||||
public class LocalizationModule : RadarrRestModule<LocalizationResource>
|
||||
[V3ApiController]
|
||||
public class LocalizationController : Controller
|
||||
{
|
||||
private readonly ILocalizationService _localizationService;
|
||||
private readonly JsonSerializerOptions _serializerSettings;
|
||||
|
||||
public LocalizationModule(ILocalizationService localizationService)
|
||||
public LocalizationController(ILocalizationService localizationService)
|
||||
{
|
||||
_localizationService = localizationService;
|
||||
_serializerSettings = STJson.GetSerializerSettings();
|
||||
_serializerSettings.DictionaryKeyPolicy = null;
|
||||
_serializerSettings.PropertyNamingPolicy = null;
|
||||
|
||||
Get("/", x => GetLocalizationDictionary());
|
||||
}
|
||||
|
||||
private string GetLocalizationDictionary()
|
||||
[HttpGet]
|
||||
public string GetLocalizationDictionary()
|
||||
{
|
||||
return JsonSerializer.Serialize(_localizationService.GetLocalizationDictionary().ToResource(), _serializerSettings);
|
||||
}
|
@ -1,41 +1,33 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using NzbDrone.Core.Languages;
|
||||
using NzbDrone.Core.MediaFiles.MovieImport.Manual;
|
||||
using NzbDrone.Core.Qualities;
|
||||
using Radarr.Api.V3.Movies;
|
||||
using Radarr.Http;
|
||||
using Radarr.Http.Extensions;
|
||||
|
||||
namespace Radarr.Api.V3.ManualImport
|
||||
{
|
||||
public class ManualImportModule : RadarrRestModule<ManualImportResource>
|
||||
[V3ApiController]
|
||||
public class ManualImportController : Controller
|
||||
{
|
||||
private readonly IManualImportService _manualImportService;
|
||||
|
||||
public ManualImportModule(IManualImportService manualImportService)
|
||||
: base("/manualimport")
|
||||
public ManualImportController(IManualImportService manualImportService)
|
||||
{
|
||||
_manualImportService = manualImportService;
|
||||
|
||||
GetResourceAll = GetMediaFiles;
|
||||
Post("/", x => ReprocessItems());
|
||||
}
|
||||
|
||||
private List<ManualImportResource> GetMediaFiles()
|
||||
[HttpGet]
|
||||
public List<ManualImportResource> GetMediaFiles(string folder, string downloadId, int? movieId, bool filterExistingFiles = true)
|
||||
{
|
||||
var folder = (string)Request.Query.folder;
|
||||
var downloadId = (string)Request.Query.downloadId;
|
||||
var filterExistingFiles = Request.GetBooleanQueryParameter("filterExistingFiles", true);
|
||||
var movieId = Request.GetNullableIntegerQueryParameter("movieId", null);
|
||||
|
||||
return _manualImportService.GetMediaFiles(folder, downloadId, movieId, filterExistingFiles).ToResource().Select(AddQualityWeight).ToList();
|
||||
}
|
||||
|
||||
private object ReprocessItems()
|
||||
[HttpPost]
|
||||
public object ReprocessItems([FromBody] List<ManualImportReprocessResource> items)
|
||||
{
|
||||
var items = Request.Body.FromJson<List<ManualImportReprocessResource>>();
|
||||
|
||||
foreach (var item in items)
|
||||
{
|
||||
var processedItem = _manualImportService.ReprocessItem(item.Path, item.DownloadId, item.MovieId, item.Quality, item.Languages);
|
@ -1,12 +1,14 @@
|
||||
using NzbDrone.Core.Extras.Metadata;
|
||||
using Radarr.Http;
|
||||
|
||||
namespace Radarr.Api.V3.Metadata
|
||||
{
|
||||
public class MetadataModule : ProviderModuleBase<MetadataResource, IMetadata, MetadataDefinition>
|
||||
[V3ApiController]
|
||||
public class MetadataController : ProviderControllerBase<MetadataResource, IMetadata, MetadataDefinition>
|
||||
{
|
||||
public static readonly MetadataResourceMapper ResourceMapper = new MetadataResourceMapper();
|
||||
|
||||
public MetadataModule(IMetadataFactory metadataFactory)
|
||||
public MetadataController(IMetadataFactory metadataFactory)
|
||||
: base(metadataFactory, "metadata", ResourceMapper)
|
||||
{
|
||||
}
|
@ -0,0 +1,36 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using NzbDrone.Core.Movies.AlternativeTitles;
|
||||
using Radarr.Http;
|
||||
using Radarr.Http.REST;
|
||||
|
||||
namespace Radarr.Api.V3.Movies
|
||||
{
|
||||
[V3ApiController("alttitle")]
|
||||
public class AlternativeTitleController : RestController<AlternativeTitleResource>
|
||||
{
|
||||
private readonly IAlternativeTitleService _altTitleService;
|
||||
|
||||
public AlternativeTitleController(IAlternativeTitleService altTitleService)
|
||||
{
|
||||
_altTitleService = altTitleService;
|
||||
}
|
||||
|
||||
public override AlternativeTitleResource GetResourceById(int id)
|
||||
{
|
||||
return _altTitleService.GetById(id).ToResource();
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public List<AlternativeTitleResource> GetAltTitles(int? movieId)
|
||||
{
|
||||
if (movieId.HasValue)
|
||||
{
|
||||
return _altTitleService.GetAllTitlesForMovie(movieId.Value).ToResource();
|
||||
}
|
||||
|
||||
return _altTitleService.GetAllTitles().ToResource();
|
||||
}
|
||||
}
|
||||
}
|
@ -1,46 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using NzbDrone.Core.Messaging.Events;
|
||||
using NzbDrone.Core.Movies;
|
||||
using NzbDrone.Core.Movies.AlternativeTitles;
|
||||
using Radarr.Http;
|
||||
|
||||
namespace Radarr.Api.V3.Movies
|
||||
{
|
||||
public class AlternativeTitleModule : RadarrRestModule<AlternativeTitleResource>
|
||||
{
|
||||
private readonly IAlternativeTitleService _altTitleService;
|
||||
private readonly IMovieService _movieService;
|
||||
private readonly IEventAggregator _eventAggregator;
|
||||
|
||||
public AlternativeTitleModule(IAlternativeTitleService altTitleService, IMovieService movieService, IEventAggregator eventAggregator)
|
||||
: base("/alttitle")
|
||||
{
|
||||
_altTitleService = altTitleService;
|
||||
_movieService = movieService;
|
||||
_eventAggregator = eventAggregator;
|
||||
|
||||
GetResourceById = GetAltTitle;
|
||||
GetResourceAll = GetAltTitles;
|
||||
}
|
||||
|
||||
private AlternativeTitleResource GetAltTitle(int id)
|
||||
{
|
||||
return _altTitleService.GetById(id).ToResource();
|
||||
}
|
||||
|
||||
private List<AlternativeTitleResource> GetAltTitles()
|
||||
{
|
||||
var movieIdQuery = Request.Query.MovieId;
|
||||
|
||||
if (movieIdQuery.HasValue)
|
||||
{
|
||||
int movieId = Convert.ToInt32(movieIdQuery.Value);
|
||||
|
||||
return _altTitleService.GetAllTitlesForMovie(movieId).ToResource();
|
||||
}
|
||||
|
||||
return _altTitleService.GetAllTitles().ToResource();
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,25 @@
|
||||
using NzbDrone.Common.Cache;
|
||||
using Radarr.Http;
|
||||
using Radarr.Http.REST;
|
||||
|
||||
namespace Radarr.Api.V3.Movies
|
||||
{
|
||||
[V3ApiController("altyear")]
|
||||
public class AlternativeYearController : RestController<AlternativeYearResource>
|
||||
{
|
||||
private readonly ICached<int> _yearCache;
|
||||
|
||||
public AlternativeYearController(ICacheManager cacheManager)
|
||||
{
|
||||
_yearCache = cacheManager.GetCache<int>(GetType(), "altYears");
|
||||
}
|
||||
|
||||
public override AlternativeYearResource GetResourceById(int id)
|
||||
{
|
||||
return new AlternativeYearResource
|
||||
{
|
||||
Year = _yearCache.Find(id.ToString())
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
@ -1,31 +0,0 @@
|
||||
using NzbDrone.Common.Cache;
|
||||
using NzbDrone.Core.Messaging.Events;
|
||||
using NzbDrone.Core.Movies;
|
||||
using Radarr.Http;
|
||||
|
||||
namespace Radarr.Api.V3.Movies
|
||||
{
|
||||
public class AlternativeYearModule : RadarrRestModule<AlternativeYearResource>
|
||||
{
|
||||
private readonly IMovieService _movieService;
|
||||
private readonly ICached<int> _yearCache;
|
||||
private readonly IEventAggregator _eventAggregator;
|
||||
|
||||
public AlternativeYearModule(IMovieService movieService, ICacheManager cacheManager, IEventAggregator eventAggregator)
|
||||
: base("/altyear")
|
||||
{
|
||||
_movieService = movieService;
|
||||
GetResourceById = GetYear;
|
||||
_yearCache = cacheManager.GetCache<int>(GetType(), "altYears");
|
||||
_eventAggregator = eventAggregator;
|
||||
}
|
||||
|
||||
private AlternativeYearResource GetYear(int id)
|
||||
{
|
||||
return new AlternativeYearResource
|
||||
{
|
||||
Year = _yearCache.Find(id.ToString())
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,33 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using NzbDrone.Core.Movies;
|
||||
using Radarr.Http;
|
||||
using Radarr.Http.REST;
|
||||
|
||||
namespace Radarr.Api.V3.Movies
|
||||
{
|
||||
[V3ApiController("movie/import")]
|
||||
public class MovieImportController : RestController<MovieResource>
|
||||
{
|
||||
private readonly IAddMovieService _addMovieService;
|
||||
|
||||
public MovieImportController(IAddMovieService addMovieService)
|
||||
{
|
||||
_addMovieService = addMovieService;
|
||||
}
|
||||
|
||||
public override MovieResource GetResourceById(int id)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public object Import([FromBody] List<MovieResource> resource)
|
||||
{
|
||||
var newMovies = resource.ToModel();
|
||||
|
||||
return _addMovieService.AddMovies(newMovies).ToResource(0);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,28 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
using Nancy;
|
||||
using NzbDrone.Core.Movies;
|
||||
using Radarr.Http;
|
||||
using Radarr.Http.Extensions;
|
||||
|
||||
namespace Radarr.Api.V3.Movies
|
||||
{
|
||||
public class MovieImportModule : RadarrRestModule<MovieResource>
|
||||
{
|
||||
private readonly IAddMovieService _addMovieService;
|
||||
|
||||
public MovieImportModule(IAddMovieService addMovieService)
|
||||
: base("/movie/import")
|
||||
{
|
||||
_addMovieService = addMovieService;
|
||||
Post("/", x => Import());
|
||||
}
|
||||
|
||||
private object Import()
|
||||
{
|
||||
var resource = Request.Body.FromJson<List<MovieResource>>();
|
||||
var newMovies = resource.ToModel();
|
||||
|
||||
return _addMovieService.AddMovies(newMovies).ToResource(0);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,25 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using NzbDrone.Core.MediaFiles;
|
||||
using Radarr.Http;
|
||||
|
||||
namespace Radarr.Api.V3.Movies
|
||||
{
|
||||
[V3ApiController("rename")]
|
||||
public class RenameMovieController : Controller
|
||||
{
|
||||
private readonly IRenameMovieFileService _renameMovieFileService;
|
||||
|
||||
public RenameMovieController(IRenameMovieFileService renameMovieFileService)
|
||||
{
|
||||
_renameMovieFileService = renameMovieFileService;
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public List<RenameMovieResource> GetMovies(int movieId)
|
||||
{
|
||||
return _renameMovieFileService.GetRenamePreviews(movieId).ToResource();
|
||||
}
|
||||
}
|
||||
}
|
@ -1,36 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
using NzbDrone.Core.MediaFiles;
|
||||
using Radarr.Http;
|
||||
using Radarr.Http.REST;
|
||||
|
||||
namespace Radarr.Api.V3.Movies
|
||||
{
|
||||
public class RenameMovieModule : RadarrRestModule<RenameMovieResource>
|
||||
{
|
||||
private readonly IRenameMovieFileService _renameMovieFileService;
|
||||
|
||||
public RenameMovieModule(IRenameMovieFileService renameMovieFileService)
|
||||
: base("rename")
|
||||
{
|
||||
_renameMovieFileService = renameMovieFileService;
|
||||
|
||||
GetResourceAll = GetMovies;
|
||||
}
|
||||
|
||||
private List<RenameMovieResource> GetMovies()
|
||||
{
|
||||
int movieId;
|
||||
|
||||
if (Request.Query.MovieId.HasValue)
|
||||
{
|
||||
movieId = (int)Request.Query.MovieId;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new BadRequestException("movieId is missing");
|
||||
}
|
||||
|
||||
return _renameMovieFileService.GetRenamePreviews(movieId).ToResource();
|
||||
}
|
||||
}
|
||||
}
|
@ -1,12 +1,14 @@
|
||||
using NzbDrone.Core.Notifications;
|
||||
using Radarr.Http;
|
||||
|
||||
namespace Radarr.Api.V3.Notifications
|
||||
{
|
||||
public class NotificationModule : ProviderModuleBase<NotificationResource, INotification, NotificationDefinition>
|
||||
[V3ApiController]
|
||||
public class NotificationController : ProviderControllerBase<NotificationResource, INotification, NotificationDefinition>
|
||||
{
|
||||
public static readonly NotificationResourceMapper ResourceMapper = new NotificationResourceMapper();
|
||||
|
||||
public NotificationModule(NotificationFactory notificationFactory)
|
||||
public NotificationController(NotificationFactory notificationFactory)
|
||||
: base(notificationFactory, "notification", ResourceMapper)
|
||||
{
|
||||
}
|
@ -1,30 +1,28 @@
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using NzbDrone.Common.Extensions;
|
||||
using NzbDrone.Core.Configuration;
|
||||
using NzbDrone.Core.Exceptions;
|
||||
using NzbDrone.Core.Parser;
|
||||
using Radarr.Api.V3.Movies;
|
||||
using Radarr.Http;
|
||||
|
||||
namespace Radarr.Api.V3.Parse
|
||||
{
|
||||
public class ParseModule : RadarrRestModule<ParseResource>
|
||||
[V3ApiController]
|
||||
public class ParseController : Controller
|
||||
{
|
||||
private readonly IParsingService _parsingService;
|
||||
private readonly IConfigService _configService;
|
||||
|
||||
public ParseModule(IParsingService parsingService, IConfigService configService)
|
||||
public ParseController(IParsingService parsingService, IConfigService configService)
|
||||
{
|
||||
_parsingService = parsingService;
|
||||
_configService = configService;
|
||||
|
||||
GetResourceSingle = Parse;
|
||||
}
|
||||
|
||||
private ParseResource Parse()
|
||||
[HttpGet]
|
||||
public ParseResource Parse(string title)
|
||||
{
|
||||
var title = Request.Query.Title.Value as string;
|
||||
|
||||
if (title.IsNullOrWhiteSpace())
|
||||
{
|
||||
return null;
|
@ -1,21 +1,21 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using NzbDrone.Core.Profiles;
|
||||
using Radarr.Http;
|
||||
|
||||
namespace Radarr.Api.V3.Profiles.Quality
|
||||
{
|
||||
public class QualityProfileSchemaModule : RadarrRestModule<QualityProfileResource>
|
||||
[V3ApiController("qualityprofile/schema")]
|
||||
public class QualityProfileSchemaController : Controller
|
||||
{
|
||||
private readonly IProfileService _profileService;
|
||||
|
||||
public QualityProfileSchemaModule(IProfileService profileService)
|
||||
: base("/qualityprofile/schema")
|
||||
public QualityProfileSchemaController(IProfileService profileService)
|
||||
{
|
||||
_profileService = profileService;
|
||||
|
||||
GetResourceSingle = GetSchema;
|
||||
}
|
||||
|
||||
private QualityProfileResource GetSchema()
|
||||
[HttpGet]
|
||||
public QualityProfileResource GetSchema()
|
||||
{
|
||||
var qualityProfile = _profileService.GetDefaultProfile(string.Empty);
|
||||
|
@ -0,0 +1,54 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using NzbDrone.Core.Qualities;
|
||||
using Radarr.Http;
|
||||
using Radarr.Http.REST;
|
||||
using Radarr.Http.REST.Attributes;
|
||||
|
||||
namespace Radarr.Api.V3.Qualities
|
||||
{
|
||||
[V3ApiController]
|
||||
public class QualityDefinitionController : RestController<QualityDefinitionResource>
|
||||
{
|
||||
private readonly IQualityDefinitionService _qualityDefinitionService;
|
||||
|
||||
public QualityDefinitionController(IQualityDefinitionService qualityDefinitionService)
|
||||
{
|
||||
_qualityDefinitionService = qualityDefinitionService;
|
||||
}
|
||||
|
||||
[RestPutById]
|
||||
public ActionResult<QualityDefinitionResource> Update(QualityDefinitionResource resource)
|
||||
{
|
||||
var model = resource.ToModel();
|
||||
_qualityDefinitionService.Update(model);
|
||||
return Accepted(model.Id);
|
||||
}
|
||||
|
||||
public override QualityDefinitionResource GetResourceById(int id)
|
||||
{
|
||||
return _qualityDefinitionService.GetById(id).ToResource();
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public List<QualityDefinitionResource> GetAll()
|
||||
{
|
||||
return _qualityDefinitionService.All().ToResource();
|
||||
}
|
||||
|
||||
[HttpPut("update")]
|
||||
public object UpdateMany([FromBody] List<QualityDefinitionResource> resource)
|
||||
{
|
||||
//Read from request
|
||||
var qualityDefinitions = resource
|
||||
.ToModel()
|
||||
.ToList();
|
||||
|
||||
_qualityDefinitionService.UpdateMany(qualityDefinitions);
|
||||
|
||||
return Accepted(_qualityDefinitionService.All()
|
||||
.ToResource());
|
||||
}
|
||||
}
|
||||
}
|
@ -1,54 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Nancy;
|
||||
using NzbDrone.Core.Qualities;
|
||||
using Radarr.Http;
|
||||
using Radarr.Http.Extensions;
|
||||
|
||||
namespace Radarr.Api.V3.Qualities
|
||||
{
|
||||
public class QualityDefinitionModule : RadarrRestModule<QualityDefinitionResource>
|
||||
{
|
||||
private readonly IQualityDefinitionService _qualityDefinitionService;
|
||||
|
||||
public QualityDefinitionModule(IQualityDefinitionService qualityDefinitionService)
|
||||
{
|
||||
_qualityDefinitionService = qualityDefinitionService;
|
||||
|
||||
GetResourceAll = GetAll;
|
||||
GetResourceById = GetById;
|
||||
UpdateResource = Update;
|
||||
Put("/update", d => UpdateMany());
|
||||
}
|
||||
|
||||
private void Update(QualityDefinitionResource resource)
|
||||
{
|
||||
var model = resource.ToModel();
|
||||
_qualityDefinitionService.Update(model);
|
||||
}
|
||||
|
||||
private QualityDefinitionResource GetById(int id)
|
||||
{
|
||||
return _qualityDefinitionService.GetById(id).ToResource();
|
||||
}
|
||||
|
||||
private List<QualityDefinitionResource> GetAll()
|
||||
{
|
||||
return _qualityDefinitionService.All().ToResource();
|
||||
}
|
||||
|
||||
private object UpdateMany()
|
||||
{
|
||||
//Read from request
|
||||
var qualityDefinitions = Request.Body.FromJson<List<QualityDefinitionResource>>()
|
||||
.ToModel()
|
||||
.ToList();
|
||||
|
||||
_qualityDefinitionService.UpdateMany(qualityDefinitions);
|
||||
|
||||
return ResponseWithCode(_qualityDefinitionService.All()
|
||||
.ToResource(),
|
||||
HttpStatusCode.Accepted);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,55 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using NzbDrone.Core.Download;
|
||||
using NzbDrone.Core.Download.Pending;
|
||||
using Radarr.Http;
|
||||
using Radarr.Http.REST;
|
||||
|
||||
namespace Radarr.Api.V3.Queue
|
||||
{
|
||||
[V3ApiController("queue")]
|
||||
public class QueueActionController : Controller
|
||||
{
|
||||
private readonly IPendingReleaseService _pendingReleaseService;
|
||||
private readonly IDownloadService _downloadService;
|
||||
|
||||
public QueueActionController(IPendingReleaseService pendingReleaseService,
|
||||
IDownloadService downloadService)
|
||||
{
|
||||
_pendingReleaseService = pendingReleaseService;
|
||||
_downloadService = downloadService;
|
||||
}
|
||||
|
||||
[HttpPost("grab/{id:int}")]
|
||||
public object Grab(int id)
|
||||
{
|
||||
var pendingRelease = _pendingReleaseService.FindPendingQueueItem(id);
|
||||
|
||||
if (pendingRelease == null)
|
||||
{
|
||||
throw new NotFoundException();
|
||||
}
|
||||
|
||||
_downloadService.DownloadReport(pendingRelease.RemoteMovie);
|
||||
|
||||
return new object();
|
||||
}
|
||||
|
||||
[HttpPost("grab/bulk")]
|
||||
public object Grab([FromBody] QueueBulkResource resource)
|
||||
{
|
||||
foreach (var id in resource.Ids)
|
||||
{
|
||||
var pendingRelease = _pendingReleaseService.FindPendingQueueItem(id);
|
||||
|
||||
if (pendingRelease == null)
|
||||
{
|
||||
throw new NotFoundException();
|
||||
}
|
||||
|
||||
_downloadService.DownloadReport(pendingRelease.RemoteMovie);
|
||||
}
|
||||
|
||||
return new object();
|
||||
}
|
||||
}
|
||||
}
|
@ -1,179 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
using Nancy;
|
||||
using NzbDrone.Core.Download;
|
||||
using NzbDrone.Core.Download.Pending;
|
||||
using NzbDrone.Core.Download.TrackedDownloads;
|
||||
using NzbDrone.Core.Queue;
|
||||
using Radarr.Http;
|
||||
using Radarr.Http.Extensions;
|
||||
using Radarr.Http.REST;
|
||||
|
||||
namespace Radarr.Api.V3.Queue
|
||||
{
|
||||
public class QueueActionModule : RadarrRestModule<QueueResource>
|
||||
{
|
||||
private readonly IQueueService _queueService;
|
||||
private readonly ITrackedDownloadService _trackedDownloadService;
|
||||
private readonly IFailedDownloadService _failedDownloadService;
|
||||
private readonly IIgnoredDownloadService _ignoredDownloadService;
|
||||
private readonly IProvideDownloadClient _downloadClientProvider;
|
||||
private readonly IPendingReleaseService _pendingReleaseService;
|
||||
private readonly IDownloadService _downloadService;
|
||||
|
||||
public QueueActionModule(IQueueService queueService,
|
||||
ITrackedDownloadService trackedDownloadService,
|
||||
IFailedDownloadService failedDownloadService,
|
||||
IIgnoredDownloadService ignoredDownloadService,
|
||||
IProvideDownloadClient downloadClientProvider,
|
||||
IPendingReleaseService pendingReleaseService,
|
||||
IDownloadService downloadService)
|
||||
{
|
||||
_queueService = queueService;
|
||||
_trackedDownloadService = trackedDownloadService;
|
||||
_failedDownloadService = failedDownloadService;
|
||||
_ignoredDownloadService = ignoredDownloadService;
|
||||
_downloadClientProvider = downloadClientProvider;
|
||||
_pendingReleaseService = pendingReleaseService;
|
||||
_downloadService = downloadService;
|
||||
|
||||
Post(@"/grab/(?<id>[\d]{1,10})", x => Grab((int)x.Id));
|
||||
Post("/grab/bulk", x => Grab());
|
||||
|
||||
Delete(@"/(?<id>[\d]{1,10})", x => Remove((int)x.Id));
|
||||
Delete("/bulk", x => Remove());
|
||||
}
|
||||
|
||||
private object Grab(int id)
|
||||
{
|
||||
var pendingRelease = _pendingReleaseService.FindPendingQueueItem(id);
|
||||
|
||||
if (pendingRelease == null)
|
||||
{
|
||||
throw new NotFoundException();
|
||||
}
|
||||
|
||||
_downloadService.DownloadReport(pendingRelease.RemoteMovie);
|
||||
|
||||
return new object();
|
||||
}
|
||||
|
||||
private object Grab()
|
||||
{
|
||||
var resource = Request.Body.FromJson<QueueBulkResource>();
|
||||
|
||||
foreach (var id in resource.Ids)
|
||||
{
|
||||
var pendingRelease = _pendingReleaseService.FindPendingQueueItem(id);
|
||||
|
||||
if (pendingRelease == null)
|
||||
{
|
||||
throw new NotFoundException();
|
||||
}
|
||||
|
||||
_downloadService.DownloadReport(pendingRelease.RemoteMovie);
|
||||
}
|
||||
|
||||
return new object();
|
||||
}
|
||||
|
||||
private object Remove(int id)
|
||||
{
|
||||
var removeFromClient = Request.GetBooleanQueryParameter("removeFromClient", true);
|
||||
var blocklist = Request.GetBooleanQueryParameter("blocklist");
|
||||
|
||||
var trackedDownload = Remove(id, removeFromClient, blocklist);
|
||||
|
||||
if (trackedDownload != null)
|
||||
{
|
||||
_trackedDownloadService.StopTracking(trackedDownload.DownloadItem.DownloadId);
|
||||
}
|
||||
|
||||
return new object();
|
||||
}
|
||||
|
||||
private object Remove()
|
||||
{
|
||||
var removeFromClient = Request.GetBooleanQueryParameter("removeFromClient", true);
|
||||
var blocklist = Request.GetBooleanQueryParameter("blocklist");
|
||||
|
||||
var resource = Request.Body.FromJson<QueueBulkResource>();
|
||||
var trackedDownloadIds = new List<string>();
|
||||
|
||||
foreach (var id in resource.Ids)
|
||||
{
|
||||
var trackedDownload = Remove(id, removeFromClient, blocklist);
|
||||
|
||||
if (trackedDownload != null)
|
||||
{
|
||||
trackedDownloadIds.Add(trackedDownload.DownloadItem.DownloadId);
|
||||
}
|
||||
}
|
||||
|
||||
_trackedDownloadService.StopTracking(trackedDownloadIds);
|
||||
|
||||
return new object();
|
||||
}
|
||||
|
||||
private TrackedDownload Remove(int id, bool removeFromClient, bool blocklist)
|
||||
{
|
||||
var pendingRelease = _pendingReleaseService.FindPendingQueueItem(id);
|
||||
|
||||
if (pendingRelease != null)
|
||||
{
|
||||
_pendingReleaseService.RemovePendingQueueItems(pendingRelease.Id);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
var trackedDownload = GetTrackedDownload(id);
|
||||
|
||||
if (trackedDownload == null)
|
||||
{
|
||||
throw new NotFoundException();
|
||||
}
|
||||
|
||||
if (removeFromClient)
|
||||
{
|
||||
var downloadClient = _downloadClientProvider.Get(trackedDownload.DownloadClient);
|
||||
|
||||
if (downloadClient == null)
|
||||
{
|
||||
throw new BadRequestException();
|
||||
}
|
||||
|
||||
downloadClient.RemoveItem(trackedDownload.DownloadItem, true);
|
||||
}
|
||||
|
||||
if (blocklist)
|
||||
{
|
||||
_failedDownloadService.MarkAsFailed(trackedDownload.DownloadItem.DownloadId);
|
||||
}
|
||||
|
||||
if (!removeFromClient && !blocklist && !_ignoredDownloadService.IgnoreDownload(trackedDownload))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return trackedDownload;
|
||||
}
|
||||
|
||||
private TrackedDownload GetTrackedDownload(int queueId)
|
||||
{
|
||||
var queueItem = _queueService.Find(queueId);
|
||||
|
||||
if (queueItem == null)
|
||||
{
|
||||
throw new NotFoundException();
|
||||
}
|
||||
|
||||
var trackedDownload = _trackedDownloadService.Find(queueItem.DownloadId);
|
||||
|
||||
if (trackedDownload == null)
|
||||
{
|
||||
throw new NotFoundException();
|
||||
}
|
||||
|
||||
return trackedDownload;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,51 +1,58 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using NzbDrone.Core.Datastore.Events;
|
||||
using NzbDrone.Core.Download.Pending;
|
||||
using NzbDrone.Core.Messaging.Events;
|
||||
using NzbDrone.Core.Queue;
|
||||
using NzbDrone.SignalR;
|
||||
using Radarr.Http;
|
||||
using Radarr.Http.Extensions;
|
||||
using Radarr.Http.REST;
|
||||
|
||||
namespace Radarr.Api.V3.Queue
|
||||
{
|
||||
public class QueueDetailsModule : RadarrRestModuleWithSignalR<QueueResource, NzbDrone.Core.Queue.Queue>,
|
||||
[V3ApiController("queue/details")]
|
||||
public class QueueDetailsController : RestControllerWithSignalR<QueueResource, NzbDrone.Core.Queue.Queue>,
|
||||
IHandle<QueueUpdatedEvent>, IHandle<PendingReleasesUpdatedEvent>
|
||||
{
|
||||
private readonly IQueueService _queueService;
|
||||
private readonly IPendingReleaseService _pendingReleaseService;
|
||||
|
||||
public QueueDetailsModule(IBroadcastSignalRMessage broadcastSignalRMessage, IQueueService queueService, IPendingReleaseService pendingReleaseService)
|
||||
: base(broadcastSignalRMessage, "queue/details")
|
||||
public QueueDetailsController(IBroadcastSignalRMessage broadcastSignalRMessage, IQueueService queueService, IPendingReleaseService pendingReleaseService)
|
||||
: base(broadcastSignalRMessage)
|
||||
{
|
||||
_queueService = queueService;
|
||||
_pendingReleaseService = pendingReleaseService;
|
||||
GetResourceAll = GetQueue;
|
||||
}
|
||||
|
||||
private List<QueueResource> GetQueue()
|
||||
public override QueueResource GetResourceById(int id)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public List<QueueResource> GetQueue(int? movieId, bool includeMovie = false)
|
||||
{
|
||||
var includeMovie = Request.GetBooleanQueryParameter("includeMovie");
|
||||
var queue = _queueService.GetQueue();
|
||||
var pending = _pendingReleaseService.GetPendingQueue();
|
||||
var fullQueue = queue.Concat(pending);
|
||||
|
||||
var movieIdQuery = Request.Query.MovieId;
|
||||
|
||||
if (movieIdQuery.HasValue)
|
||||
if (movieId.HasValue)
|
||||
{
|
||||
return fullQueue.Where(q => q.Movie?.Id == (int)movieIdQuery).ToResource(includeMovie);
|
||||
return fullQueue.Where(q => q.Movie?.Id == movieId.Value).ToResource(includeMovie);
|
||||
}
|
||||
|
||||
return fullQueue.ToResource(includeMovie);
|
||||
}
|
||||
|
||||
[NonAction]
|
||||
public void Handle(QueueUpdatedEvent message)
|
||||
{
|
||||
BroadcastResourceChange(ModelAction.Sync);
|
||||
}
|
||||
|
||||
[NonAction]
|
||||
public void Handle(PendingReleasesUpdatedEvent message)
|
||||
{
|
||||
BroadcastResourceChange(ModelAction.Sync);
|
@ -1,12 +0,0 @@
|
||||
using Radarr.Http;
|
||||
|
||||
namespace Radarr.Api.V3
|
||||
{
|
||||
public abstract class RadarrV3FeedModule : RadarrModule
|
||||
{
|
||||
protected RadarrV3FeedModule(string resource)
|
||||
: base("/feed/v3/" + resource.Trim('/'))
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
@ -1,12 +0,0 @@
|
||||
using Radarr.Http;
|
||||
|
||||
namespace Radarr.Api.V3
|
||||
{
|
||||
public abstract class RadarrV3Module : RadarrModule
|
||||
{
|
||||
protected RadarrV3Module(string resource)
|
||||
: base("/api/v3/" + resource.Trim('/'))
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,61 @@
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using NzbDrone.Core.Datastore.Events;
|
||||
using NzbDrone.Core.Messaging.Events;
|
||||
using NzbDrone.Core.Tags;
|
||||
using NzbDrone.SignalR;
|
||||
using Radarr.Http;
|
||||
using Radarr.Http.REST;
|
||||
using Radarr.Http.REST.Attributes;
|
||||
|
||||
namespace Radarr.Api.V3.Tags
|
||||
{
|
||||
[V3ApiController]
|
||||
public class TagController : RestControllerWithSignalR<TagResource, Tag>, IHandle<TagsUpdatedEvent>
|
||||
{
|
||||
private readonly ITagService _tagService;
|
||||
|
||||
public TagController(IBroadcastSignalRMessage signalRBroadcaster,
|
||||
ITagService tagService)
|
||||
: base(signalRBroadcaster)
|
||||
{
|
||||
_tagService = tagService;
|
||||
}
|
||||
|
||||
public override TagResource GetResourceById(int id)
|
||||
{
|
||||
return _tagService.GetTag(id).ToResource();
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public List<TagResource> GetAll()
|
||||
{
|
||||
return _tagService.All().ToResource();
|
||||
}
|
||||
|
||||
[RestPostById]
|
||||
public ActionResult<TagResource> Create(TagResource resource)
|
||||
{
|
||||
return Created(_tagService.Add(resource.ToModel()).Id);
|
||||
}
|
||||
|
||||
[RestPutById]
|
||||
public ActionResult<TagResource> Update(TagResource resource)
|
||||
{
|
||||
_tagService.Update(resource.ToModel());
|
||||
return Accepted(resource.Id);
|
||||
}
|
||||
|
||||
[RestDeleteById]
|
||||
public void DeleteTag(int id)
|
||||
{
|
||||
_tagService.Delete(id);
|
||||
}
|
||||
|
||||
[NonAction]
|
||||
public void Handle(TagsUpdatedEvent message)
|
||||
{
|
||||
BroadcastResourceChange(ModelAction.Sync);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,28 +1,28 @@
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using NzbDrone.Core.Tags;
|
||||
using Radarr.Http;
|
||||
using Radarr.Http.REST;
|
||||
|
||||
namespace Radarr.Api.V3.Tags
|
||||
{
|
||||
public class TagDetailsModule : RadarrRestModule<TagDetailsResource>
|
||||
[V3ApiController("tag/detail")]
|
||||
public class TagDetailsController : RestController<TagDetailsResource>
|
||||
{
|
||||
private readonly ITagService _tagService;
|
||||
|
||||
public TagDetailsModule(ITagService tagService)
|
||||
: base("/tag/detail")
|
||||
public TagDetailsController(ITagService tagService)
|
||||
{
|
||||
_tagService = tagService;
|
||||
|
||||
GetResourceById = GetById;
|
||||
GetResourceAll = GetAll;
|
||||
}
|
||||
|
||||
private TagDetailsResource GetById(int id)
|
||||
public override TagDetailsResource GetResourceById(int id)
|
||||
{
|
||||
return _tagService.Details(id).ToResource();
|
||||
}
|
||||
|
||||
private List<TagDetailsResource> GetAll()
|
||||
[HttpGet]
|
||||
public List<TagDetailsResource> GetAll()
|
||||
{
|
||||
return _tagService.Details().ToResource();
|
||||
}
|
@ -1,57 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
using NzbDrone.Core.Datastore.Events;
|
||||
using NzbDrone.Core.Messaging.Events;
|
||||
using NzbDrone.Core.Tags;
|
||||
using NzbDrone.SignalR;
|
||||
using Radarr.Http;
|
||||
|
||||
namespace Radarr.Api.V3.Tags
|
||||
{
|
||||
public class TagModule : RadarrRestModuleWithSignalR<TagResource, Tag>, IHandle<TagsUpdatedEvent>
|
||||
{
|
||||
private readonly ITagService _tagService;
|
||||
|
||||
public TagModule(IBroadcastSignalRMessage signalRBroadcaster,
|
||||
ITagService tagService)
|
||||
: base(signalRBroadcaster)
|
||||
{
|
||||
_tagService = tagService;
|
||||
|
||||
GetResourceById = GetById;
|
||||
GetResourceAll = GetAll;
|
||||
CreateResource = Create;
|
||||
UpdateResource = Update;
|
||||
DeleteResource = DeleteTag;
|
||||
}
|
||||
|
||||
private TagResource GetById(int id)
|
||||
{
|
||||
return _tagService.GetTag(id).ToResource();
|
||||
}
|
||||
|
||||
private List<TagResource> GetAll()
|
||||
{
|
||||
return _tagService.All().ToResource();
|
||||
}
|
||||
|
||||
private int Create(TagResource resource)
|
||||
{
|
||||
return _tagService.Add(resource.ToModel()).Id;
|
||||
}
|
||||
|
||||
private void Update(TagResource resource)
|
||||
{
|
||||
_tagService.Update(resource.ToModel());
|
||||
}
|
||||
|
||||
private void DeleteTag(int id)
|
||||
{
|
||||
_tagService.Delete(id);
|
||||
}
|
||||
|
||||
public void Handle(TagsUpdatedEvent message)
|
||||
{
|
||||
BroadcastResourceChange(ModelAction.Sync);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,89 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Security.Claims;
|
||||
using System.Text.Encodings.Web;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Authentication;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Options;
|
||||
|
||||
namespace Radarr.Http.Authentication
|
||||
{
|
||||
public class ApiKeyAuthenticationOptions : AuthenticationSchemeOptions
|
||||
{
|
||||
public const string DefaultScheme = "API Key";
|
||||
public string Scheme => DefaultScheme;
|
||||
public string AuthenticationType = DefaultScheme;
|
||||
|
||||
public string HeaderName { get; set; }
|
||||
public string QueryName { get; set; }
|
||||
public string ApiKey { get; set; }
|
||||
}
|
||||
|
||||
public class ApiKeyAuthenticationHandler : AuthenticationHandler<ApiKeyAuthenticationOptions>
|
||||
{
|
||||
public ApiKeyAuthenticationHandler(IOptionsMonitor<ApiKeyAuthenticationOptions> options,
|
||||
ILoggerFactory logger,
|
||||
UrlEncoder encoder,
|
||||
ISystemClock clock)
|
||||
: base(options, logger, encoder, clock)
|
||||
{
|
||||
}
|
||||
|
||||
private string ParseApiKey()
|
||||
{
|
||||
// Try query parameter
|
||||
if (Request.Query.TryGetValue(Options.QueryName, out var value))
|
||||
{
|
||||
return value.FirstOrDefault();
|
||||
}
|
||||
|
||||
// No ApiKey query parameter found try headers
|
||||
if (Request.Headers.TryGetValue(Options.HeaderName, out var headerValue))
|
||||
{
|
||||
return headerValue.FirstOrDefault();
|
||||
}
|
||||
|
||||
return Request.Headers["Authorization"].FirstOrDefault()?.Replace("Bearer ", "");
|
||||
}
|
||||
|
||||
protected override Task<AuthenticateResult> HandleAuthenticateAsync()
|
||||
{
|
||||
var providedApiKey = ParseApiKey();
|
||||
|
||||
if (string.IsNullOrWhiteSpace(providedApiKey))
|
||||
{
|
||||
return Task.FromResult(AuthenticateResult.NoResult());
|
||||
}
|
||||
|
||||
if (Options.ApiKey == providedApiKey)
|
||||
{
|
||||
var claims = new List<Claim>
|
||||
{
|
||||
new Claim("ApiKey", "true")
|
||||
};
|
||||
|
||||
var identity = new ClaimsIdentity(claims, Options.AuthenticationType);
|
||||
var identities = new List<ClaimsIdentity> { identity };
|
||||
var principal = new ClaimsPrincipal(identities);
|
||||
var ticket = new AuthenticationTicket(principal, Options.Scheme);
|
||||
|
||||
return Task.FromResult(AuthenticateResult.Success(ticket));
|
||||
}
|
||||
|
||||
return Task.FromResult(AuthenticateResult.NoResult());
|
||||
}
|
||||
|
||||
protected override Task HandleChallengeAsync(AuthenticationProperties properties)
|
||||
{
|
||||
Response.StatusCode = 401;
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
protected override Task HandleForbiddenAsync(AuthenticationProperties properties)
|
||||
{
|
||||
Response.StatusCode = 403;
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue