From a0c568bc6c9944fab8b6d1d6d420a9716bdab1e9 Mon Sep 17 00:00:00 2001 From: JPVenson Date: Sun, 15 Dec 2024 14:46:40 +0000 Subject: [PATCH] Applied review comments --- .../Controllers/PlaystateController.cs | 12 +++++------ .../Controllers/UserLibraryController.cs | 12 +++++------ Jellyfin.Data/Entities/BaseItemEntity.cs | 6 +++--- Jellyfin.Data/Entities/BaseItemExtraType.cs | 2 +- Jellyfin.Data/Entities/BaseItemImageInfo.cs | 6 ++++-- Jellyfin.Data/Entities/ItemValueType.cs | 2 -- Jellyfin.Data/Entities/MediaStreamInfo.cs | 3 ++- Jellyfin.Data/Entities/People.cs | 3 ++- .../Item/BaseItemRepository.cs | 21 ++++++++++++------- .../MediaInfo/AudioImageProvider.cs | 4 ++-- .../MediaInfo/VideoImageProvider.cs | 3 ++- 11 files changed, 42 insertions(+), 32 deletions(-) diff --git a/Jellyfin.Api/Controllers/PlaystateController.cs b/Jellyfin.Api/Controllers/PlaystateController.cs index 292344c9dd..794c6500c6 100644 --- a/Jellyfin.Api/Controllers/PlaystateController.cs +++ b/Jellyfin.Api/Controllers/PlaystateController.cs @@ -72,7 +72,7 @@ public class PlaystateController : BaseJellyfinApiController [HttpPost("UserPlayedItems/{itemId}")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status404NotFound)] - public async Task> MarkPlayedItem( + public async Task> MarkPlayedItem( [FromQuery] Guid? userId, [FromRoute, Required] Guid itemId, [FromQuery, ModelBinder(typeof(LegacyDateTimeModelBinder))] DateTime? datePlayed) @@ -121,7 +121,7 @@ public class PlaystateController : BaseJellyfinApiController [ProducesResponseType(StatusCodes.Status404NotFound)] [Obsolete("Kept for backwards compatibility")] [ApiExplorerSettings(IgnoreApi = true)] - public Task> MarkPlayedItemLegacy( + public Task> MarkPlayedItemLegacy( [FromRoute, Required] Guid userId, [FromRoute, Required] Guid itemId, [FromQuery, ModelBinder(typeof(LegacyDateTimeModelBinder))] DateTime? datePlayed) @@ -138,7 +138,7 @@ public class PlaystateController : BaseJellyfinApiController [HttpDelete("UserPlayedItems/{itemId}")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status404NotFound)] - public async Task> MarkUnplayedItem( + public async Task> MarkUnplayedItem( [FromQuery] Guid? userId, [FromRoute, Required] Guid itemId) { @@ -185,7 +185,7 @@ public class PlaystateController : BaseJellyfinApiController [ProducesResponseType(StatusCodes.Status404NotFound)] [Obsolete("Kept for backwards compatibility")] [ApiExplorerSettings(IgnoreApi = true)] - public Task> MarkUnplayedItemLegacy( + public Task> MarkUnplayedItemLegacy( [FromRoute, Required] Guid userId, [FromRoute, Required] Guid itemId) => MarkUnplayedItem(userId, itemId); @@ -502,7 +502,7 @@ public class PlaystateController : BaseJellyfinApiController /// if set to true [was played]. /// The date played. /// Task. - private UserItemDataDto UpdatePlayedStatus(User user, BaseItem item, bool wasPlayed, DateTime? datePlayed) + private UserItemDataDto? UpdatePlayedStatus(User user, BaseItem item, bool wasPlayed, DateTime? datePlayed) { if (wasPlayed) { @@ -513,7 +513,7 @@ public class PlaystateController : BaseJellyfinApiController item.MarkUnplayed(user); } - return _userDataRepository.GetUserDataDto(item, user)!; + return _userDataRepository.GetUserDataDto(item, user); } private PlayMethod ValidatePlayMethod(PlayMethod method, string? playSessionId) diff --git a/Jellyfin.Api/Controllers/UserLibraryController.cs b/Jellyfin.Api/Controllers/UserLibraryController.cs index 5330db48bf..272a59559f 100644 --- a/Jellyfin.Api/Controllers/UserLibraryController.cs +++ b/Jellyfin.Api/Controllers/UserLibraryController.cs @@ -305,7 +305,7 @@ public class UserLibraryController : BaseJellyfinApiController /// An containing the . [HttpDelete("UserItems/{itemId}/Rating")] [ProducesResponseType(StatusCodes.Status200OK)] - public ActionResult DeleteUserItemRating( + public ActionResult DeleteUserItemRating( [FromQuery] Guid? userId, [FromRoute, Required] Guid itemId) { @@ -338,7 +338,7 @@ public class UserLibraryController : BaseJellyfinApiController [ProducesResponseType(StatusCodes.Status200OK)] [Obsolete("Kept for backwards compatibility")] [ApiExplorerSettings(IgnoreApi = true)] - public ActionResult DeleteUserItemRatingLegacy( + public ActionResult DeleteUserItemRatingLegacy( [FromRoute, Required] Guid userId, [FromRoute, Required] Guid itemId) => DeleteUserItemRating(userId, itemId); @@ -353,7 +353,7 @@ public class UserLibraryController : BaseJellyfinApiController /// An containing the . [HttpPost("UserItems/{itemId}/Rating")] [ProducesResponseType(StatusCodes.Status200OK)] - public ActionResult UpdateUserItemRating( + public ActionResult UpdateUserItemRating( [FromQuery] Guid? userId, [FromRoute, Required] Guid itemId, [FromQuery] bool? likes) @@ -388,7 +388,7 @@ public class UserLibraryController : BaseJellyfinApiController [ProducesResponseType(StatusCodes.Status200OK)] [Obsolete("Kept for backwards compatibility")] [ApiExplorerSettings(IgnoreApi = true)] - public ActionResult UpdateUserItemRatingLegacy( + public ActionResult UpdateUserItemRatingLegacy( [FromRoute, Required] Guid userId, [FromRoute, Required] Guid itemId, [FromQuery] bool? likes) @@ -679,7 +679,7 @@ public class UserLibraryController : BaseJellyfinApiController /// The user. /// The item. /// if set to true [likes]. - private UserItemDataDto UpdateUserItemRatingInternal(User user, BaseItem item, bool? likes) + private UserItemDataDto? UpdateUserItemRatingInternal(User user, BaseItem item, bool? likes) { // Get the user data for this item var data = _userDataRepository.GetUserData(user, item); @@ -691,6 +691,6 @@ public class UserLibraryController : BaseJellyfinApiController _userDataRepository.SaveUserData(user, item, data, UserDataSaveReason.UpdateUserRating, CancellationToken.None); } - return _userDataRepository.GetUserDataDto(item, user)!; + return _userDataRepository.GetUserDataDto(item, user); } } diff --git a/Jellyfin.Data/Entities/BaseItemEntity.cs b/Jellyfin.Data/Entities/BaseItemEntity.cs index 0c9020a666..33b2b67413 100644 --- a/Jellyfin.Data/Entities/BaseItemEntity.cs +++ b/Jellyfin.Data/Entities/BaseItemEntity.cs @@ -1,3 +1,6 @@ +#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member +#pragma warning disable CA2227 // Collection properties should be read only + using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; @@ -5,9 +8,6 @@ using System.ComponentModel.DataAnnotations.Schema; namespace Jellyfin.Data.Entities; -#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member -#pragma warning disable CA2227 // Collection properties should be read only - public class BaseItemEntity { public required Guid Id { get; set; } diff --git a/Jellyfin.Data/Entities/BaseItemExtraType.cs b/Jellyfin.Data/Entities/BaseItemExtraType.cs index 3416974361..54aef50e40 100644 --- a/Jellyfin.Data/Entities/BaseItemExtraType.cs +++ b/Jellyfin.Data/Entities/BaseItemExtraType.cs @@ -1,6 +1,6 @@ +#pragma warning disable CS1591 namespace Jellyfin.Data.Entities; -#pragma warning disable CS1591 public enum BaseItemExtraType { Unknown = 0, diff --git a/Jellyfin.Data/Entities/BaseItemImageInfo.cs b/Jellyfin.Data/Entities/BaseItemImageInfo.cs index 6390cac58e..37723df116 100644 --- a/Jellyfin.Data/Entities/BaseItemImageInfo.cs +++ b/Jellyfin.Data/Entities/BaseItemImageInfo.cs @@ -1,8 +1,9 @@ +#pragma warning disable CA2227 + using System; using System.Collections.Generic; namespace Jellyfin.Data.Entities; -#pragma warning disable CA2227 /// /// Enum TrailerTypes. @@ -39,11 +40,12 @@ public class BaseItemImageInfo /// public int Height { get; set; } -#pragma warning disable CA1819 +#pragma warning disable CA1819 // Properties should not return arrays /// /// Gets or Sets the blurhash. /// public byte[]? Blurhash { get; set; } +#pragma warning restore CA1819 /// /// Gets or Sets the reference id to the BaseItem. diff --git a/Jellyfin.Data/Entities/ItemValueType.cs b/Jellyfin.Data/Entities/ItemValueType.cs index 006036b40e..48c5d0f305 100644 --- a/Jellyfin.Data/Entities/ItemValueType.cs +++ b/Jellyfin.Data/Entities/ItemValueType.cs @@ -10,9 +10,7 @@ public enum ItemValueType /// /// Artists. /// -#pragma warning disable CA1008 // Enums should have zero value. Cannot apply here. Artist = 0, -#pragma warning restore CA1008 // Enums should have zero value /// /// Album. diff --git a/Jellyfin.Data/Entities/MediaStreamInfo.cs b/Jellyfin.Data/Entities/MediaStreamInfo.cs index 79053652a3..77816565af 100644 --- a/Jellyfin.Data/Entities/MediaStreamInfo.cs +++ b/Jellyfin.Data/Entities/MediaStreamInfo.cs @@ -1,9 +1,10 @@ +#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member + using System; using System.Diagnostics.CodeAnalysis; namespace Jellyfin.Data.Entities; -#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member public class MediaStreamInfo { public required Guid ItemId { get; set; } diff --git a/Jellyfin.Data/Entities/People.cs b/Jellyfin.Data/Entities/People.cs index b1834a70d5..18c778b17a 100644 --- a/Jellyfin.Data/Entities/People.cs +++ b/Jellyfin.Data/Entities/People.cs @@ -1,8 +1,9 @@ +#pragma warning disable CA2227 // Collection properties should be read only + using System; using System.Collections.Generic; namespace Jellyfin.Data.Entities; -#pragma warning disable CA2227 // Collection properties should be read only /// /// People entity. diff --git a/Jellyfin.Server.Implementations/Item/BaseItemRepository.cs b/Jellyfin.Server.Implementations/Item/BaseItemRepository.cs index e1f0dc3c02..4f8fe467af 100644 --- a/Jellyfin.Server.Implementations/Item/BaseItemRepository.cs +++ b/Jellyfin.Server.Implementations/Item/BaseItemRepository.cs @@ -1,3 +1,9 @@ +#pragma warning disable RS0030 // Do not use banned APIs +// Do not enforce that because EFCore cannot deal with cultures well. +#pragma warning disable CA1304 // Specify CultureInfo +#pragma warning disable CA1311 // Specify a culture or use an invariant version +#pragma warning disable CA1862 // Use the 'StringComparison' method overloads to perform case-insensitive string comparisons + using System; using System.Collections.Concurrent; using System.Collections.Generic; @@ -31,14 +37,15 @@ using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Logging; using BaseItemDto = MediaBrowser.Controller.Entities.BaseItem; using BaseItemEntity = Jellyfin.Data.Entities.BaseItemEntity; -#pragma warning disable RS0030 // Do not use banned APIs -// Do not enforce that because EFCore cannot deal with cultures well. -#pragma warning disable CA1304 // Specify CultureInfo -#pragma warning disable CA1311 // Specify a culture or use an invariant version -#pragma warning disable CA1862 // Use the 'StringComparison' method overloads to perform case-insensitive string comparisons namespace Jellyfin.Server.Implementations.Item; + +/* + All queries in this class and all other nullable enabled EFCore repository classes will make libraral use of the null-forgiving operator "!". + This is done as the code isn't actually executed client side, but only the expressions are interpretet and the compiler cannot know that. + This is your only warning/message regarding this topic. +*/ /// /// Handles all storage logic for BaseItems. /// @@ -1065,7 +1072,7 @@ public sealed class BaseItemRepository ItemId = baseItemId, Id = Guid.NewGuid(), Path = e.Path, - Blurhash = e.BlurHash != null ? Encoding.UTF8.GetBytes(e.BlurHash) : null, + Blurhash = e.BlurHash is null ? null : Encoding.UTF8.GetBytes(e.BlurHash), DateModified = e.DateModified, Height = e.Height, Width = e.Width, @@ -1079,7 +1086,7 @@ public sealed class BaseItemRepository return new ItemImageInfo() { Path = appHost?.ExpandVirtualPath(e.Path) ?? e.Path, - BlurHash = e.Blurhash != null ? Encoding.UTF8.GetString(e.Blurhash) : null, + BlurHash = e.Blurhash is null ? null : Encoding.UTF8.GetString(e.Blurhash), DateModified = e.DateModified, Height = e.Height, Width = e.Width, diff --git a/MediaBrowser.Providers/MediaInfo/AudioImageProvider.cs b/MediaBrowser.Providers/MediaInfo/AudioImageProvider.cs index bfe4f3300f..71ea8af52a 100644 --- a/MediaBrowser.Providers/MediaInfo/AudioImageProvider.cs +++ b/MediaBrowser.Providers/MediaInfo/AudioImageProvider.cs @@ -81,11 +81,11 @@ namespace MediaBrowser.Providers.MediaInfo if (!File.Exists(path)) { Directory.CreateDirectory(Path.GetDirectoryName(path)); - +#pragma warning disable CA1826 var imageStream = imageStreams.FirstOrDefault(i => (i.Comment ?? string.Empty).Contains("front", StringComparison.OrdinalIgnoreCase)) ?? imageStreams.FirstOrDefault(i => (i.Comment ?? string.Empty).Contains("cover", StringComparison.OrdinalIgnoreCase)) ?? imageStreams.FirstOrDefault(); - +#pragma warning restore CA1826 var imageStreamIndex = imageStream?.Index; var tempFile = await _mediaEncoder.ExtractAudioImage(item.Path, imageStreamIndex, cancellationToken).ConfigureAwait(false); diff --git a/MediaBrowser.Providers/MediaInfo/VideoImageProvider.cs b/MediaBrowser.Providers/MediaInfo/VideoImageProvider.cs index ba7ad40727..bd6b40c51e 100644 --- a/MediaBrowser.Providers/MediaInfo/VideoImageProvider.cs +++ b/MediaBrowser.Providers/MediaInfo/VideoImageProvider.cs @@ -88,6 +88,7 @@ namespace MediaBrowser.Providers.MediaInfo : TimeSpan.FromSeconds(10); var query = new MediaStreamQuery { ItemId = item.Id, Index = item.DefaultVideoStreamIndex }; +#pragma warning disable CA1826 var videoStream = _mediaSourceManager.GetMediaStreams(query).FirstOrDefault(); if (videoStream is null) { @@ -95,7 +96,7 @@ namespace MediaBrowser.Providers.MediaInfo query.Index = null; videoStream = _mediaSourceManager.GetMediaStreams(query).FirstOrDefault(); } - +#pragma warning restore CA1826 if (videoStream is null) { _logger.LogInformation("Skipping image extraction: no video stream found for {Path}.", item.Path ?? string.Empty);