Lowercase CollectionTypeOptions to match legacy experience (#11272)

This commit is contained in:
Cody Robibero 2024-03-31 21:58:06 -06:00 committed by GitHub
parent d9fe900952
commit 3ade3a8e63
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 49 additions and 113 deletions

View File

@ -102,7 +102,7 @@ namespace Emby.Server.Implementations.Collections
var name = _localizationManager.GetLocalizedString("Collections"); var name = _localizationManager.GetLocalizedString("Collections");
await _libraryManager.AddVirtualFolder(name, CollectionTypeOptions.BoxSets, libraryOptions, true).ConfigureAwait(false); await _libraryManager.AddVirtualFolder(name, CollectionTypeOptions.boxsets, libraryOptions, true).ConfigureAwait(false);
return FindFolders(path).First(); return FindFolders(path).First();
} }

View File

@ -1,16 +1,49 @@
#pragma warning disable CS1591 #pragma warning disable SA1300 // Lowercase required for backwards compat.
namespace MediaBrowser.Model.Entities namespace MediaBrowser.Model.Entities;
{
/// <summary>
/// The collection type options.
/// </summary>
public enum CollectionTypeOptions public enum CollectionTypeOptions
{ {
Movies = 0, /// <summary>
TvShows = 1, /// Movies.
Music = 2, /// </summary>
MusicVideos = 3, movies = 0,
HomeVideos = 4,
BoxSets = 5, /// <summary>
Books = 6, /// TV Shows.
Mixed = 7 /// </summary>
} tvshows = 1,
/// <summary>
/// Music.
/// </summary>
music = 2,
/// <summary>
/// Music Videos.
/// </summary>
musicvideos = 3,
/// <summary>
/// Home Videos (and Photos).
/// </summary>
homevideos = 4,
/// <summary>
/// Box Sets.
/// </summary>
boxsets = 5,
/// <summary>
/// Books.
/// </summary>
books = 6,
/// <summary>
/// Mixed Movies and TV Shows.
/// </summary>
mixed = 7
} }

View File

@ -37,7 +37,6 @@ namespace MediaBrowser.Model.Entities
/// Gets or sets the type of the collection. /// Gets or sets the type of the collection.
/// </summary> /// </summary>
/// <value>The type of the collection.</value> /// <value>The type of the collection.</value>
[JsonConverter(typeof(JsonLowerCaseConverter<CollectionTypeOptions?>))]
public CollectionTypeOptions? CollectionType { get; set; } public CollectionTypeOptions? CollectionType { get; set; }
public LibraryOptions LibraryOptions { get; set; } public LibraryOptions LibraryOptions { get; set; }

View File

@ -1,25 +0,0 @@
using System;
using System.Text.Json;
using System.Text.Json.Serialization;
namespace Jellyfin.Extensions.Json.Converters
{
/// <summary>
/// Converts an object to a lowercase string.
/// </summary>
/// <typeparam name="T">The object type.</typeparam>
public class JsonLowerCaseConverter<T> : JsonConverter<T>
{
/// <inheritdoc />
public override T? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
return JsonSerializer.Deserialize<T>(ref reader, options);
}
/// <inheritdoc />
public override void Write(Utf8JsonWriter writer, T value, JsonSerializerOptions options)
{
writer.WriteStringValue(value?.ToString()?.ToLowerInvariant());
}
}
}

View File

@ -159,7 +159,7 @@ public sealed class RecordingsManager : IRecordingsManager, IDisposable
{ {
Locations = [customPath], Locations = [customPath],
Name = "Recorded Movies", Name = "Recorded Movies",
CollectionType = CollectionTypeOptions.Movies CollectionType = CollectionTypeOptions.movies
}; };
} }
@ -172,7 +172,7 @@ public sealed class RecordingsManager : IRecordingsManager, IDisposable
{ {
Locations = [customPath], Locations = [customPath],
Name = "Recorded Shows", Name = "Recorded Shows",
CollectionType = CollectionTypeOptions.TvShows CollectionType = CollectionTypeOptions.tvshows
}; };
} }
} }

View File

@ -1,71 +0,0 @@
using System.Text.Json;
using System.Text.Json.Serialization;
using Jellyfin.Extensions.Json.Converters;
using MediaBrowser.Model.Entities;
using Xunit;
namespace Jellyfin.Extensions.Tests.Json.Converters
{
public class JsonLowerCaseConverterTests
{
private readonly JsonSerializerOptions _jsonOptions = new JsonSerializerOptions()
{
Converters =
{
new JsonStringEnumConverter()
}
};
[Theory]
[InlineData(null, "{\"CollectionType\":null}")]
[InlineData(CollectionTypeOptions.Movies, "{\"CollectionType\":\"movies\"}")]
[InlineData(CollectionTypeOptions.MusicVideos, "{\"CollectionType\":\"musicvideos\"}")]
public void Serialize_CollectionTypeOptions_Correct(CollectionTypeOptions? collectionType, string expected)
{
Assert.Equal(expected, JsonSerializer.Serialize(new TestContainer(collectionType), _jsonOptions));
}
[Theory]
[InlineData("{\"CollectionType\":null}", null)]
[InlineData("{\"CollectionType\":\"movies\"}", CollectionTypeOptions.Movies)]
[InlineData("{\"CollectionType\":\"musicvideos\"}", CollectionTypeOptions.MusicVideos)]
public void Deserialize_CollectionTypeOptions_Correct(string json, CollectionTypeOptions? result)
{
var res = JsonSerializer.Deserialize<TestContainer>(json, _jsonOptions);
Assert.NotNull(res);
Assert.Equal(result, res!.CollectionType);
}
[Theory]
[InlineData(null)]
[InlineData(CollectionTypeOptions.Movies)]
[InlineData(CollectionTypeOptions.MusicVideos)]
public void RoundTrip_CollectionTypeOptions_Correct(CollectionTypeOptions? value)
{
var res = JsonSerializer.Deserialize<TestContainer>(JsonSerializer.Serialize(new TestContainer(value), _jsonOptions), _jsonOptions);
Assert.NotNull(res);
Assert.Equal(value, res!.CollectionType);
}
[Theory]
[InlineData("{\"CollectionType\":null}")]
[InlineData("{\"CollectionType\":\"movies\"}")]
[InlineData("{\"CollectionType\":\"musicvideos\"}")]
public void RoundTrip_String_Correct(string json)
{
var res = JsonSerializer.Serialize(JsonSerializer.Deserialize<TestContainer>(json, _jsonOptions), _jsonOptions);
Assert.Equal(json, res);
}
private sealed class TestContainer
{
public TestContainer(CollectionTypeOptions? collectionType)
{
CollectionType = collectionType;
}
[JsonConverter(typeof(JsonLowerCaseConverter<CollectionTypeOptions?>))]
public CollectionTypeOptions? CollectionType { get; set; }
}
}
}