Skip to content

Commit

Permalink
Enable nullable for LibraryManager (jellyfin#11191)
Browse files Browse the repository at this point in the history
  • Loading branch information
Bond-009 authored Apr 17, 2024
1 parent 356e05e commit bb018c4
Show file tree
Hide file tree
Showing 11 changed files with 121 additions and 126 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public CoreResolutionIgnoreRule(NamingOptions namingOptions, IServerApplicationP
}

/// <inheritdoc />
public bool ShouldIgnore(FileSystemMetadata fileInfo, BaseItem parent)
public bool ShouldIgnore(FileSystemMetadata fileInfo, BaseItem? parent)
{
// Don't ignore application folders
if (fileInfo.FullName.Contains(_serverApplicationPaths.RootFolderPath, StringComparison.InvariantCulture))
Expand Down
169 changes: 79 additions & 90 deletions Emby.Server.Implementations/Library/LibraryManager.cs

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ public async Task ValidatePeople(CancellationToken cancellationToken, IProgress<
try
{
var item = _libraryManager.GetPerson(person);
if (item is null)
{
_logger.LogWarning("Failed to get person: {Name}", person);
continue;
}

var options = new MetadataRefreshOptions(new DirectoryService(_fileSystem))
{
Expand Down Expand Up @@ -92,7 +97,7 @@ public async Task ValidatePeople(CancellationToken cancellationToken, IProgress<

var deadEntities = _libraryManager.GetItemList(new InternalItemsQuery
{
IncludeItemTypes = new[] { BaseItemKind.Person },
IncludeItemTypes = [BaseItemKind.Person],
IsDeadPerson = true,
IsLocked = false
});
Expand Down
16 changes: 7 additions & 9 deletions Jellyfin.Api/Controllers/LibraryStructureController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public ActionResult<IEnumerable<VirtualFolderInfo>> GetVirtualFolders()
[HttpPost]
[ProducesResponseType(StatusCodes.Status204NoContent)]
public async Task<ActionResult> AddVirtualFolder(
[FromQuery] string? name,
[FromQuery] string name,
[FromQuery] CollectionTypeOptions? collectionType,
[FromQuery, ModelBinder(typeof(CommaDelimitedArrayModelBinder))] string[] paths,
[FromBody] AddVirtualFolderDto? libraryOptionsDto,
Expand Down Expand Up @@ -103,7 +103,7 @@ public async Task<ActionResult> AddVirtualFolder(
[HttpDelete]
[ProducesResponseType(StatusCodes.Status204NoContent)]
public async Task<ActionResult> RemoveVirtualFolder(
[FromQuery] string? name,
[FromQuery] string name,
[FromQuery] bool refreshLibrary = false)
{
await _libraryManager.RemoveVirtualFolder(name, refreshLibrary).ConfigureAwait(false);
Expand Down Expand Up @@ -267,18 +267,16 @@ public ActionResult UpdateMediaPath([FromBody, Required] UpdateMediaPathRequestD
/// <param name="refreshLibrary">Whether to refresh the library.</param>
/// <returns>A <see cref="NoContentResult"/>.</returns>
/// <response code="204">Media path removed.</response>
/// <exception cref="ArgumentNullException">The name of the library may not be empty.</exception>
/// <exception cref="ArgumentException">The name of the library and path may not be empty.</exception>
[HttpDelete("Paths")]
[ProducesResponseType(StatusCodes.Status204NoContent)]
public ActionResult RemoveMediaPath(
[FromQuery] string? name,
[FromQuery] string? path,
[FromQuery] string name,
[FromQuery] string path,
[FromQuery] bool refreshLibrary = false)
{
if (string.IsNullOrWhiteSpace(name))
{
throw new ArgumentNullException(nameof(name));
}
ArgumentException.ThrowIfNullOrWhiteSpace(name);
ArgumentException.ThrowIfNullOrWhiteSpace(path);

_libraryMonitor.Stop();

Expand Down
4 changes: 3 additions & 1 deletion Jellyfin.Api/Helpers/MediaInfoHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
using MediaBrowser.Model.MediaInfo;
using MediaBrowser.Model.Session;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Http.HttpResults;
using Microsoft.Extensions.Logging;

namespace Jellyfin.Api.Helpers;
Expand Down Expand Up @@ -398,7 +399,8 @@ public async Task<LiveStreamResponse> OpenMediaSource(HttpContext httpContext, L

if (profile is not null)
{
var item = _libraryManager.GetItemById<BaseItem>(request.ItemId);
var item = _libraryManager.GetItemById<BaseItem>(request.ItemId)
?? throw new ResourceNotFoundException();

SetDeviceSpecificData(
item,
Expand Down
4 changes: 3 additions & 1 deletion Jellyfin.Api/Helpers/StreamingHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
using MediaBrowser.Model.Dto;
using MediaBrowser.Model.Entities;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Http.HttpResults;
using Microsoft.Net.Http.Headers;

namespace Jellyfin.Api.Helpers;
Expand Down Expand Up @@ -108,7 +109,8 @@ public static async Task<StreamState> GetStreamingState(
?? state.SupportedSubtitleCodecs.FirstOrDefault();
}

var item = libraryManager.GetItemById<BaseItem>(streamingRequest.Id);
var item = libraryManager.GetItemById<BaseItem>(streamingRequest.Id)
?? throw new ResourceNotFoundException();

state.IsInputVideo = item.MediaType == MediaType.Video;

Expand Down
2 changes: 1 addition & 1 deletion Jellyfin.Api/Models/LibraryStructureDto/MediaPathDto.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class MediaPathDto
/// Gets or sets the name of the library.
/// </summary>
[Required]
public string? Name { get; set; }
public required string Name { get; set; }

/// <summary>
/// Gets or sets the path to add.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public void Perform()
}

var libraryOptions = virtualFolder.LibraryOptions;
var collectionFolder = (CollectionFolder)_libraryManager.GetItemById(folderId);
var collectionFolder = _libraryManager.GetItemById<CollectionFolder>(folderId) ?? throw new InvalidOperationException("Failed to find CollectionFolder");
// The property no longer exists in LibraryOptions, so we just re-save the options to get old data removed.
collectionFolder.UpdateLibraryOptions(libraryOptions);
_logger.LogInformation("Removed from '{VirtualFolder}'", virtualFolder.Name);
Expand Down
37 changes: 18 additions & 19 deletions MediaBrowser.Controller/Library/ILibraryManager.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#nullable disable

#pragma warning disable CA1002, CS1591

using System;
Expand Down Expand Up @@ -33,17 +31,17 @@ public interface ILibraryManager
/// <summary>
/// Occurs when [item added].
/// </summary>
event EventHandler<ItemChangeEventArgs> ItemAdded;
event EventHandler<ItemChangeEventArgs>? ItemAdded;

/// <summary>
/// Occurs when [item updated].
/// </summary>
event EventHandler<ItemChangeEventArgs> ItemUpdated;
event EventHandler<ItemChangeEventArgs>? ItemUpdated;

/// <summary>
/// Occurs when [item removed].
/// </summary>
event EventHandler<ItemChangeEventArgs> ItemRemoved;
event EventHandler<ItemChangeEventArgs>? ItemRemoved;

/// <summary>
/// Gets the root folder.
Expand All @@ -60,10 +58,10 @@ public interface ILibraryManager
/// <param name="parent">The parent.</param>
/// <param name="directoryService">An instance of <see cref="IDirectoryService"/>.</param>
/// <returns>BaseItem.</returns>
BaseItem ResolvePath(
BaseItem? ResolvePath(
FileSystemMetadata fileInfo,
Folder parent = null,
IDirectoryService directoryService = null);
Folder? parent = null,
IDirectoryService? directoryService = null);

/// <summary>
/// Resolves a set of files into a list of BaseItem.
Expand All @@ -86,15 +84,15 @@ IEnumerable<BaseItem> ResolvePaths(
/// </summary>
/// <param name="name">The name of the person.</param>
/// <returns>Task{Person}.</returns>
Person GetPerson(string name);
Person? GetPerson(string name);

/// <summary>
/// Finds the by path.
/// </summary>
/// <param name="path">The path.</param>
/// <param name="isFolder"><c>true</c> is the path is a directory; otherwise <c>false</c>.</param>
/// <returns>BaseItem.</returns>
BaseItem FindByPath(string path, bool? isFolder);
BaseItem? FindByPath(string path, bool? isFolder);

/// <summary>
/// Gets the artist.
Expand Down Expand Up @@ -166,15 +164,16 @@ IEnumerable<BaseItem> ResolvePaths(
/// </summary>
/// <param name="id">The id.</param>
/// <returns>BaseItem.</returns>
BaseItem GetItemById(Guid id);
/// <exception cref="ArgumentNullException"><paramref name="id"/> is <c>null</c>.</exception>
BaseItem? GetItemById(Guid id);

/// <summary>
/// Gets the item by id, as T.
/// </summary>
/// <param name="id">The item id.</param>
/// <typeparam name="T">The type of item.</typeparam>
/// <returns>The item.</returns>
T GetItemById<T>(Guid id)
T? GetItemById<T>(Guid id)
where T : BaseItem;

/// <summary>
Expand All @@ -184,7 +183,7 @@ T GetItemById<T>(Guid id)
/// <param name="userId">The user id to validate against.</param>
/// <typeparam name="T">The type of item.</typeparam>
/// <returns>The item if found.</returns>
public T GetItemById<T>(Guid id, Guid userId)
public T? GetItemById<T>(Guid id, Guid userId)
where T : BaseItem;

/// <summary>
Expand All @@ -194,7 +193,7 @@ public T GetItemById<T>(Guid id, Guid userId)
/// <param name="user">The user to validate against.</param>
/// <typeparam name="T">The type of item.</typeparam>
/// <returns>The item if found.</returns>
public T GetItemById<T>(Guid id, User user)
public T? GetItemById<T>(Guid id, User? user)
where T : BaseItem;

/// <summary>
Expand Down Expand Up @@ -228,9 +227,9 @@ void AddParts(
/// <param name="sortBy">The sort by.</param>
/// <param name="sortOrder">The sort order.</param>
/// <returns>IEnumerable{BaseItem}.</returns>
IEnumerable<BaseItem> Sort(IEnumerable<BaseItem> items, User user, IEnumerable<ItemSortBy> sortBy, SortOrder sortOrder);
IEnumerable<BaseItem> Sort(IEnumerable<BaseItem> items, User? user, IEnumerable<ItemSortBy> sortBy, SortOrder sortOrder);

IEnumerable<BaseItem> Sort(IEnumerable<BaseItem> items, User user, IEnumerable<(ItemSortBy OrderBy, SortOrder SortOrder)> orderBy);
IEnumerable<BaseItem> Sort(IEnumerable<BaseItem> items, User? user, IEnumerable<(ItemSortBy OrderBy, SortOrder SortOrder)> orderBy);

/// <summary>
/// Gets the user root folder.
Expand All @@ -243,15 +242,15 @@ void AddParts(
/// </summary>
/// <param name="item">Item to create.</param>
/// <param name="parent">Parent of new item.</param>
void CreateItem(BaseItem item, BaseItem parent);
void CreateItem(BaseItem item, BaseItem? parent);

/// <summary>
/// Creates the items.
/// </summary>
/// <param name="items">Items to create.</param>
/// <param name="parent">Parent of new items.</param>
/// <param name="cancellationToken">CancellationToken to use for operation.</param>
void CreateItems(IReadOnlyList<BaseItem> items, BaseItem parent, CancellationToken cancellationToken);
void CreateItems(IReadOnlyList<BaseItem> items, BaseItem? parent, CancellationToken cancellationToken);

/// <summary>
/// Updates the item.
Expand Down Expand Up @@ -529,7 +528,7 @@ UserView GetShadowView(
/// <returns>QueryResult&lt;BaseItem&gt;.</returns>
QueryResult<BaseItem> QueryItems(InternalItemsQuery query);

string GetPathAfterNetworkSubstitution(string path, BaseItem ownerItem = null);
string GetPathAfterNetworkSubstitution(string path, BaseItem? ownerItem = null);

/// <summary>
/// Converts the image to local.
Expand Down
2 changes: 1 addition & 1 deletion MediaBrowser.Controller/Resolvers/IResolverIgnoreRule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ public interface IResolverIgnoreRule
/// <param name="fileInfo">The file information.</param>
/// <param name="parent">The parent BaseItem.</param>
/// <returns>True if the file should be ignored.</returns>
bool ShouldIgnore(FileSystemMetadata fileInfo, BaseItem parent);
bool ShouldIgnore(FileSystemMetadata fileInfo, BaseItem? parent);
}
}
2 changes: 1 addition & 1 deletion MediaBrowser.XbmcMetadata/Savers/BaseNfoSaver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -947,7 +947,7 @@ private void AddActors(List<PersonInfo> people, XmlWriter writer, ILibraryManage
if (saveImagePath)
{
var personEntity = libraryManager.GetPerson(person.Name);
var image = personEntity.GetImageInfo(ImageType.Primary, 0);
var image = personEntity?.GetImageInfo(ImageType.Primary, 0);

if (image is not null)
{
Expand Down

0 comments on commit bb018c4

Please sign in to comment.