diff options
Diffstat (limited to 'Jellyfin.Api/Controllers')
39 files changed, 162 insertions, 170 deletions
diff --git a/Jellyfin.Api/Controllers/ArtistsController.cs b/Jellyfin.Api/Controllers/ArtistsController.cs index c059cb198..c8ac2ed52 100644 --- a/Jellyfin.Api/Controllers/ArtistsController.cs +++ b/Jellyfin.Api/Controllers/ArtistsController.cs @@ -183,7 +183,7 @@ namespace Jellyfin.Api.Controllers { return null; } - }).Where(i => i != null).Select(i => i!.Id).ToArray(); + }).Where(i => i is not null).Select(i => i!.Id).ToArray(); } foreach (var filter in filters) @@ -386,7 +386,7 @@ namespace Jellyfin.Api.Controllers { return null; } - }).Where(i => i != null).Select(i => i!.Id).ToArray(); + }).Where(i => i is not null).Select(i => i!.Id).ToArray(); } foreach (var filter in filters) diff --git a/Jellyfin.Api/Controllers/ConfigurationController.cs b/Jellyfin.Api/Controllers/ConfigurationController.cs index bbe163312..a00ac1b0a 100644 --- a/Jellyfin.Api/Controllers/ConfigurationController.cs +++ b/Jellyfin.Api/Controllers/ConfigurationController.cs @@ -96,7 +96,7 @@ namespace Jellyfin.Api.Controllers var configurationType = _configurationManager.GetConfigurationType(key); var deserializedConfiguration = configuration.Deserialize(configurationType, _serializerOptions); - if (deserializedConfiguration == null) + if (deserializedConfiguration is null) { throw new ArgumentException("Body doesn't contain a valid configuration"); } diff --git a/Jellyfin.Api/Controllers/DashboardController.cs b/Jellyfin.Api/Controllers/DashboardController.cs index c8411f44b..3894e6c5f 100644 --- a/Jellyfin.Api/Controllers/DashboardController.cs +++ b/Jellyfin.Api/Controllers/DashboardController.cs @@ -76,7 +76,7 @@ namespace Jellyfin.Api.Controllers public ActionResult GetDashboardConfigurationPage([FromQuery] string? name) { var altPage = GetPluginPages().FirstOrDefault(p => string.Equals(p.Item1.Name, name, StringComparison.OrdinalIgnoreCase)); - if (altPage == null) + if (altPage is null) { return NotFound(); } @@ -84,7 +84,7 @@ namespace Jellyfin.Api.Controllers IPlugin plugin = altPage.Item2; string resourcePath = altPage.Item1.EmbeddedResourcePath; Stream? stream = plugin.GetType().Assembly.GetManifestResourceStream(resourcePath); - if (stream == null) + if (stream is null) { _logger.LogError("Failed to get resource {Resource} from plugin {Plugin}", resourcePath, plugin.Name); return NotFound(); diff --git a/Jellyfin.Api/Controllers/DevicesController.cs b/Jellyfin.Api/Controllers/DevicesController.cs index 8292cf83b..aad60cf5c 100644 --- a/Jellyfin.Api/Controllers/DevicesController.cs +++ b/Jellyfin.Api/Controllers/DevicesController.cs @@ -64,7 +64,7 @@ namespace Jellyfin.Api.Controllers public async Task<ActionResult<DeviceInfo>> GetDeviceInfo([FromQuery, Required] string id) { var deviceInfo = await _deviceManager.GetDevice(id).ConfigureAwait(false); - if (deviceInfo == null) + if (deviceInfo is null) { return NotFound(); } @@ -85,7 +85,7 @@ namespace Jellyfin.Api.Controllers public async Task<ActionResult<DeviceOptions>> GetDeviceOptions([FromQuery, Required] string id) { var deviceInfo = await _deviceManager.GetDeviceOptions(id).ConfigureAwait(false); - if (deviceInfo == null) + if (deviceInfo is null) { return NotFound(); } @@ -123,7 +123,7 @@ namespace Jellyfin.Api.Controllers public async Task<ActionResult> DeleteDevice([FromQuery, Required] string id) { var existingDevice = await _deviceManager.GetDevice(id).ConfigureAwait(false); - if (existingDevice == null) + if (existingDevice is null) { return NotFound(); } diff --git a/Jellyfin.Api/Controllers/DisplayPreferencesController.cs b/Jellyfin.Api/Controllers/DisplayPreferencesController.cs index 14fd7eb3c..67cceb4a8 100644 --- a/Jellyfin.Api/Controllers/DisplayPreferencesController.cs +++ b/Jellyfin.Api/Controllers/DisplayPreferencesController.cs @@ -178,7 +178,7 @@ namespace Jellyfin.Api.Controllers foreach (var key in displayPreferences.CustomPrefs.Keys.Where(key => key.StartsWith("homesection", StringComparison.OrdinalIgnoreCase))) { - var order = int.Parse(key.AsSpan().Slice("homesection".Length), NumberStyles.Any, CultureInfo.InvariantCulture); + var order = int.Parse(key.AsSpan().Slice("homesection".Length), CultureInfo.InvariantCulture); if (!Enum.TryParse<HomeSectionType>(displayPreferences.CustomPrefs[key], true, out var type)) { type = order < 8 ? defaults[order] : HomeSectionType.None; diff --git a/Jellyfin.Api/Controllers/DlnaController.cs b/Jellyfin.Api/Controllers/DlnaController.cs index 35c3a3d92..07e0590a1 100644 --- a/Jellyfin.Api/Controllers/DlnaController.cs +++ b/Jellyfin.Api/Controllers/DlnaController.cs @@ -63,7 +63,7 @@ namespace Jellyfin.Api.Controllers public ActionResult<DeviceProfile> GetProfile([FromRoute, Required] string profileId) { var profile = _dlnaManager.GetProfile(profileId); - if (profile == null) + if (profile is null) { return NotFound(); } @@ -84,7 +84,7 @@ namespace Jellyfin.Api.Controllers public ActionResult DeleteProfile([FromRoute, Required] string profileId) { var existingDeviceProfile = _dlnaManager.GetProfile(profileId); - if (existingDeviceProfile == null) + if (existingDeviceProfile is null) { return NotFound(); } @@ -121,7 +121,7 @@ namespace Jellyfin.Api.Controllers public ActionResult UpdateProfile([FromRoute, Required] string profileId, [FromBody] DeviceProfile deviceProfile) { var existingDeviceProfile = _dlnaManager.GetProfile(profileId); - if (existingDeviceProfile == null) + if (existingDeviceProfile is null) { return NotFound(); } diff --git a/Jellyfin.Api/Controllers/DlnaServerController.cs b/Jellyfin.Api/Controllers/DlnaServerController.cs index 8859d6020..96c492b3e 100644 --- a/Jellyfin.Api/Controllers/DlnaServerController.cs +++ b/Jellyfin.Api/Controllers/DlnaServerController.cs @@ -274,7 +274,7 @@ namespace Jellyfin.Api.Controllers private ActionResult GetIconInternal(string fileName) { var icon = _dlnaManager.GetIcon(fileName); - if (icon == null) + if (icon is null) { return NotFound(); } diff --git a/Jellyfin.Api/Controllers/DynamicHlsController.cs b/Jellyfin.Api/Controllers/DynamicHlsController.cs index 0f4d3c1eb..af43bb578 100644 --- a/Jellyfin.Api/Controllers/DynamicHlsController.cs +++ b/Jellyfin.Api/Controllers/DynamicHlsController.cs @@ -341,7 +341,7 @@ namespace Jellyfin.Api.Controllers job ??= _transcodingJobHelper.OnTranscodeBeginRequest(playlistPath, TranscodingJobType); - if (job != null) + if (job is not null) { _transcodingJobHelper.OnTranscodeEndRequest(job); } @@ -1482,7 +1482,7 @@ namespace Jellyfin.Api.Controllers startTranscoding = true; segmentId = 0; } - else if (currentTranscodingIndex == null) + else if (currentTranscodingIndex is null) { _logger.LogDebug("Starting transcoding because currentTranscodingIndex=null"); startTranscoding = true; @@ -1533,7 +1533,7 @@ namespace Jellyfin.Api.Controllers else { job = _transcodingJobHelper.OnTranscodeBeginRequest(playlistPath, TranscodingJobType); - if (job?.TranscodingThrottler != null) + if (job?.TranscodingThrottler is not null) { await job.TranscodingThrottler.UnpauseTranscoding().ConfigureAwait(false); } @@ -1665,7 +1665,7 @@ namespace Jellyfin.Api.Controllers /// <returns>The command line arguments for audio transcoding.</returns> private string GetAudioArguments(StreamState state) { - if (state.AudioStream == null) + if (state.AudioStream is null) { return string.Empty; } @@ -1762,7 +1762,7 @@ namespace Jellyfin.Api.Controllers /// <returns>The command line arguments for video transcoding.</returns> private string GetVideoArguments(StreamState state, int startNumber, bool isEventPlaylist) { - if (state.VideoStream == null) + if (state.VideoStream is null) { return string.Empty; } @@ -1806,7 +1806,7 @@ namespace Jellyfin.Api.Controllers if (EncodingHelper.IsCopyCodec(codec)) { // If h264_mp4toannexb is ever added, do not use it for live tv. - if (state.VideoStream != null && !string.Equals(state.VideoStream.NalLengthSize, "0", StringComparison.OrdinalIgnoreCase)) + if (state.VideoStream is not null && !string.Equals(state.VideoStream.NalLengthSize, "0", StringComparison.OrdinalIgnoreCase)) { string bitStreamArgs = EncodingHelper.GetBitStreamArgs(state.VideoStream); if (!string.IsNullOrEmpty(bitStreamArgs)) @@ -1837,7 +1837,7 @@ namespace Jellyfin.Api.Controllers // -start_at_zero is necessary to use with -ss when seeking, // otherwise the target position cannot be determined. - if (state.SubtitleStream != null) + if (state.SubtitleStream is not null) { // Disable start_at_zero for external graphical subs if (!(state.SubtitleStream.IsExternal && !state.SubtitleStream.IsTextSubtitleStream)) @@ -1883,7 +1883,7 @@ namespace Jellyfin.Api.Controllers var segmentExists = System.IO.File.Exists(segmentPath); if (segmentExists) { - if (transcodingJob != null && transcodingJob.HasExited) + if (transcodingJob is not null && transcodingJob.HasExited) { // Transcoding job is over, so assume all existing files are ready _logger.LogDebug("serving up {0} as transcode is over", segmentPath); @@ -1901,7 +1901,7 @@ namespace Jellyfin.Api.Controllers } var nextSegmentPath = GetSegmentPath(state, playlistPath, segmentIndex + 1); - if (transcodingJob != null) + if (transcodingJob is not null) { while (!cancellationToken.IsCancellationRequested && !transcodingJob.HasExited) { @@ -1953,7 +1953,7 @@ namespace Jellyfin.Api.Controllers Response.OnCompleted(() => { _logger.LogDebug("Finished serving {SegmentPath}", segmentPath); - if (transcodingJob != null) + if (transcodingJob is not null) { transcodingJob.DownloadPositionTicks = Math.Max(transcodingJob.DownloadPositionTicks ?? segmentEndingPositionTicks, segmentEndingPositionTicks); _transcodingJobHelper.OnTranscodeEndRequest(transcodingJob); @@ -1969,14 +1969,14 @@ namespace Jellyfin.Api.Controllers { var job = _transcodingJobHelper.GetTranscodingJob(playlist, TranscodingJobType); - if (job == null || job.HasExited) + if (job is null || job.HasExited) { return null; } var file = GetLastTranscodingFile(playlist, segmentExtension, _fileSystem); - if (file == null) + if (file is null) { return null; } @@ -2011,7 +2011,7 @@ namespace Jellyfin.Api.Controllers { var file = GetLastTranscodingFile(playlistPath, segmentExtension, _fileSystem); - if (file != null) + if (file is not null) { DeleteFile(file.FullName, retryCount); } diff --git a/Jellyfin.Api/Controllers/EnvironmentController.cs b/Jellyfin.Api/Controllers/EnvironmentController.cs index b0b4b5af5..6c78a7987 100644 --- a/Jellyfin.Api/Controllers/EnvironmentController.cs +++ b/Jellyfin.Api/Controllers/EnvironmentController.cs @@ -104,7 +104,7 @@ namespace Jellyfin.Api.Controllers if (validatePathDto.ValidateWritable) { - if (validatePathDto.Path == null) + if (validatePathDto.Path is null) { throw new ResourceNotFoundException(nameof(validatePathDto.Path)); } diff --git a/Jellyfin.Api/Controllers/FilterController.cs b/Jellyfin.Api/Controllers/FilterController.cs index 11808b1b8..b6780ee20 100644 --- a/Jellyfin.Api/Controllers/FilterController.cs +++ b/Jellyfin.Api/Controllers/FilterController.cs @@ -182,7 +182,7 @@ namespace Jellyfin.Api.Controllers if ((recursive ?? true) || parentItem is UserView || parentItem is ICollectionFolder) { - genreQuery.AncestorIds = parentItem == null ? Array.Empty<Guid>() : new[] { parentItem.Id }; + genreQuery.AncestorIds = parentItem is null ? Array.Empty<Guid>() : new[] { parentItem.Id }; } else { diff --git a/Jellyfin.Api/Controllers/HlsSegmentController.cs b/Jellyfin.Api/Controllers/HlsSegmentController.cs index 78634f0bf..50fee233a 100644 --- a/Jellyfin.Api/Controllers/HlsSegmentController.cs +++ b/Jellyfin.Api/Controllers/HlsSegmentController.cs @@ -167,7 +167,7 @@ namespace Jellyfin.Api.Controllers } } - return playlistPath == null + return playlistPath is null ? NotFound("Hls segment not found.") : GetFileResult(file, playlistPath); } @@ -178,7 +178,7 @@ namespace Jellyfin.Api.Controllers Response.OnCompleted(() => { - if (transcodingJob != null) + if (transcodingJob is not null) { _transcodingJobHelper.OnTranscodeEndRequest(transcodingJob); } diff --git a/Jellyfin.Api/Controllers/ImageByNameController.cs b/Jellyfin.Api/Controllers/ImageByNameController.cs index 89bbf22c9..c54851b96 100644 --- a/Jellyfin.Api/Controllers/ImageByNameController.cs +++ b/Jellyfin.Api/Controllers/ImageByNameController.cs @@ -77,7 +77,7 @@ namespace Jellyfin.Api.Controllers .Select(i => Path.GetFullPath(Path.Combine(_applicationPaths.GeneralPath, name, filename + i))) .FirstOrDefault(System.IO.File.Exists); - if (path == null) + if (path is null) { return NotFound(); } diff --git a/Jellyfin.Api/Controllers/ImageController.cs b/Jellyfin.Api/Controllers/ImageController.cs index f092bd882..49342ad5c 100644 --- a/Jellyfin.Api/Controllers/ImageController.cs +++ b/Jellyfin.Api/Controllers/ImageController.cs @@ -28,6 +28,7 @@ using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Primitives; using Microsoft.Net.Http.Headers; namespace Jellyfin.Api.Controllers @@ -110,7 +111,7 @@ namespace Jellyfin.Api.Controllers // Handle image/png; charset=utf-8 var mimeType = Request.ContentType?.Split(';').FirstOrDefault(); var userDataPath = Path.Combine(_serverConfigurationManager.ApplicationPaths.UserConfigurationDirectoryPath, user.Username); - if (user.ProfileImage != null) + if (user.ProfileImage is not null) { await _userManager.ClearProfileImageAsync(user).ConfigureAwait(false); } @@ -157,7 +158,7 @@ namespace Jellyfin.Api.Controllers // Handle image/png; charset=utf-8 var mimeType = Request.ContentType?.Split(';').FirstOrDefault(); var userDataPath = Path.Combine(_serverConfigurationManager.ApplicationPaths.UserConfigurationDirectoryPath, user.Username); - if (user.ProfileImage != null) + if (user.ProfileImage is not null) { await _userManager.ClearProfileImageAsync(user).ConfigureAwait(false); } @@ -198,7 +199,7 @@ namespace Jellyfin.Api.Controllers } var user = _userManager.GetUserById(userId); - if (user?.ProfileImage == null) + if (user?.ProfileImage is null) { return NoContent(); } @@ -242,7 +243,7 @@ namespace Jellyfin.Api.Controllers } var user = _userManager.GetUserById(userId); - if (user?.ProfileImage == null) + if (user?.ProfileImage is null) { return NoContent(); } @@ -279,7 +280,7 @@ namespace Jellyfin.Api.Controllers [FromQuery] int? imageIndex) { var item = _libraryManager.GetItemById(itemId); - if (item == null) + if (item is null) { return NotFound(); } @@ -307,7 +308,7 @@ namespace Jellyfin.Api.Controllers [FromRoute] int imageIndex) { var item = _libraryManager.GetItemById(itemId); - if (item == null) + if (item is null) { return NotFound(); } @@ -335,7 +336,7 @@ namespace Jellyfin.Api.Controllers [FromRoute, Required] ImageType imageType) { var item = _libraryManager.GetItemById(itemId); - if (item == null) + if (item is null) { return NotFound(); } @@ -371,7 +372,7 @@ namespace Jellyfin.Api.Controllers [FromRoute] int imageIndex) { var item = _libraryManager.GetItemById(itemId); - if (item == null) + if (item is null) { return NotFound(); } @@ -407,7 +408,7 @@ namespace Jellyfin.Api.Controllers [FromQuery, Required] int newIndex) { var item = _libraryManager.GetItemById(itemId); - if (item == null) + if (item is null) { return NotFound(); } @@ -430,7 +431,7 @@ namespace Jellyfin.Api.Controllers public async Task<ActionResult<IEnumerable<ImageInfo>>> GetItemImageInfos([FromRoute, Required] Guid itemId) { var item = _libraryManager.GetItemById(itemId); - if (item == null) + if (item is null) { return NotFound(); } @@ -452,7 +453,7 @@ namespace Jellyfin.Api.Controllers { var info = GetImageInfo(item, image, null); - if (info != null) + if (info is not null) { list.Add(info); } @@ -470,7 +471,7 @@ namespace Jellyfin.Api.Controllers { var info = GetImageInfo(item, image, index); - if (info != null) + if (info is not null) { list.Add(info); } @@ -537,7 +538,7 @@ namespace Jellyfin.Api.Controllers [FromQuery] int? imageIndex) { var item = _libraryManager.GetItemById(itemId); - if (item == null) + if (item is null) { return NotFound(); } @@ -620,7 +621,7 @@ namespace Jellyfin.Api.Controllers [FromQuery] string? foregroundLayer) { var item = _libraryManager.GetItemById(itemId); - if (item == null) + if (item is null) { return NotFound(); } @@ -703,7 +704,7 @@ namespace Jellyfin.Api.Controllers [FromRoute, Required] int imageIndex) { var item = _libraryManager.GetItemById(itemId); - if (item == null) + if (item is null) { return NotFound(); } @@ -786,7 +787,7 @@ namespace Jellyfin.Api.Controllers [FromRoute, Required] int imageIndex) { var item = _libraryManager.GetArtist(name); - if (item == null) + if (item is null) { return NotFound(); } @@ -869,7 +870,7 @@ namespace Jellyfin.Api.Controllers [FromQuery] int? imageIndex) { var item = _libraryManager.GetGenre(name); - if (item == null) + if (item is null) { return NotFound(); } @@ -952,7 +953,7 @@ namespace Jellyfin.Api.Controllers [FromQuery] string? foregroundLayer) { var item = _libraryManager.GetGenre(name); - if (item == null) + if (item is null) { return NotFound(); } @@ -1035,7 +1036,7 @@ namespace Jellyfin.Api.Controllers [FromQuery] int? imageIndex) { var item = _libraryManager.GetMusicGenre(name); - if (item == null) + if (item is null) { return NotFound(); } @@ -1118,7 +1119,7 @@ namespace Jellyfin.Api.Controllers [FromQuery] string? foregroundLayer) { var item = _libraryManager.GetMusicGenre(name); - if (item == null) + if (item is null) { return NotFound(); } @@ -1201,7 +1202,7 @@ namespace Jellyfin.Api.Controllers [FromQuery] int? imageIndex) { var item = _libraryManager.GetPerson(name); - if (item == null) + if (item is null) { return NotFound(); } @@ -1284,7 +1285,7 @@ namespace Jellyfin.Api.Controllers [FromQuery] string? foregroundLayer) { var item = _libraryManager.GetPerson(name); - if (item == null) + if (item is null) { return NotFound(); } @@ -1367,7 +1368,7 @@ namespace Jellyfin.Api.Controllers [FromQuery] int? imageIndex) { var item = _libraryManager.GetStudio(name); - if (item == null) + if (item is null) { return NotFound(); } @@ -1450,7 +1451,7 @@ namespace Jellyfin.Api.Controllers [FromQuery] string? foregroundLayer) { var item = _libraryManager.GetStudio(name); - if (item == null) + if (item is null) { return NotFound(); } @@ -1533,7 +1534,7 @@ namespace Jellyfin.Api.Controllers [FromQuery] int? imageIndex) { var user = _userManager.GetUserById(userId); - if (user?.ProfileImage == null) + if (user?.ProfileImage is null) { return NotFound(); } @@ -1634,7 +1635,7 @@ namespace Jellyfin.Api.Controllers [FromQuery] string? foregroundLayer) { var user = _userManager.GetUserById(userId); - if (user?.ProfileImage == null) + if (user?.ProfileImage is null) { return NotFound(); } @@ -1944,10 +1945,10 @@ namespace Jellyfin.Api.Controllers unplayedCount = null; } - if (imageInfo == null) + if (imageInfo is null) { imageInfo = item?.GetImageInfo(imageType, imageIndex ?? 0); - if (imageInfo == null) + if (imageInfo is null) { return NotFound(string.Format(NumberFormatInfo.InvariantInfo, "{0} does not have an image of type {1}", item?.Name, imageType)); } @@ -1968,7 +1969,7 @@ namespace Jellyfin.Api.Controllers { "realTimeInfo.dlna.org", "DLNA.ORG_TLAG=*" } }; - if (!imageInfo.IsLocalFile && item != null) + if (!imageInfo.IsLocalFile && item is not null) { imageInfo = await _libraryManager.ConvertImageToLocal(item, imageInfo, imageIndex ?? 0).ConfigureAwait(false); } @@ -2026,8 +2027,13 @@ namespace Jellyfin.Api.Controllers } var acceptParam = Request.Query[HeaderNames.Accept]; + if (StringValues.IsNullOrEmpty(acceptParam)) + { + return Array.Empty<ImageFormat>(); + } - var supportsWebP = SupportsFormat(supportedFormats, acceptParam, ImageFormat.Webp, false); + // Can't be null, checked above + var supportsWebP = SupportsFormat(supportedFormats, acceptParam!, ImageFormat.Webp, false); if (!supportsWebP) { @@ -2049,7 +2055,8 @@ namespace Jellyfin.Api.Controllers formats.Add(ImageFormat.Jpg); formats.Add(ImageFormat.Png); - if (SupportsFormat(supportedFormats, acceptParam, ImageFormat.Gif, true)) + // Can't be null, checked above + if (SupportsFormat(supportedFormats, acceptParam!, ImageFormat.Gif, true)) { formats.Add(ImageFormat.Gif); } diff --git a/Jellyfin.Api/Controllers/ItemLookupController.cs b/Jellyfin.Api/Controllers/ItemLookupController.cs index c49f85616..34893d682 100644 --- a/Jellyfin.Api/Controllers/ItemLookupController.cs +++ b/Jellyfin.Api/Controllers/ItemLookupController.cs @@ -65,7 +65,7 @@ namespace Jellyfin.Api.Controllers public ActionResult<IEnumerable<ExternalIdInfo>> GetExternalIdInfos([FromRoute, Required] Guid itemId) { var item = _libraryManager.GetItemById(itemId); - if (item == null) + if (item is null) { return NotFound(); } diff --git a/Jellyfin.Api/Controllers/ItemRefreshController.cs b/Jellyfin.Api/Controllers/ItemRefreshController.cs index 9340737b5..0dc3fbd05 100644 --- a/Jellyfin.Api/Controllers/ItemRefreshController.cs +++ b/Jellyfin.Api/Controllers/ItemRefreshController.cs @@ -61,7 +61,7 @@ namespace Jellyfin.Api.Controllers [FromQuery] bool replaceAllImages = false) { var item = _libraryManager.GetItemById(itemId); - if (item == null) + if (item is null) { return NotFound(); } diff --git a/Jellyfin.Api/Controllers/ItemUpdateController.cs b/Jellyfin.Api/Controllers/ItemUpdateController.cs index fd137f98f..af3d779f5 100644 --- a/Jellyfin.Api/Controllers/ItemUpdateController.cs +++ b/Jellyfin.Api/Controllers/ItemUpdateController.cs @@ -71,7 +71,7 @@ namespace Jellyfin.Api.Controllers public async Task<ActionResult> UpdateItem([FromRoute, Required] Guid itemId, [FromBody, Required] BaseItemDto request) { var item = _libraryManager.GetItemById(itemId); - if (item == null) + if (item is null) { return NotFound(); } @@ -80,13 +80,13 @@ namespace Jellyfin.Api.Controllers var isLockedChanged = item.IsLocked != newLockData; var series = item as Series; - var displayOrderChanged = series != null && !string.Equals( + var displayOrderChanged = series is not null && !string.Equals( series.DisplayOrder ?? string.Empty, request.DisplayOrder ?? string.Empty, StringComparison.OrdinalIgnoreCase); // Do this first so that metadata savers can pull the updates from the database. - if (request.People != null) + if (request.People is not null) { _libraryManager.UpdatePeople( item, @@ -198,7 +198,7 @@ namespace Jellyfin.Api.Controllers public ActionResult UpdateItemContentType([FromRoute, Required] Guid itemId, [FromQuery] string? contentType) { var item = _libraryManager.GetItemById(itemId); - if (item == null) + if (item is null) { return NotFound(); } @@ -248,12 +248,12 @@ namespace Jellyfin.Api.Controllers item.Tags = request.Tags; - if (request.Taglines != null) + if (request.Taglines is not null) { item.Tagline = request.Taglines.FirstOrDefault(); } - if (request.Studios != null) + if (request.Studios is not null) { item.Studios = request.Studios.Select(x => x.Name).ToArray(); } @@ -269,7 +269,7 @@ namespace Jellyfin.Api.Controllers item.OfficialRating = string.IsNullOrWhiteSpace(request.OfficialRating) ? null : request.OfficialRating; item.CustomRating = request.CustomRating; - if (request.ProductionLocations != null) + if (request.ProductionLocations is not null) { item.ProductionLocations = request.ProductionLocations; } @@ -289,7 +289,7 @@ namespace Jellyfin.Api.Controllers item.IsLocked = request.LockData ?? false; - if (request.LockedFields != null) + if (request.LockedFields is not null) { item.LockedFields = request.LockedFields; } @@ -315,7 +315,7 @@ namespace Jellyfin.Api.Controllers video.Video3DFormat = request.Video3DFormat; } - if (request.AlbumArtists != null) + if (request.AlbumArtists is not null) { if (item is IHasAlbumArtist hasAlbumArtists) { @@ -326,7 +326,7 @@ namespace Jellyfin.Api.Controllers } } - if (request.ArtistItems != null) + if (request.ArtistItems is not null) { if (item is IHasArtist hasArtists) { @@ -349,7 +349,7 @@ namespace Jellyfin.Api.Controllers { series.Status = GetSeriesStatus(request); - if (request.AirDays != null) + if (request.AirDays is not null) { series.AirDays = request.AirDays; series.AirTime = request.AirTime; diff --git a/Jellyfin.Api/Controllers/ItemsController.cs b/Jellyfin.Api/Controllers/ItemsController.cs index 3ee5b8d73..717ddc32b 100644 --- a/Jellyfin.Api/Controllers/ItemsController.cs +++ b/Jellyfin.Api/Controllers/ItemsController.cs @@ -447,7 +447,7 @@ namespace Jellyfin.Api.Controllers { return null; } - }).Where(i => i != null).Select(i => i!.Id).ToArray(); + }).Where(i => i is not null).Select(i => i!.Id).ToArray(); } // ExcludeArtistIds @@ -483,7 +483,7 @@ namespace Jellyfin.Api.Controllers { return null; } - }).Where(i => i != null).Select(i => i!.Id).ToArray(); + }).Where(i => i is not null).Select(i => i!.Id).ToArray(); } // Apply default sorting if none requested @@ -837,7 +837,7 @@ namespace Jellyfin.Api.Controllers if (excludeActiveSessions) { excludeItemIds = _sessionManager.Sessions - .Where(s => s.UserId.Equals(userId) && s.NowPlayingItem != null) + .Where(s => s.UserId.Equals(userId) && s.NowPlayingItem is not null) .Select(s => s.NowPlayingItem.Id) .ToArray(); } diff --git a/Jellyfin.Api/Controllers/LibraryController.cs b/Jellyfin.Api/Controllers/LibraryController.cs index 7a57bf1a2..ab2020830 100644 --- a/Jellyfin.Api/Controllers/LibraryController.cs +++ b/Jellyfin.Api/Controllers/LibraryController.cs @@ -104,7 +104,7 @@ namespace Jellyfin.Api.Controllers public ActionResult GetFile([FromRoute, Required] Guid itemId) { var item = _libraryManager.GetItemById(itemId); - if (item == null) + if (item is null) { return NotFound(); } @@ -154,7 +154,7 @@ namespace Jellyfin.Api.Controllers : _libraryManager.GetUserRootFolder()) : _libraryManager.GetItemById(itemId); - if (item == null) + if (item is null) { return NotFound("Item not found."); } @@ -171,7 +171,7 @@ namespace Jellyfin.Api.Controllers } var parent = item.GetParent(); - if (parent == null) + if (parent is null) { break; } @@ -220,7 +220,7 @@ namespace Jellyfin.Api.Controllers : _libraryManager.GetUserRootFolder()) : _libraryManager.GetItemById(itemId); - if (item == null) + if (item is null) { return NotFound("Item not found."); } @@ -237,7 +237,7 @@ namespace Jellyfin.Api.Controllers } var parent = item.GetParent(); - if (parent == null) + if (parent is null) { break; } @@ -435,7 +435,7 @@ namespace Jellyfin.Api.Controllers { var item = _libraryManager.GetItemById(itemId); - if (item == null) + if (item is null) { return NotFound("Item not found"); } @@ -449,9 +449,9 @@ namespace Jellyfin.Api.Controllers var dtoOptions = new DtoOptions().AddClientFields(User); BaseItem? parent = item.GetParent(); - while (parent != null) + while (parent is not null) { - if (user != null) + if (user is not null) { parent = TranslateParentItem(parent, user); } @@ -610,14 +610,14 @@ namespace Jellyfin.Api.Controllers public async Task<ActionResult> GetDownload([FromRoute, Required] Guid itemId) { var item = _libraryManager.GetItemById(itemId); - if (item == null) + if (item is null) { return NotFound(); } var user = _userManager.GetUserById(User.GetUserId()); - if (user != null) + if (user is not null) { if (!item.CanDownload(user)) { @@ -632,27 +632,15 @@ namespace Jellyfin.Api.Controllers } } - if (user != null) + if (user is not null) { await LogDownloadAsync(item, user).ConfigureAwait(false); } - var path = item.Path; + // Quotes are valid in linux. They'll possibly cause issues here. + var filename = Path.GetFileName(item.Path)?.Replace("\"", string.Empty, StringComparison.Ordinal); - // Quotes are valid in linux. They'll possibly cause issues here - var filename = (Path.GetFileName(path) ?? string.Empty).Replace("\"", string.Empty, StringComparison.Ordinal); - if (!string.IsNullOrWhiteSpace(filename)) - { - // Kestrel doesn't support non-ASCII characters in headers - if (Regex.IsMatch(filename, @"[^\p{IsBasicLatin}]")) - { - // Manually encoding non-ASCII characters, following https://tools.ietf.org/html/rfc5987#section-3.2.2 - filename = WebUtility.UrlEncode(filename); - } - } - - // TODO determine non-ASCII validity. - return PhysicalFile(path, MimeTypes.GetMimeType(path), filename, true); + return PhysicalFile(item.Path, MimeTypes.GetMimeType(item.Path), filename, true); } /// <summary> @@ -698,8 +686,8 @@ namespace Jellyfin.Api.Controllers .AddClientFields(User); var program = item as IHasProgramAttributes; - bool? isMovie = item is Movie || (program != null && program.IsMovie) || item is Trailer; - bool? isSeries = item is Series || (program != null && program.IsSeries); + bool? isMovie = item is Movie || (program is not null && program.IsMovie) || item is Trailer; + bool? isSeries = item is Series || (program is not null && program.IsSeries); var includeItemTypes = new List<BaseItemKind>(); if (isMovie.Value) diff --git a/Jellyfin.Api/Controllers/LibraryStructureController.cs b/Jellyfin.Api/Controllers/LibraryStructureController.cs index ec1170411..1c2394055 100644 --- a/Jellyfin.Api/Controllers/LibraryStructureController.cs +++ b/Jellyfin.Api/Controllers/LibraryStructureController.cs @@ -82,7 +82,7 @@ namespace Jellyfin.Api.Controllers { var libraryOptions = libraryOptionsDto?.LibraryOptions ?? new LibraryOptions(); - if (paths != null && paths.Length > 0) + if (paths is not null && paths.Length > 0) { libraryOptions.PathInfos = paths.Select(i => new MediaPathInfo(i)).ToArray(); } diff --git a/Jellyfin.Api/Controllers/LiveTvController.cs b/Jellyfin.Api/Controllers/LiveTvController.cs index 394df0f58..94710d78f 100644 --- a/Jellyfin.Api/Controllers/LiveTvController.cs +++ b/Jellyfin.Api/Controllers/LiveTvController.cs @@ -763,7 +763,7 @@ namespace Jellyfin.Api.Controllers await AssertUserCanManageLiveTv().ConfigureAwait(false); var item = _libraryManager.GetItemById(recordingId); - if (item == null) + if (item is null) { return NotFound(); } @@ -840,7 +840,7 @@ namespace Jellyfin.Api.Controllers public async Task<ActionResult<SeriesTimerInfoDto>> GetSeriesTimer([FromRoute, Required] string timerId) { var timer = await _liveTvManager.GetSeriesTimer(timerId, CancellationToken.None).ConfigureAwait(false); - if (timer == null) + if (timer is null) { return NotFound(); } @@ -1201,7 +1201,7 @@ namespace Jellyfin.Api.Controllers public ActionResult GetLiveStreamFile([FromRoute, Required] string streamId, [FromRoute, Required] string container) { var liveStreamInfo = _mediaSourceManager.GetLiveStreamInfoByUniqueId(streamId); - if (liveStreamInfo == null) + if (liveStreamInfo is null) { return NotFound(); } diff --git a/Jellyfin.Api/Controllers/MediaInfoController.cs b/Jellyfin.Api/Controllers/MediaInfoController.cs index c111e9218..8115c3585 100644 --- a/Jellyfin.Api/Controllers/MediaInfoController.cs +++ b/Jellyfin.Api/Controllers/MediaInfoController.cs @@ -121,10 +121,10 @@ namespace Jellyfin.Api.Controllers var profile = playbackInfoDto?.DeviceProfile; _logger.LogDebug("GetPostedPlaybackInfo profile: {@Profile}", profile); - if (profile == null) + if (profile is null) { var caps = _deviceManager.GetCapabilities(User.GetDeviceId()); - if (caps != null) + if (caps is not null) { profile = caps.DeviceProfile; } @@ -154,12 +154,12 @@ namespace Jellyfin.Api.Controllers liveStreamId) .ConfigureAwait(false); - if (info.ErrorCode != null) + if (info.ErrorCode is not null) { return info; } - if (profile != null) + if (profile is not null) { // set device specific data var item = _libraryManager.GetItemById(itemId); @@ -194,7 +194,7 @@ namespace Jellyfin.Api.Controllers { var mediaSource = string.IsNullOrWhiteSpace(mediaSourceId) ? info.MediaSources[0] : info.MediaSources.FirstOrDefault(i => string.Equals(i.Id, mediaSourceId, StringComparison.Ordinal)); - if (mediaSource != null && mediaSource.RequiresOpening && string.IsNullOrWhiteSpace(mediaSource.LiveStreamId)) + if (mediaSource is not null && mediaSource.RequiresOpening && string.IsNullOrWhiteSpace(mediaSource.LiveStreamId)) { var openStreamResult = await _mediaInfoHelper.OpenMediaSource( HttpContext, diff --git a/Jellyfin.Api/Controllers/PackageController.cs b/Jellyfin.Api/Controllers/PackageController.cs index 9690aead0..0aa7c2ac9 100644 --- a/Jellyfin.Api/Controllers/PackageController.cs +++ b/Jellyfin.Api/Controllers/PackageController.cs @@ -54,7 +54,7 @@ namespace Jellyfin.Api.Controllers assemblyGuid ?? default) .FirstOrDefault(); - if (result == null) + if (result is null) { return NotFound(); } @@ -110,7 +110,7 @@ namespace Jellyfin.Api.Controllers specificVersion: string.IsNullOrEmpty(version) ? null : Version.Parse(version)) .FirstOrDefault(); - if (package == null) + if (package is null) { return NotFound(); } diff --git a/Jellyfin.Api/Controllers/PersonsController.cs b/Jellyfin.Api/Controllers/PersonsController.cs index 42be969b2..09f7281ec 100644 --- a/Jellyfin.Api/Controllers/PersonsController.cs +++ b/Jellyfin.Api/Controllers/PersonsController.cs @@ -122,7 +122,7 @@ namespace Jellyfin.Api.Controllers .AddClientFields(User); var item = _libraryManager.GetPerson(name); - if (item == null) + if (item is null) { return NotFound(); } diff --git a/Jellyfin.Api/Controllers/PlaylistsController.cs b/Jellyfin.Api/Controllers/PlaylistsController.cs index fb045f891..e0c565da1 100644 --- a/Jellyfin.Api/Controllers/PlaylistsController.cs +++ b/Jellyfin.Api/Controllers/PlaylistsController.cs @@ -176,7 +176,7 @@ namespace Jellyfin.Api.Controllers [FromQuery, ModelBinder(typeof(CommaDelimitedArrayModelBinder))] ImageType[] enableImageTypes) { var playlist = (Playlist)_libraryManager.GetItemById(playlistId); - if (playlist == null) + if (playlist is null) { return NotFound(); } diff --git a/Jellyfin.Api/Controllers/PlaystateController.cs b/Jellyfin.Api/Controllers/PlaystateController.cs index 3a2ba033e..58f9b7d35 100644 --- a/Jellyfin.Api/Controllers/PlaystateController.cs +++ b/Jellyfin.Api/Controllers/PlaystateController.cs @@ -353,7 +353,7 @@ namespace Jellyfin.Api.Controllers if (method == PlayMethod.Transcode) { var job = string.IsNullOrWhiteSpace(playSessionId) ? null : _transcodingJobHelper.GetTranscodingJob(playSessionId); - if (job == null) + if (job is null) { return PlayMethod.DirectPlay; } diff --git a/Jellyfin.Api/Controllers/PluginsController.cs b/Jellyfin.Api/Controllers/PluginsController.cs index b227dba2d..6a729b237 100644 --- a/Jellyfin.Api/Controllers/PluginsController.cs +++ b/Jellyfin.Api/Controllers/PluginsController.cs @@ -71,7 +71,7 @@ namespace Jellyfin.Api.Controllers public ActionResult EnablePlugin([FromRoute, Required] Guid pluginId, [FromRoute, Required] Version version) { var plugin = _pluginManager.GetPlugin(pluginId, version); - if (plugin == null) + if (plugin is null) { return NotFound(); } @@ -95,7 +95,7 @@ namespace Jellyfin.Api.Controllers public ActionResult DisablePlugin([FromRoute, Required] Guid pluginId, [FromRoute, Required] Version version) { var plugin = _pluginManager.GetPlugin(pluginId, version); - if (plugin == null) + if (plugin is null) { return NotFound(); } @@ -119,7 +119,7 @@ namespace Jellyfin.Api.Controllers public ActionResult UninstallPluginByVersion([FromRoute, Required] Guid pluginId, [FromRoute, Required] Version version) { var plugin = _pluginManager.GetPlugin(pluginId, version); - if (plugin == null) + if (plugin is null) { return NotFound(); } @@ -146,9 +146,9 @@ namespace Jellyfin.Api.Controllers var plugins = _pluginManager.Plugins.Where(p => p.Id.Equals(pluginId)); // Select the un-instanced one first. - var plugin = plugins.FirstOrDefault(p => p.Instance == null) ?? plugins.OrderBy(p => p.Manifest.Status).FirstOrDefault(); + var plugin = plugins.FirstOrDefault(p => p.Instance is null) ?? plugins.OrderBy(p => p.Manifest.Status).FirstOrDefault(); - if (plugin != null) + if (plugin is not null) { _installationManager.UninstallPlugin(plugin); return NoContent(); @@ -202,7 +202,7 @@ namespace Jellyfin.Api.Controllers var configuration = (BasePluginConfiguration?)await JsonSerializer.DeserializeAsync(Request.Body, configPlugin.ConfigurationType, _serializerOptions) .ConfigureAwait(false); - if (configuration != null) + if (configuration is not null) { configPlugin.UpdateConfiguration(configuration); } @@ -225,13 +225,13 @@ namespace Jellyfin.Api.Controllers public ActionResult GetPluginImage([FromRoute, Required] Guid pluginId, [FromRoute, Required] Version version) { var plugin = _pluginManager.GetPlugin(pluginId, version); - if (plugin == null) + if (plugin is null) { return NotFound(); } var imagePath = Path.Combine(plugin.Path, plugin.Manifest.ImagePath ?? string.Empty); - if (plugin.Manifest.ImagePath == null || !System.IO.File.Exists(imagePath)) + if (plugin.Manifest.ImagePath is null || !System.IO.File.Exists(imagePath)) { return NotFound(); } @@ -254,7 +254,7 @@ namespace Jellyfin.Api.Controllers { var plugin = _pluginManager.GetPlugin(pluginId); - if (plugin != null) + if (plugin is not null) { return plugin.Manifest; } diff --git a/Jellyfin.Api/Controllers/RemoteImageController.cs b/Jellyfin.Api/Controllers/RemoteImageController.cs index dbee56e14..da9e8cf90 100644 --- a/Jellyfin.Api/Controllers/RemoteImageController.cs +++ b/Jellyfin.Api/Controllers/RemoteImageController.cs @@ -68,7 +68,7 @@ namespace Jellyfin.Api.Controllers [FromQuery] bool includeAllLanguages = false) { var item = _libraryManager.GetItemById(itemId); - if (item == null) + if (item is null) { return NotFound(); } @@ -127,7 +127,7 @@ namespace Jellyfin.Api.Controllers public ActionResult<IEnumerable<ImageProviderInfo>> GetRemoteImageProviders([FromRoute, Required] Guid itemId) { var item = _libraryManager.GetItemById(itemId); - if (item == null) + if (item is null) { return NotFound(); } @@ -154,7 +154,7 @@ namespace Jellyfin.Api.Controllers [FromQuery] string? imageUrl) { var item = _libraryManager.GetItemById(itemId); - if (item == null) + if (item is null) { return NotFound(); } diff --git a/Jellyfin.Api/Controllers/ScheduledTasksController.cs b/Jellyfin.Api/Controllers/ScheduledTasksController.cs index 68e4f0586..832e14505 100644 --- a/Jellyfin.Api/Controllers/ScheduledTasksController.cs +++ b/Jellyfin.Api/Controllers/ScheduledTasksController.cs @@ -76,7 +76,7 @@ namespace Jellyfin.Api.Controllers var task = _taskManager.ScheduledTasks.FirstOrDefault(i => string.Equals(i.Id, taskId, StringComparison.OrdinalIgnoreCase)); - if (task == null) + if (task is null) { return NotFound(); } @@ -99,7 +99,7 @@ namespace Jellyfin.Api.Controllers var task = _taskManager.ScheduledTasks.FirstOrDefault(o => o.Id.Equals(taskId, StringComparison.OrdinalIgnoreCase)); - if (task == null) + if (task is null) { return NotFound(); } @@ -123,7 +123,7 @@ namespace Jellyfin.Api.Controllers var task = _taskManager.ScheduledTasks.FirstOrDefault(o => o.Id.Equals(taskId, StringComparison.OrdinalIgnoreCase)); - if (task == null) + if (task is null) { return NotFound(); } @@ -149,7 +149,7 @@ namespace Jellyfin.Api.Controllers { var task = _taskManager.ScheduledTasks.FirstOrDefault(o => o.Id.Equals(taskId, StringComparison.OrdinalIgnoreCase)); - if (task == null) + if (task is null) { return NotFound(); } diff --git a/Jellyfin.Api/Controllers/SearchController.cs b/Jellyfin.Api/Controllers/SearchController.cs index aeed0c0d6..3b7719f37 100644 --- a/Jellyfin.Api/Controllers/SearchController.cs +++ b/Jellyfin.Api/Controllers/SearchController.cs @@ -161,7 +161,7 @@ namespace Jellyfin.Api.Controllers var primaryImageTag = _imageProcessor.GetImageCacheTag(item, ImageType.Primary); - if (primaryImageTag != null) + if (primaryImageTag is not null) { result.PrimaryImageTag = primaryImageTag; result.PrimaryImageAspectRatio = _dtoService.GetPrimaryImageAspectRatio(item); @@ -195,7 +195,7 @@ namespace Jellyfin.Api.Controllers MusicAlbum musicAlbum = song.AlbumEntity; - if (musicAlbum != null) + if (musicAlbum is not null) { result.Album = musicAlbum.Name; result.AlbumId = musicAlbum.Id; @@ -221,18 +221,18 @@ namespace Jellyfin.Api.Controllers { var itemWithImage = item.HasImage(ImageType.Thumb) ? item : null; - if (itemWithImage == null && item is Episode) + if (itemWithImage is null && item is Episode) { itemWithImage = GetParentWithImage<Series>(item, ImageType.Thumb); } itemWithImage ??= GetParentWithImage<BaseItem>(item, ImageType.Thumb); - if (itemWithImage != null) + if (itemWithImage is not null) { var tag = _imageProcessor.GetImageCacheTag(itemWithImage, ImageType.Thumb); - if (tag != null) + if (tag is not null) { hint.ThumbImageTag = tag; hint.ThumbImageItemId = itemWithImage.Id.ToString("N", CultureInfo.InvariantCulture); @@ -245,11 +245,11 @@ namespace Jellyfin.Api.Controllers var itemWithImage = (item.HasImage(ImageType.Backdrop) ? item : null) ?? GetParentWithImage<BaseItem>(item, ImageType.Backdrop); - if (itemWithImage != null) + if (itemWithImage is not null) { var tag = _imageProcessor.GetImageCacheTag(itemWithImage, ImageType.Backdrop); - if (tag != null) + if (tag is not null) { hint.BackdropImageTag = tag; hint.BackdropImageItemId = itemWithImage.Id.ToString("N", CultureInfo.InvariantCulture); diff --git a/Jellyfin.Api/Controllers/SessionController.cs b/Jellyfin.Api/Controllers/SessionController.cs index 31b95162d..25f930135 100644 --- a/Jellyfin.Api/Controllers/SessionController.cs +++ b/Jellyfin.Api/Controllers/SessionController.cs @@ -294,10 +294,7 @@ namespace Jellyfin.Api.Controllers { var currentSession = await RequestHelpers.GetSession(_sessionManager, _userManager, HttpContext).ConfigureAwait(false); - if (command == null) - { - throw new ArgumentException("Request body may not be null"); - } + ArgumentNullException.ThrowIfNull(command); command.ControllingUserId = currentSession.UserId; diff --git a/Jellyfin.Api/Controllers/StartupController.cs b/Jellyfin.Api/Controllers/StartupController.cs index c49bde93f..eec5779e6 100644 --- a/Jellyfin.Api/Controllers/StartupController.cs +++ b/Jellyfin.Api/Controllers/StartupController.cs @@ -132,7 +132,7 @@ namespace Jellyfin.Api.Controllers { var user = _userManager.Users.First(); - if (startupUserDto.Name != null) + if (startupUserDto.Name is not null) { user.Username = startupUserDto.Name; } diff --git a/Jellyfin.Api/Controllers/SubtitleController.cs b/Jellyfin.Api/Controllers/SubtitleController.cs index 1258a9876..ff9bd095b 100644 --- a/Jellyfin.Api/Controllers/SubtitleController.cs +++ b/Jellyfin.Api/Controllers/SubtitleController.cs @@ -96,7 +96,7 @@ namespace Jellyfin.Api.Controllers { var item = _libraryManager.GetItemById(itemId); - if (item == null) + if (item is null) { return NotFound(); } @@ -522,7 +522,7 @@ namespace Jellyfin.Api.Controllers .First(i => string.Equals(i.Name, name, StringComparison.OrdinalIgnoreCase)); var fileSize = fontFile?.Length; - if (fontFile != null && fileSize != null && fileSize > 0) + if (fontFile is not null && fileSize is not null && fileSize > 0) { _logger.LogDebug("Fallback font size is {FileSize} Bytes", fileSize); return PhysicalFile(fontFile.FullName, MimeTypes.GetMimeType(fontFile.FullName)); diff --git a/Jellyfin.Api/Controllers/TvShowsController.cs b/Jellyfin.Api/Controllers/TvShowsController.cs index ea13ceb91..7f4f4d077 100644 --- a/Jellyfin.Api/Controllers/TvShowsController.cs +++ b/Jellyfin.Api/Controllers/TvShowsController.cs @@ -247,7 +247,7 @@ namespace Jellyfin.Api.Controllers .GetSeasons(user, dtoOptions) .FirstOrDefault(i => i.IndexNumber == season.Value); - episodes = seasonItem == null ? + episodes = seasonItem is null ? new List<BaseItem>() : ((Season)seasonItem).GetEpisodes(user, dtoOptions); } diff --git a/Jellyfin.Api/Controllers/UserController.cs b/Jellyfin.Api/Controllers/UserController.cs index ff653fe6b..002327d74 100644 --- a/Jellyfin.Api/Controllers/UserController.cs +++ b/Jellyfin.Api/Controllers/UserController.cs @@ -124,7 +124,7 @@ namespace Jellyfin.Api.Controllers { var user = _userManager.GetUserById(userId); - if (user == null) + if (user is null) { return NotFound("User not found"); } @@ -173,7 +173,7 @@ namespace Jellyfin.Api.Controllers { var user = _userManager.GetUserById(userId); - if (user == null) + if (user is null) { return NotFound("User not found"); } @@ -272,7 +272,7 @@ namespace Jellyfin.Api.Controllers var user = _userManager.GetUserById(userId); - if (user == null) + if (user is null) { return NotFound("User not found"); } @@ -292,7 +292,7 @@ namespace Jellyfin.Api.Controllers HttpContext.GetNormalizedRemoteIp().ToString(), false).ConfigureAwait(false); - if (success == null) + if (success is null) { return StatusCode(StatusCodes.Status403Forbidden, "Invalid user or password entered."); } @@ -333,7 +333,7 @@ namespace Jellyfin.Api.Controllers var user = _userManager.GetUserById(userId); - if (user == null) + if (user is null) { return NotFound("User not found"); } @@ -477,7 +477,7 @@ namespace Jellyfin.Api.Controllers var newUser = await _userManager.CreateUserAsync(request.Name).ConfigureAwait(false); // no need to authenticate password for new user - if (request.Password != null) + if (request.Password is not null) { await _userManager.ChangePassword(newUser, request.Password).ConfigureAwait(false); } @@ -544,7 +544,7 @@ namespace Jellyfin.Api.Controllers } var user = _userManager.GetUserById(userId); - if (user == null) + if (user is null) { return BadRequest(); } diff --git a/Jellyfin.Api/Controllers/UserLibraryController.cs b/Jellyfin.Api/Controllers/UserLibraryController.cs index 8a2d5a27d..c18fa29af 100644 --- a/Jellyfin.Api/Controllers/UserLibraryController.cs +++ b/Jellyfin.Api/Controllers/UserLibraryController.cs @@ -306,7 +306,7 @@ namespace Jellyfin.Api.Controllers var item = i.Item2[0]; var childCount = 0; - if (i.Item1 != null && (i.Item2.Count > 1 || i.Item1 is MusicAlbum)) + if (i.Item1 is not null && (i.Item2.Count > 1 || i.Item1 is MusicAlbum)) { item = i.Item1; childCount = i.Item2.Count; @@ -402,7 +402,7 @@ namespace Jellyfin.Api.Controllers { var user = _userManager.GetUserById(userId); - if (user == null) + if (user is null) { return NotFound(); } @@ -411,7 +411,7 @@ namespace Jellyfin.Api.Controllers ? _libraryManager.GetUserRootFolder() : _libraryManager.GetItemById(itemId); - if (item == null) + if (item is null) { return NotFound(); } diff --git a/Jellyfin.Api/Controllers/UserViewsController.cs b/Jellyfin.Api/Controllers/UserViewsController.cs index 85d154cac..3aeb444df 100644 --- a/Jellyfin.Api/Controllers/UserViewsController.cs +++ b/Jellyfin.Api/Controllers/UserViewsController.cs @@ -117,7 +117,7 @@ namespace Jellyfin.Api.Controllers public ActionResult<IEnumerable<SpecialViewOptionDto>> GetGroupingOptions([FromRoute, Required] Guid userId) { var user = _userManager.GetUserById(userId); - if (user == null) + if (user is null) { return NotFound(); } diff --git a/Jellyfin.Api/Controllers/VideoAttachmentsController.cs b/Jellyfin.Api/Controllers/VideoAttachmentsController.cs index c2bb0dfff..bb3162614 100644 --- a/Jellyfin.Api/Controllers/VideoAttachmentsController.cs +++ b/Jellyfin.Api/Controllers/VideoAttachmentsController.cs @@ -55,7 +55,7 @@ namespace Jellyfin.Api.Controllers try { var item = _libraryManager.GetItemById(videoId); - if (item == null) + if (item is null) { return NotFound(); } diff --git a/Jellyfin.Api/Controllers/VideosController.cs b/Jellyfin.Api/Controllers/VideosController.cs index bf08ad376..64d8fb498 100644 --- a/Jellyfin.Api/Controllers/VideosController.cs +++ b/Jellyfin.Api/Controllers/VideosController.cs @@ -149,7 +149,7 @@ namespace Jellyfin.Api.Controllers { var video = (Video)_libraryManager.GetItemById(itemId); - if (video == null) + if (video is null) { return NotFound("The video either does not exist or the id does not belong to a video."); } @@ -199,7 +199,7 @@ namespace Jellyfin.Api.Controllers } var primaryVersion = items.FirstOrDefault(i => i.MediaSourceCount > 1 && string.IsNullOrEmpty(i.PrimaryVersionId)); - if (primaryVersion == null) + if (primaryVersion is null) { primaryVersion = items .OrderBy(i => @@ -439,12 +439,12 @@ namespace Jellyfin.Api.Controllers cancellationTokenSource.Token) .ConfigureAwait(false); - if (@static.HasValue && @static.Value && state.DirectStreamProvider != null) + if (@static.HasValue && @static.Value && state.DirectStreamProvider is not null) { StreamingHelpers.AddDlnaHeaders(state, Response.Headers, true, state.Request.StartTimeTicks, Request, _dlnaManager); var liveStreamInfo = _mediaSourceManager.GetLiveStreamInfo(streamingRequest.LiveStreamId); - if (liveStreamInfo == null) + if (liveStreamInfo is null) { return NotFound(); } @@ -472,7 +472,7 @@ namespace Jellyfin.Api.Controllers var outputPathExists = System.IO.File.Exists(outputPath); var transcodingJob = _transcodingJobHelper.GetTranscodingJob(outputPath, TranscodingJobType.Progressive); - var isTranscodeCached = outputPathExists && transcodingJob != null; + var isTranscodeCached = outputPathExists && transcodingJob is not null; StreamingHelpers.AddDlnaHeaders(state, Response.Headers, (@static.HasValue && @static.Value) || isTranscodeCached, state.Request.StartTimeTicks, Request, _dlnaManager); diff --git a/Jellyfin.Api/Controllers/YearsController.cs b/Jellyfin.Api/Controllers/YearsController.cs index b732bdff3..cd85ba221 100644 --- a/Jellyfin.Api/Controllers/YearsController.cs +++ b/Jellyfin.Api/Controllers/YearsController.cs @@ -152,7 +152,7 @@ namespace Jellyfin.Api.Controllers var result = new QueryResult<BaseItemDto>( startIndex, ibnItemsArray.Count, - dtos.Where(i => i != null).ToArray()); + dtos.Where(i => i is not null).ToArray()); return result; } @@ -173,7 +173,7 @@ namespace Jellyfin.Api.Controllers public ActionResult<BaseItemDto> GetYear([FromRoute, Required] int year, [FromQuery] Guid? userId) { var item = _libraryManager.GetYear(year); - if (item == null) + if (item is null) { return NotFound(); } |
