From 2d4e91c5a202aeb7b5d6d2206767d05a8f850212 Mon Sep 17 00:00:00 2001 From: crobibero Date: Sat, 15 Aug 2020 10:39:24 -0600 Subject: [PATCH 1/4] Add xml output formatter --- .../ApiServiceCollectionExtensions.cs | 1 + .../Formatters/XmlOutputFormatter.cs | 30 +++++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 Jellyfin.Server/Formatters/XmlOutputFormatter.cs diff --git a/Jellyfin.Server/Extensions/ApiServiceCollectionExtensions.cs b/Jellyfin.Server/Extensions/ApiServiceCollectionExtensions.cs index 83d8fac5b5..2e2bfea684 100644 --- a/Jellyfin.Server/Extensions/ApiServiceCollectionExtensions.cs +++ b/Jellyfin.Server/Extensions/ApiServiceCollectionExtensions.cs @@ -154,6 +154,7 @@ namespace Jellyfin.Server.Extensions opts.OutputFormatters.Insert(0, new PascalCaseJsonProfileFormatter()); opts.OutputFormatters.Add(new CssOutputFormatter()); + opts.OutputFormatters.Add(new XmlOutputFormatter()); }) // Clear app parts to avoid other assemblies being picked up diff --git a/Jellyfin.Server/Formatters/XmlOutputFormatter.cs b/Jellyfin.Server/Formatters/XmlOutputFormatter.cs new file mode 100644 index 0000000000..5f2337b2a2 --- /dev/null +++ b/Jellyfin.Server/Formatters/XmlOutputFormatter.cs @@ -0,0 +1,30 @@ +using System.Text; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc.Formatters; + +namespace Jellyfin.Server.Formatters +{ + /// + /// Xml output formatter. + /// + public class XmlOutputFormatter : TextOutputFormatter + { + /// + /// Initializes a new instance of the class. + /// + public XmlOutputFormatter() + { + SupportedMediaTypes.Add("text/xml"); + SupportedMediaTypes.Add("text/xml;charset=UTF-8"); + SupportedEncodings.Add(Encoding.UTF8); + SupportedEncodings.Add(Encoding.Unicode); + } + + /// + public override Task WriteResponseBodyAsync(OutputFormatterWriteContext context, Encoding selectedEncoding) + { + return context.HttpContext.Response.WriteAsync(context.Object?.ToString()); + } + } +} From 7d2ad3e0fc4e1002d5d5739e0766fb0c253f32f4 Mon Sep 17 00:00:00 2001 From: crobibero Date: Sun, 16 Aug 2020 08:32:03 -0600 Subject: [PATCH 2/4] Fix DlnaControlResponse string return --- Emby.Dlna/ControlResponse.cs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Emby.Dlna/ControlResponse.cs b/Emby.Dlna/ControlResponse.cs index 140ef9b463..ee72329b77 100644 --- a/Emby.Dlna/ControlResponse.cs +++ b/Emby.Dlna/ControlResponse.cs @@ -16,5 +16,10 @@ namespace Emby.Dlna public string Xml { get; set; } public bool IsSuccessful { get; set; } + + public override string ToString() + { + return Xml; + } } } From 7fe372749e248721c57f60527733ee002215ad09 Mon Sep 17 00:00:00 2001 From: crobibero Date: Sun, 16 Aug 2020 08:32:13 -0600 Subject: [PATCH 3/4] fix dlna server routes --- Jellyfin.Api/Controllers/DlnaServerController.cs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Jellyfin.Api/Controllers/DlnaServerController.cs b/Jellyfin.Api/Controllers/DlnaServerController.cs index ef507f2ed6..0100d642be 100644 --- a/Jellyfin.Api/Controllers/DlnaServerController.cs +++ b/Jellyfin.Api/Controllers/DlnaServerController.cs @@ -60,8 +60,8 @@ namespace Jellyfin.Api.Controllers /// Server UUID. /// Dlna content directory returned. /// An containing the dlna content directory xml. - [HttpGet("{serverId}/ContentDirectory/ContentDirectory")] - [HttpGet("{serverId}/ContentDirectory/ContentDirectory.xml", Name = "GetContentDirectory_2")] + [HttpGet("{serverId}/ContentDirectory")] + [HttpGet("{serverId}/ContentDirectory.xml", Name = "GetContentDirectory_2")] [Produces(XMLContentType)] [ProducesResponseType(StatusCodes.Status200OK)] [SuppressMessage("Microsoft.Performance", "CA1801:ReviewUnusedParameters", MessageId = "serverId", Justification = "Required for DLNA")] @@ -75,8 +75,8 @@ namespace Jellyfin.Api.Controllers /// /// Server UUID. /// Dlna media receiver registrar xml. - [HttpGet("{serverId}/MediaReceiverRegistrar/MediaReceiverRegistrar")] - [HttpGet("{serverId}/MediaReceiverRegistrar/MediaReceiverRegistrar.xml", Name = "GetMediaReceiverRegistrar_2")] + [HttpGet("{serverId}/MediaReceiverRegistrar")] + [HttpGet("{serverId}/MediaReceiverRegistrar.xml", Name = "GetMediaReceiverRegistrar_2")] [Produces(XMLContentType)] [ProducesResponseType(StatusCodes.Status200OK)] [SuppressMessage("Microsoft.Performance", "CA1801:ReviewUnusedParameters", MessageId = "serverId", Justification = "Required for DLNA")] @@ -90,8 +90,8 @@ namespace Jellyfin.Api.Controllers /// /// Server UUID. /// Dlna media receiver registrar xml. - [HttpGet("{serverId}/ConnectionManager/ConnectionManager")] - [HttpGet("{serverId}/ConnectionManager/ConnectionManager.xml", Name = "GetConnectionManager_2")] + [HttpGet("{serverId}/ConnectionManager")] + [HttpGet("{serverId}/ConnectionManager.xml", Name = "GetConnectionManager_2")] [Produces(XMLContentType)] [ProducesResponseType(StatusCodes.Status200OK)] [SuppressMessage("Microsoft.Performance", "CA1801:ReviewUnusedParameters", MessageId = "serverId", Justification = "Required for DLNA")] From 09c859746116a949008ebba832fa17b55c90e6e4 Mon Sep 17 00:00:00 2001 From: crobibero Date: Sun, 16 Aug 2020 08:40:43 -0600 Subject: [PATCH 4/4] inheritdoc --- Emby.Dlna/ControlResponse.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/Emby.Dlna/ControlResponse.cs b/Emby.Dlna/ControlResponse.cs index ee72329b77..243b097867 100644 --- a/Emby.Dlna/ControlResponse.cs +++ b/Emby.Dlna/ControlResponse.cs @@ -17,6 +17,7 @@ namespace Emby.Dlna public bool IsSuccessful { get; set; } + /// public override string ToString() { return Xml;