From 7186b343bd21fe6b4e771b8530bd780a98a84472 Mon Sep 17 00:00:00 2001 From: Patrick Barron Date: Fri, 13 Jan 2023 22:23:22 -0500 Subject: Move Formatters to Jellyfin.Api --- .../Formatters/CamelCaseJsonProfileFormatter.cs | 21 +++++++++++++ Jellyfin.Api/Formatters/CssOutputFormatter.cs | 36 ++++++++++++++++++++++ .../Formatters/PascalCaseJsonProfileFormatter.cs | 24 +++++++++++++++ Jellyfin.Api/Formatters/XmlOutputFormatter.cs | 33 ++++++++++++++++++++ .../Extensions/ApiServiceCollectionExtensions.cs | 2 +- .../Formatters/CamelCaseJsonProfileFormatter.cs | 21 ------------- Jellyfin.Server/Formatters/CssOutputFormatter.cs | 36 ---------------------- .../Formatters/PascalCaseJsonProfileFormatter.cs | 24 --------------- Jellyfin.Server/Formatters/XmlOutputFormatter.cs | 33 -------------------- 9 files changed, 115 insertions(+), 115 deletions(-) create mode 100644 Jellyfin.Api/Formatters/CamelCaseJsonProfileFormatter.cs create mode 100644 Jellyfin.Api/Formatters/CssOutputFormatter.cs create mode 100644 Jellyfin.Api/Formatters/PascalCaseJsonProfileFormatter.cs create mode 100644 Jellyfin.Api/Formatters/XmlOutputFormatter.cs delete mode 100644 Jellyfin.Server/Formatters/CamelCaseJsonProfileFormatter.cs delete mode 100644 Jellyfin.Server/Formatters/CssOutputFormatter.cs delete mode 100644 Jellyfin.Server/Formatters/PascalCaseJsonProfileFormatter.cs delete mode 100644 Jellyfin.Server/Formatters/XmlOutputFormatter.cs diff --git a/Jellyfin.Api/Formatters/CamelCaseJsonProfileFormatter.cs b/Jellyfin.Api/Formatters/CamelCaseJsonProfileFormatter.cs new file mode 100644 index 0000000000..8f1f5dd940 --- /dev/null +++ b/Jellyfin.Api/Formatters/CamelCaseJsonProfileFormatter.cs @@ -0,0 +1,21 @@ +using Jellyfin.Extensions.Json; +using Microsoft.AspNetCore.Mvc.Formatters; +using Microsoft.Net.Http.Headers; + +namespace Jellyfin.Api.Formatters +{ + /// + /// Camel Case Json Profile Formatter. + /// + public class CamelCaseJsonProfileFormatter : SystemTextJsonOutputFormatter + { + /// + /// Initializes a new instance of the class. + /// + public CamelCaseJsonProfileFormatter() : base(JsonDefaults.CamelCaseOptions) + { + SupportedMediaTypes.Clear(); + SupportedMediaTypes.Add(MediaTypeHeaderValue.Parse(JsonDefaults.CamelCaseMediaType)); + } + } +} diff --git a/Jellyfin.Api/Formatters/CssOutputFormatter.cs b/Jellyfin.Api/Formatters/CssOutputFormatter.cs new file mode 100644 index 0000000000..e88c8ad1b2 --- /dev/null +++ b/Jellyfin.Api/Formatters/CssOutputFormatter.cs @@ -0,0 +1,36 @@ +using System.Text; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc.Formatters; + +namespace Jellyfin.Api.Formatters +{ + /// + /// Css output formatter. + /// + public class CssOutputFormatter : TextOutputFormatter + { + /// + /// Initializes a new instance of the class. + /// + public CssOutputFormatter() + { + SupportedMediaTypes.Add("text/css"); + + SupportedEncodings.Add(Encoding.UTF8); + SupportedEncodings.Add(Encoding.Unicode); + } + + /// + /// Write context object to stream. + /// + /// Writer context. + /// Unused. Writer encoding. + /// Write stream task. + public override Task WriteResponseBodyAsync(OutputFormatterWriteContext context, Encoding selectedEncoding) + { + var stringResponse = context.Object?.ToString(); + return stringResponse is null ? Task.CompletedTask : context.HttpContext.Response.WriteAsync(stringResponse); + } + } +} diff --git a/Jellyfin.Api/Formatters/PascalCaseJsonProfileFormatter.cs b/Jellyfin.Api/Formatters/PascalCaseJsonProfileFormatter.cs new file mode 100644 index 0000000000..5d77dbf4cc --- /dev/null +++ b/Jellyfin.Api/Formatters/PascalCaseJsonProfileFormatter.cs @@ -0,0 +1,24 @@ +using System.Net.Mime; +using Jellyfin.Extensions.Json; +using Microsoft.AspNetCore.Mvc.Formatters; +using Microsoft.Net.Http.Headers; + +namespace Jellyfin.Api.Formatters +{ + /// + /// Pascal Case Json Profile Formatter. + /// + public class PascalCaseJsonProfileFormatter : SystemTextJsonOutputFormatter + { + /// + /// Initializes a new instance of the class. + /// + public PascalCaseJsonProfileFormatter() : base(JsonDefaults.PascalCaseOptions) + { + SupportedMediaTypes.Clear(); + // Add application/json for default formatter + SupportedMediaTypes.Add(MediaTypeHeaderValue.Parse(MediaTypeNames.Application.Json)); + SupportedMediaTypes.Add(MediaTypeHeaderValue.Parse(JsonDefaults.PascalCaseMediaType)); + } + } +} diff --git a/Jellyfin.Api/Formatters/XmlOutputFormatter.cs b/Jellyfin.Api/Formatters/XmlOutputFormatter.cs new file mode 100644 index 0000000000..df8b1650be --- /dev/null +++ b/Jellyfin.Api/Formatters/XmlOutputFormatter.cs @@ -0,0 +1,33 @@ +using System.Net.Mime; +using System.Text; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc.Formatters; + +namespace Jellyfin.Api.Formatters +{ + /// + /// Xml output formatter. + /// + public class XmlOutputFormatter : TextOutputFormatter + { + /// + /// Initializes a new instance of the class. + /// + public XmlOutputFormatter() + { + SupportedMediaTypes.Clear(); + SupportedMediaTypes.Add(MediaTypeNames.Text.Xml); + + SupportedEncodings.Add(Encoding.UTF8); + SupportedEncodings.Add(Encoding.Unicode); + } + + /// + public override Task WriteResponseBodyAsync(OutputFormatterWriteContext context, Encoding selectedEncoding) + { + var stringResponse = context.Object?.ToString(); + return stringResponse is null ? Task.CompletedTask : context.HttpContext.Response.WriteAsync(stringResponse); + } + } +} diff --git a/Jellyfin.Server/Extensions/ApiServiceCollectionExtensions.cs b/Jellyfin.Server/Extensions/ApiServiceCollectionExtensions.cs index f74152405a..e9af1cf83c 100644 --- a/Jellyfin.Server/Extensions/ApiServiceCollectionExtensions.cs +++ b/Jellyfin.Server/Extensions/ApiServiceCollectionExtensions.cs @@ -20,13 +20,13 @@ using Jellyfin.Api.Auth.RequiresElevationPolicy; using Jellyfin.Api.Auth.SyncPlayAccessPolicy; using Jellyfin.Api.Constants; using Jellyfin.Api.Controllers; +using Jellyfin.Api.Formatters; using Jellyfin.Api.ModelBinders; using Jellyfin.Data.Enums; using Jellyfin.Extensions.Json; using Jellyfin.Networking.Configuration; using Jellyfin.Server.Configuration; using Jellyfin.Server.Filters; -using Jellyfin.Server.Formatters; using MediaBrowser.Common.Net; using MediaBrowser.Model.Entities; using MediaBrowser.Model.Session; diff --git a/Jellyfin.Server/Formatters/CamelCaseJsonProfileFormatter.cs b/Jellyfin.Server/Formatters/CamelCaseJsonProfileFormatter.cs deleted file mode 100644 index ea8c5ecdb1..0000000000 --- a/Jellyfin.Server/Formatters/CamelCaseJsonProfileFormatter.cs +++ /dev/null @@ -1,21 +0,0 @@ -using Jellyfin.Extensions.Json; -using Microsoft.AspNetCore.Mvc.Formatters; -using Microsoft.Net.Http.Headers; - -namespace Jellyfin.Server.Formatters -{ - /// - /// Camel Case Json Profile Formatter. - /// - public class CamelCaseJsonProfileFormatter : SystemTextJsonOutputFormatter - { - /// - /// Initializes a new instance of the class. - /// - public CamelCaseJsonProfileFormatter() : base(JsonDefaults.CamelCaseOptions) - { - SupportedMediaTypes.Clear(); - SupportedMediaTypes.Add(MediaTypeHeaderValue.Parse(JsonDefaults.CamelCaseMediaType)); - } - } -} diff --git a/Jellyfin.Server/Formatters/CssOutputFormatter.cs b/Jellyfin.Server/Formatters/CssOutputFormatter.cs deleted file mode 100644 index fdaa48f847..0000000000 --- a/Jellyfin.Server/Formatters/CssOutputFormatter.cs +++ /dev/null @@ -1,36 +0,0 @@ -using System.Text; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Http; -using Microsoft.AspNetCore.Mvc.Formatters; - -namespace Jellyfin.Server.Formatters -{ - /// - /// Css output formatter. - /// - public class CssOutputFormatter : TextOutputFormatter - { - /// - /// Initializes a new instance of the class. - /// - public CssOutputFormatter() - { - SupportedMediaTypes.Add("text/css"); - - SupportedEncodings.Add(Encoding.UTF8); - SupportedEncodings.Add(Encoding.Unicode); - } - - /// - /// Write context object to stream. - /// - /// Writer context. - /// Unused. Writer encoding. - /// Write stream task. - public override Task WriteResponseBodyAsync(OutputFormatterWriteContext context, Encoding selectedEncoding) - { - var stringResponse = context.Object?.ToString(); - return stringResponse is null ? Task.CompletedTask : context.HttpContext.Response.WriteAsync(stringResponse); - } - } -} diff --git a/Jellyfin.Server/Formatters/PascalCaseJsonProfileFormatter.cs b/Jellyfin.Server/Formatters/PascalCaseJsonProfileFormatter.cs deleted file mode 100644 index 03ca7dda72..0000000000 --- a/Jellyfin.Server/Formatters/PascalCaseJsonProfileFormatter.cs +++ /dev/null @@ -1,24 +0,0 @@ -using System.Net.Mime; -using Jellyfin.Extensions.Json; -using Microsoft.AspNetCore.Mvc.Formatters; -using Microsoft.Net.Http.Headers; - -namespace Jellyfin.Server.Formatters -{ - /// - /// Pascal Case Json Profile Formatter. - /// - public class PascalCaseJsonProfileFormatter : SystemTextJsonOutputFormatter - { - /// - /// Initializes a new instance of the class. - /// - public PascalCaseJsonProfileFormatter() : base(JsonDefaults.PascalCaseOptions) - { - SupportedMediaTypes.Clear(); - // Add application/json for default formatter - SupportedMediaTypes.Add(MediaTypeHeaderValue.Parse(MediaTypeNames.Application.Json)); - SupportedMediaTypes.Add(MediaTypeHeaderValue.Parse(JsonDefaults.PascalCaseMediaType)); - } - } -} diff --git a/Jellyfin.Server/Formatters/XmlOutputFormatter.cs b/Jellyfin.Server/Formatters/XmlOutputFormatter.cs deleted file mode 100644 index 156368d695..0000000000 --- a/Jellyfin.Server/Formatters/XmlOutputFormatter.cs +++ /dev/null @@ -1,33 +0,0 @@ -using System.Net.Mime; -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.Clear(); - SupportedMediaTypes.Add(MediaTypeNames.Text.Xml); - - SupportedEncodings.Add(Encoding.UTF8); - SupportedEncodings.Add(Encoding.Unicode); - } - - /// - public override Task WriteResponseBodyAsync(OutputFormatterWriteContext context, Encoding selectedEncoding) - { - var stringResponse = context.Object?.ToString(); - return stringResponse is null ? Task.CompletedTask : context.HttpContext.Response.WriteAsync(stringResponse); - } - } -} -- cgit v1.2.3