mirror of
https://github.com/jellyfin/jellyfin.git
synced 2025-06-02 13:15:25 -04:00
Fix parsing
This commit is contained in:
parent
f7c7b1e7e1
commit
ee03b919f9
@ -2,6 +2,7 @@ using System.Text.Json;
|
|||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Jellyfin.Api.Constants;
|
using Jellyfin.Api.Constants;
|
||||||
using Jellyfin.Api.Models.ConfigurationDtos;
|
using Jellyfin.Api.Models.ConfigurationDtos;
|
||||||
|
using MediaBrowser.Common.Json;
|
||||||
using MediaBrowser.Controller.Configuration;
|
using MediaBrowser.Controller.Configuration;
|
||||||
using MediaBrowser.Controller.MediaEncoding;
|
using MediaBrowser.Controller.MediaEncoding;
|
||||||
using MediaBrowser.Model.Configuration;
|
using MediaBrowser.Model.Configuration;
|
||||||
@ -87,7 +88,7 @@ namespace Jellyfin.Api.Controllers
|
|||||||
public async Task<ActionResult> UpdateNamedConfiguration([FromRoute] string? key)
|
public async Task<ActionResult> UpdateNamedConfiguration([FromRoute] string? key)
|
||||||
{
|
{
|
||||||
var configurationType = _configurationManager.GetConfigurationType(key);
|
var configurationType = _configurationManager.GetConfigurationType(key);
|
||||||
var configuration = await JsonSerializer.DeserializeAsync(Request.Body, configurationType).ConfigureAwait(false);
|
var configuration = await JsonSerializer.DeserializeAsync(Request.Body, configurationType, JsonDefaults.GetOptions()).ConfigureAwait(false);
|
||||||
_configurationManager.SaveConfiguration(key, configuration);
|
_configurationManager.SaveConfiguration(key, configuration);
|
||||||
return NoContent();
|
return NoContent();
|
||||||
}
|
}
|
||||||
|
@ -7,6 +7,7 @@ using System.Threading.Tasks;
|
|||||||
using Jellyfin.Api.Constants;
|
using Jellyfin.Api.Constants;
|
||||||
using Jellyfin.Api.Models.PluginDtos;
|
using Jellyfin.Api.Models.PluginDtos;
|
||||||
using MediaBrowser.Common;
|
using MediaBrowser.Common;
|
||||||
|
using MediaBrowser.Common.Json;
|
||||||
using MediaBrowser.Common.Plugins;
|
using MediaBrowser.Common.Plugins;
|
||||||
using MediaBrowser.Common.Updates;
|
using MediaBrowser.Common.Updates;
|
||||||
using MediaBrowser.Model.Plugins;
|
using MediaBrowser.Model.Plugins;
|
||||||
@ -118,7 +119,7 @@ namespace Jellyfin.Api.Controllers
|
|||||||
return NotFound();
|
return NotFound();
|
||||||
}
|
}
|
||||||
|
|
||||||
var configuration = (BasePluginConfiguration)await JsonSerializer.DeserializeAsync(Request.Body, plugin.ConfigurationType)
|
var configuration = (BasePluginConfiguration)await JsonSerializer.DeserializeAsync(Request.Body, plugin.ConfigurationType, JsonDefaults.GetOptions())
|
||||||
.ConfigureAwait(false);
|
.ConfigureAwait(false);
|
||||||
|
|
||||||
plugin.UpdateConfiguration(configuration);
|
plugin.UpdateConfiguration(configuration);
|
||||||
|
56
MediaBrowser.Common/Json/Converters/JsonDoubleConverter.cs
Normal file
56
MediaBrowser.Common/Json/Converters/JsonDoubleConverter.cs
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
using System;
|
||||||
|
using System.Buffers;
|
||||||
|
using System.Buffers.Text;
|
||||||
|
using System.Globalization;
|
||||||
|
using System.Text.Json;
|
||||||
|
using System.Text.Json.Serialization;
|
||||||
|
|
||||||
|
namespace MediaBrowser.Common.Json.Converters
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Double to String JSON converter.
|
||||||
|
/// Web client send quoted doubles.
|
||||||
|
/// </summary>
|
||||||
|
public class JsonDoubleConverter : JsonConverter<double>
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Read JSON string as double.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="reader"><see cref="Utf8JsonReader"/>.</param>
|
||||||
|
/// <param name="typeToConvert">Type.</param>
|
||||||
|
/// <param name="options">Options.</param>
|
||||||
|
/// <returns>Parsed value.</returns>
|
||||||
|
public override double Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
|
||||||
|
{
|
||||||
|
if (reader.TokenType == JsonTokenType.String)
|
||||||
|
{
|
||||||
|
// try to parse number directly from bytes
|
||||||
|
var span = reader.HasValueSequence ? reader.ValueSequence.ToArray() : reader.ValueSpan;
|
||||||
|
if (Utf8Parser.TryParse(span, out double number, out var bytesConsumed) && span.Length == bytesConsumed)
|
||||||
|
{
|
||||||
|
return number;
|
||||||
|
}
|
||||||
|
|
||||||
|
// try to parse from a string if the above failed, this covers cases with other escaped/UTF characters
|
||||||
|
if (double.TryParse(reader.GetString(), out number))
|
||||||
|
{
|
||||||
|
return number;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// fallback to default handling
|
||||||
|
return reader.GetDouble();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Write double to JSON string.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="writer"><see cref="Utf8JsonWriter"/>.</param>
|
||||||
|
/// <param name="value">Value to write.</param>
|
||||||
|
/// <param name="options">Options.</param>
|
||||||
|
public override void Write(Utf8JsonWriter writer, double value, JsonSerializerOptions options)
|
||||||
|
{
|
||||||
|
writer.WriteStringValue(value.ToString(NumberFormatInfo.InvariantInfo));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -32,6 +32,7 @@ namespace MediaBrowser.Common.Json
|
|||||||
options.Converters.Add(new JsonStringEnumConverter());
|
options.Converters.Add(new JsonStringEnumConverter());
|
||||||
options.Converters.Add(new JsonNonStringKeyDictionaryConverterFactory());
|
options.Converters.Add(new JsonNonStringKeyDictionaryConverterFactory());
|
||||||
options.Converters.Add(new JsonInt64Converter());
|
options.Converters.Add(new JsonInt64Converter());
|
||||||
|
options.Converters.Add(new JsonDoubleConverter());
|
||||||
|
|
||||||
return options;
|
return options;
|
||||||
}
|
}
|
||||||
|
@ -44,7 +44,13 @@ namespace MediaBrowser.Model.Configuration
|
|||||||
public string PreviousVersionStr
|
public string PreviousVersionStr
|
||||||
{
|
{
|
||||||
get => PreviousVersion?.ToString();
|
get => PreviousVersion?.ToString();
|
||||||
set => PreviousVersion = Version.Parse(value);
|
set
|
||||||
|
{
|
||||||
|
if (Version.TryParse(value, out var version))
|
||||||
|
{
|
||||||
|
PreviousVersion = version;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user