aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Jellyfin.Api/BaseJellyfinApiController.cs4
-rw-r--r--Jellyfin.Api/Controllers/ActivityLogController.cs11
-rw-r--r--Jellyfin.Api/Models/ConfigurationDtos/MediaEncoderPathDto.cs6
-rw-r--r--Jellyfin.Server/Extensions/ApiServiceCollectionExtensions.cs2
-rw-r--r--Jellyfin.Server/Formatters/CamelCaseJsonProfileFormatter.cs2
-rw-r--r--Jellyfin.Server/Formatters/PascalCaseJsonProfileFormatter.cs2
-rw-r--r--MediaBrowser.Api/MediaBrowser.Api.csproj4
-rw-r--r--MediaBrowser.Api/System/ActivityLogService.cs66
-rw-r--r--MediaBrowser.Common/Json/Converters/JsonNonStringKeyDictionaryConverter.cs26
-rw-r--r--MediaBrowser.Common/Json/Converters/JsonNonStringKeyDictionaryConverterFactory.cs5
-rw-r--r--MediaBrowser.Common/Json/JsonDefaults.cs30
11 files changed, 46 insertions, 112 deletions
diff --git a/Jellyfin.Api/BaseJellyfinApiController.cs b/Jellyfin.Api/BaseJellyfinApiController.cs
index 615f330a4..a34f9eb62 100644
--- a/Jellyfin.Api/BaseJellyfinApiController.cs
+++ b/Jellyfin.Api/BaseJellyfinApiController.cs
@@ -1,8 +1,4 @@
-<<<<<<< HEAD
-using System;
-=======
using System.Net.Mime;
->>>>>>> origin/master
using Microsoft.AspNetCore.Mvc;
namespace Jellyfin.Api
diff --git a/Jellyfin.Api/Controllers/ActivityLogController.cs b/Jellyfin.Api/Controllers/ActivityLogController.cs
index 8d37a8373..895d9f719 100644
--- a/Jellyfin.Api/Controllers/ActivityLogController.cs
+++ b/Jellyfin.Api/Controllers/ActivityLogController.cs
@@ -1,6 +1,10 @@
+#nullable enable
+#pragma warning disable CA1801
+
using System;
-using System.Globalization;
+using System.Linq;
using Jellyfin.Api.Constants;
+using Jellyfin.Data.Entities;
using MediaBrowser.Model.Activity;
using MediaBrowser.Model.Querying;
using Microsoft.AspNetCore.Authorization;
@@ -44,7 +48,10 @@ namespace Jellyfin.Api.Controllers
[FromQuery] DateTime? minDate,
bool? hasUserId)
{
- return _activityManager.GetActivityLogEntries(minDate, hasUserId, startIndex, limit);
+ var filterFunc = new Func<IQueryable<ActivityLog>, IQueryable<ActivityLog>>(
+ entries => entries.Where(entry => entry.DateCreated >= minDate));
+
+ return _activityManager.GetPagedResult(filterFunc, startIndex, limit);
}
}
}
diff --git a/Jellyfin.Api/Models/ConfigurationDtos/MediaEncoderPathDto.cs b/Jellyfin.Api/Models/ConfigurationDtos/MediaEncoderPathDto.cs
index b05e0cdf5..3706a11e3 100644
--- a/Jellyfin.Api/Models/ConfigurationDtos/MediaEncoderPathDto.cs
+++ b/Jellyfin.Api/Models/ConfigurationDtos/MediaEncoderPathDto.cs
@@ -1,3 +1,5 @@
+#nullable enable
+
namespace Jellyfin.Api.Models.ConfigurationDtos
{
/// <summary>
@@ -8,11 +10,11 @@ namespace Jellyfin.Api.Models.ConfigurationDtos
/// <summary>
/// Gets or sets media encoder path.
/// </summary>
- public string Path { get; set; }
+ public string Path { get; set; } = null!;
/// <summary>
/// Gets or sets media encoder path type.
/// </summary>
- public string PathType { get; set; }
+ public string PathType { get; set; } = null!;
}
}
diff --git a/Jellyfin.Server/Extensions/ApiServiceCollectionExtensions.cs b/Jellyfin.Server/Extensions/ApiServiceCollectionExtensions.cs
index 86d547af0..9cdaa0eb1 100644
--- a/Jellyfin.Server/Extensions/ApiServiceCollectionExtensions.cs
+++ b/Jellyfin.Server/Extensions/ApiServiceCollectionExtensions.cs
@@ -93,7 +93,7 @@ namespace Jellyfin.Server.Extensions
.AddJsonOptions(options =>
{
// Update all properties that are set in JsonDefaults
- var jsonOptions = JsonDefaults.PascalCase;
+ var jsonOptions = JsonDefaults.GetPascalCaseOptions();
// From JsonDefaults
options.JsonSerializerOptions.ReadCommentHandling = jsonOptions.ReadCommentHandling;
diff --git a/Jellyfin.Server/Formatters/CamelCaseJsonProfileFormatter.cs b/Jellyfin.Server/Formatters/CamelCaseJsonProfileFormatter.cs
index 989c8ecea..9b347ae2c 100644
--- a/Jellyfin.Server/Formatters/CamelCaseJsonProfileFormatter.cs
+++ b/Jellyfin.Server/Formatters/CamelCaseJsonProfileFormatter.cs
@@ -12,7 +12,7 @@ namespace Jellyfin.Server.Formatters
/// <summary>
/// Initializes a new instance of the <see cref="CamelCaseJsonProfileFormatter"/> class.
/// </summary>
- public CamelCaseJsonProfileFormatter() : base(JsonDefaults.CamelCase)
+ public CamelCaseJsonProfileFormatter() : base(JsonDefaults.GetCamelCaseOptions())
{
SupportedMediaTypes.Clear();
SupportedMediaTypes.Add(MediaTypeHeaderValue.Parse("application/json;profile=\"CamelCase\""));
diff --git a/Jellyfin.Server/Formatters/PascalCaseJsonProfileFormatter.cs b/Jellyfin.Server/Formatters/PascalCaseJsonProfileFormatter.cs
index 69963b3fb..0024708ba 100644
--- a/Jellyfin.Server/Formatters/PascalCaseJsonProfileFormatter.cs
+++ b/Jellyfin.Server/Formatters/PascalCaseJsonProfileFormatter.cs
@@ -12,7 +12,7 @@ namespace Jellyfin.Server.Formatters
/// <summary>
/// Initializes a new instance of the <see cref="PascalCaseJsonProfileFormatter"/> class.
/// </summary>
- public PascalCaseJsonProfileFormatter() : base(JsonDefaults.PascalCase)
+ public PascalCaseJsonProfileFormatter() : base(JsonDefaults.GetPascalCaseOptions())
{
SupportedMediaTypes.Clear();
// Add application/json for default formatter
diff --git a/MediaBrowser.Api/MediaBrowser.Api.csproj b/MediaBrowser.Api/MediaBrowser.Api.csproj
index 0b0c5cc9f..d703bdb05 100644
--- a/MediaBrowser.Api/MediaBrowser.Api.csproj
+++ b/MediaBrowser.Api/MediaBrowser.Api.csproj
@@ -14,10 +14,6 @@
<Compile Include="..\SharedVersion.cs" />
</ItemGroup>
- <ItemGroup>
- <Folder Include="Attachments" />
- </ItemGroup>
-
<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
diff --git a/MediaBrowser.Api/System/ActivityLogService.cs b/MediaBrowser.Api/System/ActivityLogService.cs
deleted file mode 100644
index a6bacad4f..000000000
--- a/MediaBrowser.Api/System/ActivityLogService.cs
+++ /dev/null
@@ -1,66 +0,0 @@
-using System;
-using System.Globalization;
-using System.Linq;
-using Jellyfin.Data.Entities;
-using MediaBrowser.Controller.Configuration;
-using MediaBrowser.Controller.Net;
-using MediaBrowser.Model.Activity;
-using MediaBrowser.Model.Querying;
-using MediaBrowser.Model.Services;
-using Microsoft.Extensions.Logging;
-
-namespace MediaBrowser.Api.System
-{
- [Route("/System/ActivityLog/Entries", "GET", Summary = "Gets activity log entries")]
- public class GetActivityLogs : IReturn<QueryResult<ActivityLogEntry>>
- {
- /// <summary>
- /// Skips over a given number of items within the results. Use for paging.
- /// </summary>
- /// <value>The start index.</value>
- [ApiMember(Name = "StartIndex", Description = "Optional. The record index to start at. All items with a lower index will be dropped from the results.", IsRequired = false, DataType = "int", ParameterType = "query", Verb = "GET")]
- public int? StartIndex { get; set; }
-
- /// <summary>
- /// The maximum number of items to return
- /// </summary>
- /// <value>The limit.</value>
- [ApiMember(Name = "Limit", Description = "Optional. The maximum number of records to return", IsRequired = false, DataType = "int", ParameterType = "query", Verb = "GET")]
- public int? Limit { get; set; }
-
- [ApiMember(Name = "MinDate", Description = "Optional. The minimum date. Format = ISO", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET")]
- public string MinDate { get; set; }
-
- public bool? HasUserId { get; set; }
- }
-
- [Authenticated(Roles = "Admin")]
- public class ActivityLogService : BaseApiService
- {
- private readonly IActivityManager _activityManager;
-
- public ActivityLogService(
- ILogger<ActivityLogService> logger,
- IServerConfigurationManager serverConfigurationManager,
- IHttpResultFactory httpResultFactory,
- IActivityManager activityManager)
- : base(logger, serverConfigurationManager, httpResultFactory)
- {
- _activityManager = activityManager;
- }
-
- public object Get(GetActivityLogs request)
- {
- DateTime? minDate = string.IsNullOrWhiteSpace(request.MinDate) ?
- (DateTime?)null :
- DateTime.Parse(request.MinDate, null, DateTimeStyles.RoundtripKind).ToUniversalTime();
-
- var filterFunc = new Func<IQueryable<ActivityLog>, IQueryable<ActivityLog>>(
- entries => entries.Where(entry => entry.DateCreated >= minDate));
-
- var result = _activityManager.GetPagedResult(filterFunc, request.StartIndex, request.Limit);
-
- return ToOptimizedResult(result);
- }
- }
-}
diff --git a/MediaBrowser.Common/Json/Converters/JsonNonStringKeyDictionaryConverter.cs b/MediaBrowser.Common/Json/Converters/JsonNonStringKeyDictionaryConverter.cs
index 636ef5372..8053461f0 100644
--- a/MediaBrowser.Common/Json/Converters/JsonNonStringKeyDictionaryConverter.cs
+++ b/MediaBrowser.Common/Json/Converters/JsonNonStringKeyDictionaryConverter.cs
@@ -25,7 +25,7 @@ namespace MediaBrowser.Common.Json.Converters
/// <param name="typeToConvert">The type to convert.</param>
/// <param name="options">The json serializer options.</param>
/// <returns>Typed dictionary.</returns>
- /// <exception cref="NotSupportedException"></exception>
+ /// <exception cref="NotSupportedException">Dictionary key type not supported.</exception>
public override IDictionary<TKey, TValue> Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
var convertedType = typeof(Dictionary<,>).MakeGenericType(typeof(string), typeToConvert.GenericTypeArguments[1]);
@@ -38,24 +38,24 @@ namespace MediaBrowser.Common.Json.Converters
CultureInfo.CurrentCulture);
var enumerator = (IEnumerator)convertedType.GetMethod("GetEnumerator")!.Invoke(value, null);
var parse = typeof(TKey).GetMethod(
- "Parse",
- 0,
- BindingFlags.Public | BindingFlags.Static,
- null,
- CallingConventions.Any,
- new[] { typeof(string) },
+ "Parse",
+ 0,
+ BindingFlags.Public | BindingFlags.Static,
+ null,
+ CallingConventions.Any,
+ new[] { typeof(string) },
null);
if (parse == null)
{
throw new NotSupportedException($"{typeof(TKey)} as TKey in IDictionary<TKey, TValue> is not supported.");
}
-
+
while (enumerator.MoveNext())
{
var element = (KeyValuePair<string?, TValue>)enumerator.Current;
- instance.Add((TKey)parse.Invoke(null, new[] { (object?) element.Key }), element.Value);
+ instance.Add((TKey)parse.Invoke(null, new[] { (object?)element.Key }), element.Value);
}
-
+
return instance;
}
@@ -70,8 +70,12 @@ namespace MediaBrowser.Common.Json.Converters
var convertedDictionary = new Dictionary<string?, TValue>(value.Count);
foreach (var (k, v) in value)
{
- convertedDictionary[k?.ToString()] = v;
+ if (k != null)
+ {
+ convertedDictionary[k.ToString()] = v;
+ }
}
+
JsonSerializer.Serialize(writer, convertedDictionary, options);
}
}
diff --git a/MediaBrowser.Common/Json/Converters/JsonNonStringKeyDictionaryConverterFactory.cs b/MediaBrowser.Common/Json/Converters/JsonNonStringKeyDictionaryConverterFactory.cs
index d9795a189..52f360740 100644
--- a/MediaBrowser.Common/Json/Converters/JsonNonStringKeyDictionaryConverterFactory.cs
+++ b/MediaBrowser.Common/Json/Converters/JsonNonStringKeyDictionaryConverterFactory.cs
@@ -22,18 +22,17 @@ namespace MediaBrowser.Common.Json.Converters
/// <returns>Conversion ability.</returns>
public override bool CanConvert(Type typeToConvert)
{
-
if (!typeToConvert.IsGenericType)
{
return false;
}
-
+
// Let built in converter handle string keys
if (typeToConvert.GenericTypeArguments[0] == typeof(string))
{
return false;
}
-
+
// Only support objects that implement IDictionary
return typeToConvert.GetInterface(nameof(IDictionary)) != null;
}
diff --git a/MediaBrowser.Common/Json/JsonDefaults.cs b/MediaBrowser.Common/Json/JsonDefaults.cs
index f38e2893e..adc15123b 100644
--- a/MediaBrowser.Common/Json/JsonDefaults.cs
+++ b/MediaBrowser.Common/Json/JsonDefaults.cs
@@ -16,7 +16,7 @@ namespace MediaBrowser.Common.Json
/// When changing these options, update
/// Jellyfin.Server/Extensions/ApiServiceCollectionExtensions.cs
/// -> AddJellyfinApi
- /// -> AddJsonOptions
+ /// -> AddJsonOptions.
/// </remarks>
/// <returns>The default <see cref="JsonSerializerOptions" /> options.</returns>
public static JsonSerializerOptions GetOptions()
@@ -33,31 +33,27 @@ namespace MediaBrowser.Common.Json
return options;
}
-
+
/// <summary>
- /// Gets CamelCase json options.
+ /// Gets camelCase json options.
/// </summary>
- public static JsonSerializerOptions CamelCase
+ /// <returns>The camelCase <see cref="JsonSerializerOptions" /> options.</returns>
+ public static JsonSerializerOptions GetCamelCaseOptions()
{
- get
- {
- var options = GetOptions();
- options.PropertyNamingPolicy = JsonNamingPolicy.CamelCase;
- return options;
- }
+ var options = GetOptions();
+ options.PropertyNamingPolicy = JsonNamingPolicy.CamelCase;
+ return options;
}
/// <summary>
/// Gets PascalCase json options.
/// </summary>
- public static JsonSerializerOptions PascalCase
+ /// <returns>The PascalCase <see cref="JsonSerializerOptions" /> options.</returns>
+ public static JsonSerializerOptions GetPascalCaseOptions()
{
- get
- {
- var options = GetOptions();
- options.PropertyNamingPolicy = null;
- return options;
- }
+ var options = GetOptions();
+ options.PropertyNamingPolicy = null;
+ return options;
}
}
}