Fixed: Add back LanguageProfiles endpoints and deprecate

* Fixed: Add back LanguageProfiles endpoints and deprecate

* fixup! Fixed: Add back LanguageProfiles endpoints and deprecate
This commit is contained in:
Qstick 2022-11-30 19:46:27 -06:00 committed by GitHub
parent c9b483bdf7
commit aaaf18aec3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 429 additions and 1 deletions

View File

@ -0,0 +1,81 @@
using System;
using System.Collections.Generic;
using Microsoft.AspNetCore.Mvc;
using NzbDrone.Core.Languages;
using Sonarr.Http;
using Sonarr.Http.REST;
using Sonarr.Http.REST.Attributes;
namespace Sonarr.Api.V3.Profiles.Languages
{
[V3ApiController]
[Obsolete("Deprecated")]
public class LanguageProfileController : RestController<LanguageProfileResource>
{
[RestPostById]
[Produces("application/json")]
[Consumes("application/json")]
public ActionResult<LanguageProfileResource> Create(LanguageProfileResource resource)
{
return Accepted(resource);
}
[RestDeleteById]
public void DeleteProfile(int id)
{
}
[RestPutById]
[Produces("application/json")]
[Consumes("application/json")]
public ActionResult<LanguageProfileResource> Update(LanguageProfileResource resource)
{
return Accepted(resource);
}
[RestGetById]
[Produces("application/json")]
protected override LanguageProfileResource GetResourceById(int id)
{
return new LanguageProfileResource
{
Id = 1,
Name = "Deprecated",
UpgradeAllowed = true,
Cutoff = Language.English,
Languages = new List<LanguageProfileItemResource>
{
new LanguageProfileItemResource
{
Language = Language.English,
Allowed = true
}
}
};
}
[HttpGet]
[Produces("application/json")]
public ActionResult<List<LanguageProfileResource>> GetAll()
{
return new List<LanguageProfileResource>
{
new LanguageProfileResource
{
Id = 1,
Name = "Deprecated",
UpgradeAllowed = true,
Cutoff = Language.English,
Languages = new List<LanguageProfileItemResource>
{
new LanguageProfileItemResource
{
Language = Language.English,
Allowed = true
}
}
}
};
}
}
}

View File

@ -0,0 +1,20 @@
using System.Collections.Generic;
using System.Linq;
using Sonarr.Http.REST;
namespace Sonarr.Api.V3.Profiles.Languages
{
public class LanguageProfileResource : RestResource
{
public string Name { get; set; }
public bool UpgradeAllowed { get; set; }
public NzbDrone.Core.Languages.Language Cutoff { get; set; }
public List<LanguageProfileItemResource> Languages { get; set; }
}
public class LanguageProfileItemResource : RestResource
{
public NzbDrone.Core.Languages.Language Language { get; set; }
public bool Allowed { get; set; }
}
}

View File

@ -0,0 +1,40 @@
using System;
using System.Collections.Generic;
using Microsoft.AspNetCore.Mvc;
using NzbDrone.Core.Languages;
using Sonarr.Http;
using Sonarr.Http.REST;
namespace Sonarr.Api.V3.Profiles.Languages
{
[V3ApiController("languageprofile/schema")]
[Obsolete("Deprecated")]
public class LanguageProfileSchemaController : RestController<LanguageProfileResource>
{
[HttpGet]
[Produces("application/json")]
public LanguageProfileResource GetSchema()
{
return new LanguageProfileResource
{
Id = 1,
Name = "Deprecated",
UpgradeAllowed = true,
Cutoff = Language.English,
Languages = new List<LanguageProfileItemResource>
{
new LanguageProfileItemResource
{
Language = Language.English,
Allowed = true
}
}
};
}
protected override LanguageProfileResource GetResourceById(int id)
{
throw new global::System.NotImplementedException();
}
}
}

View File

@ -66,6 +66,9 @@ namespace Sonarr.Api.V3.Series
public SeriesStatisticsResource Statistics { get; set; }
public bool? EpisodesChanged { get; set; }
[Obsolete("Deprecated")]
public int LanguageProfileId => 1;
}
public static class SeriesResourceMapper

View File

