Merge pull request #3946 from crobibero/output-formatters
Clean up output formatters
This commit is contained in:
commit
7a03e6d2c6
|
@ -1,4 +1,5 @@
|
||||||
using System.Net.Mime;
|
using System.Net.Mime;
|
||||||
|
using MediaBrowser.Common.Json;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
|
||||||
namespace Jellyfin.Api
|
namespace Jellyfin.Api
|
||||||
|
@ -8,7 +9,10 @@ namespace Jellyfin.Api
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[ApiController]
|
[ApiController]
|
||||||
[Route("[controller]")]
|
[Route("[controller]")]
|
||||||
[Produces(MediaTypeNames.Application.Json)]
|
[Produces(
|
||||||
|
MediaTypeNames.Application.Json,
|
||||||
|
JsonDefaults.CamelCaseMediaType,
|
||||||
|
JsonDefaults.PascalCaseMediaType)]
|
||||||
public class BaseJellyfinApiController : ControllerBase
|
public class BaseJellyfinApiController : ControllerBase
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Diagnostics.CodeAnalysis;
|
using System.Diagnostics.CodeAnalysis;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using System.Net.Mime;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Emby.Dlna;
|
using Emby.Dlna;
|
||||||
using Emby.Dlna.Main;
|
using Emby.Dlna.Main;
|
||||||
|
@ -17,8 +18,6 @@ namespace Jellyfin.Api.Controllers
|
||||||
[Route("Dlna")]
|
[Route("Dlna")]
|
||||||
public class DlnaServerController : BaseJellyfinApiController
|
public class DlnaServerController : BaseJellyfinApiController
|
||||||
{
|
{
|
||||||
private const string XMLContentType = "text/xml; charset=UTF-8";
|
|
||||||
|
|
||||||
private readonly IDlnaManager _dlnaManager;
|
private readonly IDlnaManager _dlnaManager;
|
||||||
private readonly IContentDirectory _contentDirectory;
|
private readonly IContentDirectory _contentDirectory;
|
||||||
private readonly IConnectionManager _connectionManager;
|
private readonly IConnectionManager _connectionManager;
|
||||||
|
@ -44,7 +43,7 @@ namespace Jellyfin.Api.Controllers
|
||||||
/// <returns>An <see cref="OkResult"/> containing the description xml.</returns>
|
/// <returns>An <see cref="OkResult"/> containing the description xml.</returns>
|
||||||
[HttpGet("{serverId}/description")]
|
[HttpGet("{serverId}/description")]
|
||||||
[HttpGet("{serverId}/description.xml", Name = "GetDescriptionXml_2")]
|
[HttpGet("{serverId}/description.xml", Name = "GetDescriptionXml_2")]
|
||||||
[Produces(XMLContentType)]
|
[Produces(MediaTypeNames.Text.Xml)]
|
||||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||||
public ActionResult GetDescriptionXml([FromRoute] string serverId)
|
public ActionResult GetDescriptionXml([FromRoute] string serverId)
|
||||||
{
|
{
|
||||||
|
@ -63,7 +62,7 @@ namespace Jellyfin.Api.Controllers
|
||||||
[HttpGet("{serverId}/ContentDirectory")]
|
[HttpGet("{serverId}/ContentDirectory")]
|
||||||
[HttpGet("{serverId}/ContentDirectory/ContentDirectory", Name = "GetContentDirectory_2")]
|
[HttpGet("{serverId}/ContentDirectory/ContentDirectory", Name = "GetContentDirectory_2")]
|
||||||
[HttpGet("{serverId}/ContentDirectory/ContentDirectory.xml", Name = "GetContentDirectory_3")]
|
[HttpGet("{serverId}/ContentDirectory/ContentDirectory.xml", Name = "GetContentDirectory_3")]
|
||||||
[Produces(XMLContentType)]
|
[Produces(MediaTypeNames.Text.Xml)]
|
||||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||||
[SuppressMessage("Microsoft.Performance", "CA1801:ReviewUnusedParameters", MessageId = "serverId", Justification = "Required for DLNA")]
|
[SuppressMessage("Microsoft.Performance", "CA1801:ReviewUnusedParameters", MessageId = "serverId", Justification = "Required for DLNA")]
|
||||||
public ActionResult GetContentDirectory([FromRoute] string serverId)
|
public ActionResult GetContentDirectory([FromRoute] string serverId)
|
||||||
|
@ -79,7 +78,7 @@ namespace Jellyfin.Api.Controllers
|
||||||
[HttpGet("{serverId}/MediaReceiverRegistrar")]
|
[HttpGet("{serverId}/MediaReceiverRegistrar")]
|
||||||
[HttpGet("{serverId}/MediaReceiverRegistrar/MediaReceiverRegistrar", Name = "GetMediaReceiverRegistrar_2")]
|
[HttpGet("{serverId}/MediaReceiverRegistrar/MediaReceiverRegistrar", Name = "GetMediaReceiverRegistrar_2")]
|
||||||
[HttpGet("{serverId}/MediaReceiverRegistrar/MediaReceiverRegistrar.xml", Name = "GetMediaReceiverRegistrar_3")]
|
[HttpGet("{serverId}/MediaReceiverRegistrar/MediaReceiverRegistrar.xml", Name = "GetMediaReceiverRegistrar_3")]
|
||||||
[Produces(XMLContentType)]
|
[Produces(MediaTypeNames.Text.Xml)]
|
||||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||||
[SuppressMessage("Microsoft.Performance", "CA1801:ReviewUnusedParameters", MessageId = "serverId", Justification = "Required for DLNA")]
|
[SuppressMessage("Microsoft.Performance", "CA1801:ReviewUnusedParameters", MessageId = "serverId", Justification = "Required for DLNA")]
|
||||||
public ActionResult GetMediaReceiverRegistrar([FromRoute] string serverId)
|
public ActionResult GetMediaReceiverRegistrar([FromRoute] string serverId)
|
||||||
|
@ -95,7 +94,7 @@ namespace Jellyfin.Api.Controllers
|
||||||
[HttpGet("{serverId}/ConnectionManager")]
|
[HttpGet("{serverId}/ConnectionManager")]
|
||||||
[HttpGet("{serverId}/ConnectionManager/ConnectionManager", Name = "GetConnectionManager_2")]
|
[HttpGet("{serverId}/ConnectionManager/ConnectionManager", Name = "GetConnectionManager_2")]
|
||||||
[HttpGet("{serverId}/ConnectionManager/ConnectionManager.xml", Name = "GetConnectionManager_3")]
|
[HttpGet("{serverId}/ConnectionManager/ConnectionManager.xml", Name = "GetConnectionManager_3")]
|
||||||
[Produces(XMLContentType)]
|
[Produces(MediaTypeNames.Text.Xml)]
|
||||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||||
[SuppressMessage("Microsoft.Performance", "CA1801:ReviewUnusedParameters", MessageId = "serverId", Justification = "Required for DLNA")]
|
[SuppressMessage("Microsoft.Performance", "CA1801:ReviewUnusedParameters", MessageId = "serverId", Justification = "Required for DLNA")]
|
||||||
public ActionResult GetConnectionManager([FromRoute] string serverId)
|
public ActionResult GetConnectionManager([FromRoute] string serverId)
|
||||||
|
|
|
@ -152,6 +152,10 @@ namespace Jellyfin.Server.Extensions
|
||||||
.AddMvc(opts =>
|
.AddMvc(opts =>
|
||||||
{
|
{
|
||||||
opts.UseGeneralRoutePrefix(baseUrl);
|
opts.UseGeneralRoutePrefix(baseUrl);
|
||||||
|
|
||||||
|
// Allow requester to change between camelCase and PascalCase
|
||||||
|
opts.RespectBrowserAcceptHeader = true;
|
||||||
|
|
||||||
opts.OutputFormatters.Insert(0, new CamelCaseJsonProfileFormatter());
|
opts.OutputFormatters.Insert(0, new CamelCaseJsonProfileFormatter());
|
||||||
opts.OutputFormatters.Insert(0, new PascalCaseJsonProfileFormatter());
|
opts.OutputFormatters.Insert(0, new PascalCaseJsonProfileFormatter());
|
||||||
|
|
||||||
|
|
|
@ -15,7 +15,7 @@ namespace Jellyfin.Server.Formatters
|
||||||
public CamelCaseJsonProfileFormatter() : base(JsonDefaults.GetCamelCaseOptions())
|
public CamelCaseJsonProfileFormatter() : base(JsonDefaults.GetCamelCaseOptions())
|
||||||
{
|
{
|
||||||
SupportedMediaTypes.Clear();
|
SupportedMediaTypes.Clear();
|
||||||
SupportedMediaTypes.Add(MediaTypeHeaderValue.Parse("application/json;profile=\"CamelCase\""));
|
SupportedMediaTypes.Add(MediaTypeHeaderValue.Parse(JsonDefaults.CamelCaseMediaType));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
using System.Net.Mime;
|
||||||
using MediaBrowser.Common.Json;
|
using MediaBrowser.Common.Json;
|
||||||
using Microsoft.AspNetCore.Mvc.Formatters;
|
using Microsoft.AspNetCore.Mvc.Formatters;
|
||||||
using Microsoft.Net.Http.Headers;
|
using Microsoft.Net.Http.Headers;
|
||||||
|
@ -16,8 +17,8 @@ namespace Jellyfin.Server.Formatters
|
||||||
{
|
{
|
||||||
SupportedMediaTypes.Clear();
|
SupportedMediaTypes.Clear();
|
||||||
// Add application/json for default formatter
|
// Add application/json for default formatter
|
||||||
SupportedMediaTypes.Add(MediaTypeHeaderValue.Parse("application/json"));
|
SupportedMediaTypes.Add(MediaTypeHeaderValue.Parse(MediaTypeNames.Application.Json));
|
||||||
SupportedMediaTypes.Add(MediaTypeHeaderValue.Parse("application/json;profile=\"PascalCase\""));
|
SupportedMediaTypes.Add(MediaTypeHeaderValue.Parse(JsonDefaults.PascalCaseMediaType));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,8 +16,9 @@ namespace Jellyfin.Server.Formatters
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public XmlOutputFormatter()
|
public XmlOutputFormatter()
|
||||||
{
|
{
|
||||||
|
SupportedMediaTypes.Clear();
|
||||||
SupportedMediaTypes.Add(MediaTypeNames.Text.Xml);
|
SupportedMediaTypes.Add(MediaTypeNames.Text.Xml);
|
||||||
SupportedMediaTypes.Add("text/xml;charset=UTF-8");
|
|
||||||
SupportedEncodings.Add(Encoding.UTF8);
|
SupportedEncodings.Add(Encoding.UTF8);
|
||||||
SupportedEncodings.Add(Encoding.Unicode);
|
SupportedEncodings.Add(Encoding.Unicode);
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,6 +9,16 @@ namespace MediaBrowser.Common.Json
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static class JsonDefaults
|
public static class JsonDefaults
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Pascal case json profile media type.
|
||||||
|
/// </summary>
|
||||||
|
public const string PascalCaseMediaType = "application/json; profile=\"PascalCase\"";
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Camel case json profile media type.
|
||||||
|
/// </summary>
|
||||||
|
public const string CamelCaseMediaType = "application/json; profile=\"CamelCase\"";
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the default <see cref="JsonSerializerOptions" /> options.
|
/// Gets the default <see cref="JsonSerializerOptions" /> options.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
Loading…
Reference in New Issue
Block a user