using System; using System.Collections.Generic; using System.Security.Claims; using Jellyfin.Extensions; using MediaBrowser.Controller.Dto; using MediaBrowser.Model.Entities; using MediaBrowser.Model.Querying; namespace Jellyfin.Api.Extensions; /// /// Dto Extensions. /// public static class DtoExtensions { /// /// Add additional fields depending on client. /// /// /// Use in place of GetDtoOptions. /// Legacy order: 2. /// /// DtoOptions object. /// Current claims principal. /// Modified DtoOptions object. internal static DtoOptions AddClientFields( this DtoOptions dtoOptions, ClaimsPrincipal user) { string? client = user.GetClient(); // No client in claim if (string.IsNullOrEmpty(client)) { return dtoOptions; } if (!dtoOptions.ContainsField(ItemFields.RecursiveItemCount)) { if (client.Contains("kodi", StringComparison.OrdinalIgnoreCase) || client.Contains("wmc", StringComparison.OrdinalIgnoreCase) || client.Contains("media center", StringComparison.OrdinalIgnoreCase) || client.Contains("classic", StringComparison.OrdinalIgnoreCase)) { dtoOptions.Fields = [..dtoOptions.Fields, ItemFields.RecursiveItemCount]; } } if (!dtoOptions.ContainsField(ItemFields.ChildCount)) { if (client.Contains("kodi", StringComparison.OrdinalIgnoreCase) || client.Contains("wmc", StringComparison.OrdinalIgnoreCase) || client.Contains("media center", StringComparison.OrdinalIgnoreCase) || client.Contains("classic", StringComparison.OrdinalIgnoreCase) || client.Contains("roku", StringComparison.OrdinalIgnoreCase) || client.Contains("samsung", StringComparison.OrdinalIgnoreCase) || client.Contains("androidtv", StringComparison.OrdinalIgnoreCase)) { dtoOptions.Fields = [..dtoOptions.Fields, ItemFields.ChildCount]; } } return dtoOptions; } /// /// Add additional DtoOptions. /// /// /// Converted from IHasDtoOptions. /// Legacy order: 3. /// /// DtoOptions object. /// Enable images. /// Enable user data. /// Image type limit. /// Enable image types. /// Modified DtoOptions object. internal static DtoOptions AddAdditionalDtoOptions( this DtoOptions dtoOptions, bool? enableImages, bool? enableUserData, int? imageTypeLimit, IReadOnlyList enableImageTypes) { dtoOptions.EnableImages = enableImages ?? true; if (imageTypeLimit.HasValue) { dtoOptions.ImageTypeLimit = imageTypeLimit.Value; } if (enableUserData.HasValue) { dtoOptions.EnableUserData = enableUserData.Value; } if (enableImageTypes.Count != 0) { dtoOptions.ImageTypes = enableImageTypes; } return dtoOptions; } }