@ -27,6 +27,18 @@
}
],
"paths": {
"/api": {
"get": {
"tags": [
"ApiInfo"
],
"responses": {
"200": {
"description": "Success"
}
}
}
},
"/login": {
"post": {
"tags": [
@ -1596,7 +1608,24 @@
},
"responses": {
"200": {
"description": "Success"
"description": "Success",
"content": {
"text/plain": {
"schema": {
"$ref": "#/components/schemas/EpisodeResource"
}
},
"application/json": {
"schema": {
"$ref": "#/components/schemas/EpisodeResource"
}
},
"text/json": {
"schema": {
"$ref": "#/components/schemas/EpisodeResource"
}
}
}
}
}
},
@ -3088,6 +3117,195 @@
}
}
},
"/api/v3/languageprofile": {
"post": {
"tags": [
"LanguageProfile"
],
"requestBody": {
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/LanguageProfileResource"
}
}
}
},
"responses": {
"200": {
"description": "Success",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/LanguageProfileResource"
}
}
}
}
},
"deprecated": true
},
"get": {
"tags": [
"LanguageProfile"
],
"responses": {
"200": {
"description": "Success",
"content": {
"application/json": {
"schema": {
"type": "array",
"items": {
"$ref": "#/components/schemas/LanguageProfileResource"
}
}
}
}
}
},
"deprecated": true
}
},
"/api/v3/languageprofile/{id}": {
"delete": {
"tags": [
"LanguageProfile"
],
"parameters": [
{
"name": "id",
"in": "path",
"required": true,
"schema": {
"type": "integer",
"format": "int32"
}
}
],
"responses": {
"200": {
"description": "Success"
}
},
"deprecated": true
},
"put": {
"tags": [
"LanguageProfile"
],
"parameters": [
{
"name": "id",
"in": "path",
"required": true,
"schema": {
"type": "string"
}
}
],
"requestBody": {
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/LanguageProfileResource"
}
}
}
},
"responses": {
"200": {
"description": "Success",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/LanguageProfileResource"
}
}
}
}
},
"deprecated": true
},
"get": {
"tags": [
"LanguageProfile"
],
"parameters": [
{
"name": "id",
"in": "path",
"required": true,
"schema": {
"type": "integer",
"format": "int32"
}
}
],
"responses": {
"200": {
"description": "Success",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/LanguageProfileResource"
}
}
}
}
}
}
},
"/api/v3/languageprofile/schema": {
"get": {
"tags": [
"LanguageProfileSchema"
],
"responses": {
"200": {
"description": "Success",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/LanguageProfileResource"
}
}
}
}
},
"deprecated": true
}
},
"/api/v3/languageprofile/schema/{id}": {
"get": {
"tags": [
"LanguageProfileSchema"
],
"parameters": [
{
"name": "id",
"in": "path",
"required": true,
"schema": {
"type": "integer",
"format": "int32"
}
}
],
"responses": {
"200": {
"description": "Success",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/LanguageProfileResource"
}
}
}
}
}
}
},
"/api/v3/localization": {
"get": {
"tags": [
@ -8064,6 +8282,49 @@
},
"additionalProperties": false
},
"LanguageProfileItemResource": {
"type": "object",
"properties": {
"id": {
"type": "integer",
"format": "int32"
},
"language": {
"$ref": "#/components/schemas/Language"
},
"allowed": {
"type": "boolean"
}
},
"additionalProperties": false
},
"LanguageProfileResource": {
"type": "object",
"properties": {
"id": {
"type": "integer",
"format": "int32"
},
"name": {
"type": "string",
"nullable": true
},
"upgradeAllowed": {
"type": "boolean"
},
"cutoff": {
"$ref": "#/components/schemas/Language"
},
"languages": {
"type": "array",
"items": {
"$ref": "#/components/schemas/LanguageProfileItemResource"
},
"nullable": true
}
},
"additionalProperties": false
},
"LanguageResource": {
"type": "object",
"properties": {
@ -10004,6 +10265,9 @@
},
"nullable": true
},
"originalLanguage": {
"$ref": "#/components/schemas/Language"
},
"remotePoster": {
"type": "string",
"nullable": true
@ -10116,6 +10380,12 @@
"episodesChanged": {
"type": "boolean",
"nullable": true
},
"languageProfileId": {
"type": "integer",
"format": "int32",
"readOnly": true,
"deprecated": true
}
},
"additionalProperties": false

View File

@ -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 Sonarr.Http.REST.Attributes;
using Sonarr.Http.Validation;
@ -16,6 +18,9 @@ namespace Sonarr.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; }
@ -31,6 +36,8 @@ namespace Sonarr.Http.REST
protected RestController()
{
_logger = NzbDroneLogger.GetLogger(this);
PostValidator = new ResourceValidator<TResource>();
PutValidator = new ResourceValidator<TResource>();
SharedValidator = new ResourceValidator<TResource>();
@ -89,6 +96,13 @@ namespace Sonarr.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);
}