|
|
|
@ -6,6 +6,8 @@ using FluentValidation.Results;
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
using Microsoft.AspNetCore.Mvc.Controllers;
|
|
|
|
|
using Microsoft.AspNetCore.Mvc.Filters;
|
|
|
|
|
using NLog;
|
|
|
|
|
using NzbDrone.Common.Instrumentation;
|
|
|
|
|
using NzbDrone.Core.Datastore;
|
|
|
|
|
using NzbDrone.Http.REST.Attributes;
|
|
|
|
|
using Prowlarr.Http.Validation;
|
|
|
|
@ -16,7 +18,9 @@ namespace Prowlarr.Http.REST
|
|
|
|
|
where TResource : RestResource, new()
|
|
|
|
|
{
|
|
|
|
|
private static readonly List<Type> VALIDATE_ID_ATTRIBUTES = new List<Type> { typeof(RestPutByIdAttribute), typeof(RestDeleteByIdAttribute) };
|
|
|
|
|
private static readonly Type DEPRECATED_ATTRIBUTE = typeof(ObsoleteAttribute);
|
|
|
|
|
|
|
|
|
|
private readonly Logger _logger;
|
|
|
|
|
protected ResourceValidator<TResource> PostValidator { get; private set; }
|
|
|
|
|
protected ResourceValidator<TResource> PutValidator { get; private set; }
|
|
|
|
|
protected ResourceValidator<TResource> SharedValidator { get; private set; }
|
|
|
|
@ -31,6 +35,8 @@ namespace Prowlarr.Http.REST
|
|
|
|
|
|
|
|
|
|
protected RestController()
|
|
|
|
|
{
|
|
|
|
|
_logger = NzbDroneLogger.GetLogger(this);
|
|
|
|
|
|
|
|
|
|
PostValidator = new ResourceValidator<TResource>();
|
|
|
|
|
PutValidator = new ResourceValidator<TResource>();
|
|
|
|
|
SharedValidator = new ResourceValidator<TResource>();
|
|
|
|
@ -76,6 +82,13 @@ namespace Prowlarr.Http.REST
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var controllerAttributes = descriptor.ControllerTypeInfo.CustomAttributes;
|
|
|
|
|
if (controllerAttributes.Any(x => x.AttributeType == DEPRECATED_ATTRIBUTE) || attributes.Any(x => x.AttributeType == DEPRECATED_ATTRIBUTE))
|
|
|
|
|
{
|
|
|
|
|
_logger.Warn("API call made to deprecated endpoint from {0}", Request.Headers.UserAgent.ToString());
|
|
|
|
|
Response.Headers.Add("Deprecation", "true");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
base.OnActionExecuting(context);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|