diff options
Diffstat (limited to 'Jellyfin.Api/Controllers')
| -rw-r--r-- | Jellyfin.Api/Controllers/ArtistsController.cs | 64 | ||||
| -rw-r--r-- | Jellyfin.Api/Controllers/GenresController.cs | 9 | ||||
| -rw-r--r-- | Jellyfin.Api/Controllers/LibraryStructureController.cs | 11 | ||||
| -rw-r--r-- | Jellyfin.Api/Controllers/MusicGenresController.cs | 9 | ||||
| -rw-r--r-- | Jellyfin.Api/Controllers/PackageController.cs | 31 | ||||
| -rw-r--r-- | Jellyfin.Api/Controllers/StudiosController.cs | 9 | ||||
| -rw-r--r-- | Jellyfin.Api/Controllers/SubtitleController.cs | 2 |
7 files changed, 74 insertions, 61 deletions
diff --git a/Jellyfin.Api/Controllers/ArtistsController.cs b/Jellyfin.Api/Controllers/ArtistsController.cs index f19ca77818..fdbbace1e7 100644 --- a/Jellyfin.Api/Controllers/ArtistsController.cs +++ b/Jellyfin.Api/Controllers/ArtistsController.cs @@ -126,6 +126,12 @@ public class ArtistsController : BaseJellyfinApiController var dtoOptions = new DtoOptions { Fields = fields } .AddAdditionalDtoOptions(enableImages, enableUserData, imageTypeLimit, enableImageTypes); + // Asking for a type filter has always implied wanting that type's counts back. + if (includeItemTypes.Length != 0 && !dtoOptions.ContainsField(ItemFields.ItemCounts)) + { + dtoOptions.Fields = [.. dtoOptions.Fields, ItemFields.ItemCounts]; + } + User? user = null; BaseItem parentItem = _libraryManager.GetParentItem(parentId, userId); @@ -193,31 +199,7 @@ public class ArtistsController : BaseJellyfinApiController var result = _libraryManager.GetArtists(query); - var dtos = result.Items.Select(i => - { - var (baseItem, itemCounts) = i; - var dto = _dtoService.GetItemByNameDto(baseItem, dtoOptions, null, user); - - if (includeItemTypes.Length != 0) - { - dto.ChildCount = itemCounts.ItemCount; - dto.ProgramCount = itemCounts.ProgramCount; - dto.SeriesCount = itemCounts.SeriesCount; - dto.EpisodeCount = itemCounts.EpisodeCount; - dto.MovieCount = itemCounts.MovieCount; - dto.TrailerCount = itemCounts.TrailerCount; - dto.AlbumCount = itemCounts.AlbumCount; - dto.SongCount = itemCounts.SongCount; - dto.ArtistCount = itemCounts.ArtistCount; - } - - return dto; - }); - - return new QueryResult<BaseItemDto>( - query.StartIndex, - result.TotalRecordCount, - dtos.ToArray()); + return RequestHelpers.CreateQueryResult(result, dtoOptions, _dtoService, user); } /// <summary> @@ -298,6 +280,12 @@ public class ArtistsController : BaseJellyfinApiController var dtoOptions = new DtoOptions { Fields = fields } .AddAdditionalDtoOptions(enableImages, enableUserData, imageTypeLimit, enableImageTypes); + // Asking for a type filter has always implied wanting that type's counts back. + if (includeItemTypes.Length != 0 && !dtoOptions.ContainsField(ItemFields.ItemCounts)) + { + dtoOptions.Fields = [.. dtoOptions.Fields, ItemFields.ItemCounts]; + } + User? user = null; BaseItem parentItem = _libraryManager.GetParentItem(parentId, userId); @@ -365,31 +353,7 @@ public class ArtistsController : BaseJellyfinApiController var result = _libraryManager.GetAlbumArtists(query); - var dtos = result.Items.Select(i => - { - var (baseItem, itemCounts) = i; - var dto = _dtoService.GetItemByNameDto(baseItem, dtoOptions, null, user); - - if (includeItemTypes.Length != 0) - { - dto.ChildCount = itemCounts.ItemCount; - dto.ProgramCount = itemCounts.ProgramCount; - dto.SeriesCount = itemCounts.SeriesCount; - dto.EpisodeCount = itemCounts.EpisodeCount; - dto.MovieCount = itemCounts.MovieCount; - dto.TrailerCount = itemCounts.TrailerCount; - dto.AlbumCount = itemCounts.AlbumCount; - dto.SongCount = itemCounts.SongCount; - dto.ArtistCount = itemCounts.ArtistCount; - } - - return dto; - }); - - return new QueryResult<BaseItemDto>( - query.StartIndex, - result.TotalRecordCount, - dtos.ToArray()); + return RequestHelpers.CreateQueryResult(result, dtoOptions, _dtoService, user); } /// <summary> diff --git a/Jellyfin.Api/Controllers/GenresController.cs b/Jellyfin.Api/Controllers/GenresController.cs index 39c3f5abcf..18a8b67be2 100644 --- a/Jellyfin.Api/Controllers/GenresController.cs +++ b/Jellyfin.Api/Controllers/GenresController.cs @@ -97,6 +97,12 @@ public class GenresController : BaseJellyfinApiController var dtoOptions = new DtoOptions { Fields = fields } .AddAdditionalDtoOptions(enableImages, false, imageTypeLimit, enableImageTypes); + // Asking for a type filter has always implied wanting that type's counts back. + if (includeItemTypes.Length != 0 && !dtoOptions.ContainsField(ItemFields.ItemCounts)) + { + dtoOptions.Fields = [.. dtoOptions.Fields, ItemFields.ItemCounts]; + } + User? user = userId.IsNullOrEmpty() ? null : _userManager.GetUserById(userId.Value); @@ -143,8 +149,7 @@ public class GenresController : BaseJellyfinApiController result = _libraryManager.GetGenres(query); } - var shouldIncludeItemTypes = includeItemTypes.Length != 0; - return RequestHelpers.CreateQueryResult(result, dtoOptions, _dtoService, shouldIncludeItemTypes, user); + return RequestHelpers.CreateQueryResult(result, dtoOptions, _dtoService, user); } /// <summary> diff --git a/Jellyfin.Api/Controllers/LibraryStructureController.cs b/Jellyfin.Api/Controllers/LibraryStructureController.cs index 5c596c21b9..65bfe25d21 100644 --- a/Jellyfin.Api/Controllers/LibraryStructureController.cs +++ b/Jellyfin.Api/Controllers/LibraryStructureController.cs @@ -16,6 +16,7 @@ using MediaBrowser.Controller.Configuration; using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.IO; using MediaBrowser.Controller.Library; +using MediaBrowser.Controller.Providers; using MediaBrowser.Model.Configuration; using MediaBrowser.Model.Entities; using Microsoft.AspNetCore.Authorization; @@ -34,6 +35,7 @@ public class LibraryStructureController : BaseJellyfinApiController private readonly IServerApplicationPaths _appPaths; private readonly ILibraryManager _libraryManager; private readonly ILibraryMonitor _libraryMonitor; + private readonly IDirectoryService _directoryService; /// <summary> /// Initializes a new instance of the <see cref="LibraryStructureController"/> class. @@ -41,14 +43,17 @@ public class LibraryStructureController : BaseJellyfinApiController /// <param name="serverConfigurationManager">Instance of <see cref="IServerConfigurationManager"/> interface.</param> /// <param name="libraryManager">Instance of <see cref="ILibraryManager"/> interface.</param> /// <param name="libraryMonitor">Instance of <see cref="ILibraryMonitor"/> interface.</param> + /// <param name="directoryService">Instance of <see cref="IDirectoryService"/> interface.</param> public LibraryStructureController( IServerConfigurationManager serverConfigurationManager, ILibraryManager libraryManager, - ILibraryMonitor libraryMonitor) + ILibraryMonitor libraryMonitor, + IDirectoryService directoryService) { _appPaths = serverConfigurationManager.ApplicationPaths; _libraryManager = libraryManager; _libraryMonitor = libraryMonitor; + _directoryService = directoryService; } /// <summary> @@ -178,11 +183,11 @@ public class LibraryStructureController : BaseJellyfinApiController var tempPath = Path.Combine( rootFolderPath, Guid.NewGuid().ToString("N", CultureInfo.InvariantCulture)); - Directory.Move(currentPath, tempPath); + _directoryService.Move(currentPath, tempPath); currentPath = tempPath; } - Directory.Move(currentPath, newPath); + _directoryService.Move(currentPath, newPath); } finally { diff --git a/Jellyfin.Api/Controllers/MusicGenresController.cs b/Jellyfin.Api/Controllers/MusicGenresController.cs index 7af44f8bd6..4ebf914895 100644 --- a/Jellyfin.Api/Controllers/MusicGenresController.cs +++ b/Jellyfin.Api/Controllers/MusicGenresController.cs @@ -98,6 +98,12 @@ public class MusicGenresController : BaseJellyfinApiController var dtoOptions = new DtoOptions { Fields = fields } .AddAdditionalDtoOptions(enableImages, false, imageTypeLimit, enableImageTypes); + // Asking for a type filter has always implied wanting that type's counts back. + if (includeItemTypes.Length != 0 && !dtoOptions.ContainsField(ItemFields.ItemCounts)) + { + dtoOptions.Fields = [.. dtoOptions.Fields, ItemFields.ItemCounts]; + } + User? user = userId.IsNullOrEmpty() ? null : _userManager.GetUserById(userId.Value); @@ -134,8 +140,7 @@ public class MusicGenresController : BaseJellyfinApiController var result = _libraryManager.GetMusicGenres(query); - var shouldIncludeItemTypes = includeItemTypes.Length != 0; - return RequestHelpers.CreateQueryResult(result, dtoOptions, _dtoService, shouldIncludeItemTypes, user); + return RequestHelpers.CreateQueryResult(result, dtoOptions, _dtoService, user); } /// <summary> diff --git a/Jellyfin.Api/Controllers/PackageController.cs b/Jellyfin.Api/Controllers/PackageController.cs index 1f8f963f70..10bcf4e717 100644 --- a/Jellyfin.Api/Controllers/PackageController.cs +++ b/Jellyfin.Api/Controllers/PackageController.cs @@ -3,7 +3,9 @@ using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.Linq; using System.Threading.Tasks; +using Jellyfin.Extensions; using MediaBrowser.Common.Api; +using MediaBrowser.Common.Plugins; using MediaBrowser.Common.Updates; using MediaBrowser.Controller.Configuration; using MediaBrowser.Model.Updates; @@ -23,16 +25,22 @@ public class PackageController : BaseJellyfinApiController { private readonly IInstallationManager _installationManager; private readonly IServerConfigurationManager _serverConfigurationManager; + private readonly IPluginManager _pluginManager; /// <summary> /// Initializes a new instance of the <see cref="PackageController"/> class. /// </summary> /// <param name="installationManager">Instance of the <see cref="IInstallationManager"/> interface.</param> /// <param name="serverConfigurationManager">Instance of the <see cref="IServerConfigurationManager"/> interface.</param> - public PackageController(IInstallationManager installationManager, IServerConfigurationManager serverConfigurationManager) + /// <param name="pluginManager">Instance of the <see cref="IPluginManager"/> interface.</param> + public PackageController( + IInstallationManager installationManager, + IServerConfigurationManager serverConfigurationManager, + IPluginManager pluginManager) { _installationManager = installationManager; _serverConfigurationManager = serverConfigurationManager; + _pluginManager = pluginManager; } /// <summary> @@ -48,6 +56,13 @@ public class PackageController : BaseJellyfinApiController [FromRoute, Required] string name, [FromQuery] Guid? assemblyGuid) { + // Plugins bundled with the server are not published to any repository, so querying + // the configured repositories for them can only ever fail, and does so slowly. + if (IsBundledPlugin(name, assemblyGuid)) + { + return NotFound(); + } + var packages = await _installationManager.GetAvailablePackages().ConfigureAwait(false); var result = _installationManager.FilterPackages( packages, @@ -96,6 +111,11 @@ public class PackageController : BaseJellyfinApiController [FromQuery] string? version, [FromQuery] string? repositoryUrl) { + if (IsBundledPlugin(name, assemblyGuid)) + { + return NotFound(); + } + var packages = await _installationManager.GetAvailablePackages().ConfigureAwait(false); if (!string.IsNullOrEmpty(repositoryUrl)) { @@ -161,4 +181,13 @@ public class PackageController : BaseJellyfinApiController _serverConfigurationManager.SaveConfiguration(); return NoContent(); } + + private bool IsBundledPlugin(string name, Guid? assemblyGuid) + { + var plugin = assemblyGuid is Guid id && !id.IsEmpty() + ? _pluginManager.GetPlugin(id) + : _pluginManager.Plugins.FirstOrDefault(p => p.Name.Equals(name, StringComparison.OrdinalIgnoreCase)); + + return plugin?.Instance?.CanUninstall == false; + } } diff --git a/Jellyfin.Api/Controllers/StudiosController.cs b/Jellyfin.Api/Controllers/StudiosController.cs index a8feb206a4..5bac850859 100644 --- a/Jellyfin.Api/Controllers/StudiosController.cs +++ b/Jellyfin.Api/Controllers/StudiosController.cs @@ -92,6 +92,12 @@ public class StudiosController : BaseJellyfinApiController var dtoOptions = new DtoOptions { Fields = fields } .AddAdditionalDtoOptions(enableImages, enableUserData, imageTypeLimit, enableImageTypes); + // Asking for a type filter has always implied wanting that type's counts back. + if (includeItemTypes.Length != 0 && !dtoOptions.ContainsField(ItemFields.ItemCounts)) + { + dtoOptions.Fields = [.. dtoOptions.Fields, ItemFields.ItemCounts]; + } + User? user = userId.IsNullOrEmpty() ? null : _userManager.GetUserById(userId.Value); @@ -126,8 +132,7 @@ public class StudiosController : BaseJellyfinApiController } var result = _libraryManager.GetStudios(query); - var shouldIncludeItemTypes = includeItemTypes.Length != 0; - return RequestHelpers.CreateQueryResult(result, dtoOptions, _dtoService, shouldIncludeItemTypes, user); + return RequestHelpers.CreateQueryResult(result, dtoOptions, _dtoService, user); } /// <summary> diff --git a/Jellyfin.Api/Controllers/SubtitleController.cs b/Jellyfin.Api/Controllers/SubtitleController.cs index e5df873f5b..c4851091c1 100644 --- a/Jellyfin.Api/Controllers/SubtitleController.cs +++ b/Jellyfin.Api/Controllers/SubtitleController.cs @@ -557,7 +557,7 @@ public class SubtitleController : BaseJellyfinApiController if (!string.IsNullOrEmpty(fallbackFontPath)) { var fontFile = _fileSystem.GetFiles(fallbackFontPath) - .First(i => string.Equals(i.Name, name, StringComparison.OrdinalIgnoreCase)); + .FirstOrDefault(i => string.Equals(i.Name, name, StringComparison.OrdinalIgnoreCase)); var fileSize = fontFile?.Length; if (fontFile is not null && fileSize is not null && fileSize > 0) |
