The Free Software Media System - Server Backend & API
Updated based on review feedback
crobibero73d2cb1c2a3a
diff --git a/Emby.Server.Implementations/AppBase/ConfigurationHelper.cs b/Emby.Server.Implementations/AppBase/ConfigurationHelper.csindex 6c425c7fb4..77819c7649 100644--- a/Emby.Server.Implementations/AppBase/ConfigurationHelper.cs+++ b/Emby.Server.Implementations/AppBase/ConfigurationHelper.cs@@ -36,7 +36,7 @@ namespace Emby.Server.Implementations.AppBase}catch (Exception){- configuration = Activator.CreateInstance(type) ?? throw new ResourceNotFoundException(nameof(type));+ configuration = Activator.CreateInstance(type) ?? throw new ArgumentException($"Provided path ({type}) is not valid.", nameof(type));}using var stream = new MemoryStream(buffer?.Length ?? 0);@@ -49,7 +49,7 @@ namespace Emby.Server.Implementations.AppBase// If the file didn't exist before, or if something has changed, re-saveif (buffer == null || !newBytes.AsSpan(0, newBytesLen).SequenceEqual(buffer)){- var directory = Path.GetDirectoryName(path) ?? throw new ResourceNotFoundException(nameof(path));+ var directory = Path.GetDirectoryName(path) ?? throw new ArgumentException($"Provided path ({path}) is not valid.", nameof(path));Directory.CreateDirectory(directory);// Save it after load in case we got new itemsdiff --git a/Emby.Server.Implementations/Cryptography/CryptographyProvider.cs b/Emby.Server.Implementations/Cryptography/CryptographyProvider.csindex 42db183963..12a9e44e70 100644--- a/Emby.Server.Implementations/Cryptography/CryptographyProvider.cs+++ b/Emby.Server.Implementations/Cryptography/CryptographyProvider.cs@@ -81,7 +81,7 @@ namespace Emby.Server.Implementations.Cryptographythrow new CryptographicException($"Requested hash method is not supported: {hashMethod}");}- using var h = HashAlgorithm.Create(hashMethod) ?? throw new ResourceNotFoundException(nameof(hashMethod));+ using var h = HashAlgorithm.Create(hashMethod) ?? throw new ResourceNotFoundException($"Unknown hash method: {hashMethod}.");if (salt.Length == 0){return h.ComputeHash(bytes);diff --git a/Emby.Server.Implementations/Session/WebSocketController.cs b/Emby.Server.Implementations/Session/WebSocketController.csindex 5268ea1b93..f9c6a13c69 100644--- a/Emby.Server.Implementations/Session/WebSocketController.cs+++ b/Emby.Server.Implementations/Session/WebSocketController.cs@@ -58,7 +58,7 @@ namespace Emby.Server.Implementations.Sessionprivate void OnConnectionClosed(object? sender, EventArgs e){- var connection = sender as IWebSocketConnection ?? throw new ResourceNotFoundException(nameof(sender));+ var connection = sender as IWebSocketConnection ?? throw new ArgumentException($"{nameof(sender)} is not of type {nameof(IWebSocketConnection)}", nameof(sender));_logger.LogDebug("Removing websocket from session {Session}", _session.Id);_sockets.Remove(connection);connection.Closed -= OnConnectionClosed;diff --git a/Jellyfin.Api/Controllers/DynamicHlsController.cs b/Jellyfin.Api/Controllers/DynamicHlsController.csindex 783deebdce..6e59da798c 100644--- a/Jellyfin.Api/Controllers/DynamicHlsController.cs+++ b/Jellyfin.Api/Controllers/DynamicHlsController.cs@@ -1348,7 +1348,7 @@ namespace Jellyfin.Api.Controllersvar mapArgs = state.IsOutputVideo ? _encodingHelper.GetMapArgs(state) : string.Empty;- var directory = Path.GetDirectoryName(outputPath) ?? throw new ResourceNotFoundException(nameof(outputPath));+ var directory = Path.GetDirectoryName(outputPath) ?? throw new ArgumentException($"Provided path ({outputPath}) is not valid.", nameof(outputPath));var outputTsArg = Path.Combine(directory, Path.GetFileNameWithoutExtension(outputPath)) + "%d" + GetSegmentFileExtension(state.Request.SegmentContainer);@@ -1568,7 +1568,7 @@ namespace Jellyfin.Api.Controllersprivate string GetSegmentPath(StreamState state, string playlist, int index){- var folder = Path.GetDirectoryName(playlist) ?? throw new ResourceNotFoundException(nameof(playlist));+ var folder = Path.GetDirectoryName(playlist) ?? throw new ArgumentException($"Provided path ({playlist}) is not valid.", nameof(playlist));var filename = Path.GetFileNameWithoutExtension(playlist);return Path.Combine(folder, filename + index.ToString(CultureInfo.InvariantCulture) + GetSegmentFileExtension(state.Request.SegmentContainer));diff --git a/Jellyfin.Api/Controllers/HlsSegmentController.cs b/Jellyfin.Api/Controllers/HlsSegmentController.csindex b9adcd3806..3b75e8d431 100644--- a/Jellyfin.Api/Controllers/HlsSegmentController.cs+++ b/Jellyfin.Api/Controllers/HlsSegmentController.cs@@ -136,7 +136,7 @@ namespace Jellyfin.Api.Controllers.FirstOrDefault(i =>string.Equals(Path.GetExtension(i), ".m3u8", StringComparison.OrdinalIgnoreCase)&& i.IndexOf(normalizedPlaylistId, StringComparison.OrdinalIgnoreCase) != -1)- ?? throw new ResourceNotFoundException(nameof(transcodeFolderPath));+ ?? throw new ResourceNotFoundException($"Provided path ({transcodeFolderPath}) is not valid.");return GetFileResult(file, playlistPath);}diff --git a/Jellyfin.Api/Controllers/ItemLookupController.cs b/Jellyfin.Api/Controllers/ItemLookupController.csindex a0d9bfb543..a7c1a63882 100644--- a/Jellyfin.Api/Controllers/ItemLookupController.cs+++ b/Jellyfin.Api/Controllers/ItemLookupController.cs@@ -342,7 +342,7 @@ namespace Jellyfin.Api.Controllersvar ext = result.Content.Headers.ContentType.MediaType.Split('/')[^1];var fullCachePath = GetFullCachePath(urlHash + "." + ext);- var directory = Path.GetDirectoryName(fullCachePath) ?? throw new ResourceNotFoundException(nameof(fullCachePath));+ var directory = Path.GetDirectoryName(fullCachePath) ?? throw new ResourceNotFoundException($"Provided path ({fullCachePath}) is not valid.");Directory.CreateDirectory(directory);using (var stream = result.Content){@@ -357,7 +357,7 @@ namespace Jellyfin.Api.Controllersawait stream.CopyToAsync(fileStream).ConfigureAwait(false);}- var pointerCacheDirectory = Path.GetDirectoryName(pointerCachePath) ?? throw new ResourceNotFoundException(nameof(pointerCachePath));+ var pointerCacheDirectory = Path.GetDirectoryName(pointerCachePath) ?? throw new ArgumentException($"Provided path ({pointerCachePath}) is not valid.", nameof(pointerCachePath));Directory.CreateDirectory(pointerCacheDirectory);await System.IO.File.WriteAllTextAsync(pointerCachePath, fullCachePath).ConfigureAwait(false);diff --git a/Jellyfin.Api/Controllers/RemoteImageController.cs b/Jellyfin.Api/Controllers/RemoteImageController.csindex b4a9e5582d..c2bfab175a 100644--- a/Jellyfin.Api/Controllers/RemoteImageController.cs+++ b/Jellyfin.Api/Controllers/RemoteImageController.cs@@ -257,12 +257,12 @@ namespace Jellyfin.Api.Controllersvar ext = response.Content.Headers.ContentType.MediaType.Split('/').Last();var fullCachePath = GetFullCachePath(urlHash + "." + ext);- var fullCacheDirectory = Path.GetDirectoryName(fullCachePath) ?? throw new ResourceNotFoundException(nameof(fullCachePath));+ var fullCacheDirectory = Path.GetDirectoryName(fullCachePath) ?? throw new ResourceNotFoundException($"Provided path ({fullCachePath}) is not valid.");Directory.CreateDirectory(fullCacheDirectory);await using var fileStream = new FileStream(fullCachePath, FileMode.Create, FileAccess.Write, FileShare.Read, IODefaults.FileStreamBufferSize, true);await response.Content.CopyToAsync(fileStream).ConfigureAwait(false);- var pointerCacheDirectory = Path.GetDirectoryName(pointerCachePath) ?? throw new ResourceNotFoundException(nameof(pointerCachePath));+ var pointerCacheDirectory = Path.GetDirectoryName(pointerCachePath) ?? throw new ArgumentException($"Provided path ({pointerCachePath}) is not valid.", nameof(pointerCachePath));Directory.CreateDirectory(pointerCacheDirectory);await System.IO.File.WriteAllTextAsync(pointerCachePath, fullCachePath, CancellationToken.None).ConfigureAwait(false);diff --git a/Jellyfin.Api/Controllers/VideoHlsController.cs b/Jellyfin.Api/Controllers/VideoHlsController.csindex cc538f15e2..389dc8a088 100644--- a/Jellyfin.Api/Controllers/VideoHlsController.cs+++ b/Jellyfin.Api/Controllers/VideoHlsController.cs@@ -362,7 +362,7 @@ namespace Jellyfin.Api.Controllersvar threads = _encodingHelper.GetNumberOfThreads(state, _encodingOptions, videoCodec);var inputModifier = _encodingHelper.GetInputModifier(state, _encodingOptions);var format = !string.IsNullOrWhiteSpace(state.Request.SegmentContainer) ? "." + state.Request.SegmentContainer : ".ts";- var directory = Path.GetDirectoryName(outputPath) ?? throw new ResourceNotFoundException(nameof(outputPath));+ var directory = Path.GetDirectoryName(outputPath) ?? throw new ArgumentException($"Provided path ({outputPath}) is not valid.", nameof(outputPath));var outputTsArg = Path.Combine(directory, Path.GetFileNameWithoutExtension(outputPath)) + "%d" + format;var segmentFormat = format.TrimStart('.');diff --git a/Jellyfin.Api/Helpers/HlsHelpers.cs b/Jellyfin.Api/Helpers/HlsHelpers.csindex bcf0da319c..7fd784806e 100644--- a/Jellyfin.Api/Helpers/HlsHelpers.cs+++ b/Jellyfin.Api/Helpers/HlsHelpers.cs@@ -3,7 +3,6 @@ using System.Globalization;using System.IO;using System.Threading;using System.Threading.Tasks;-using MediaBrowser.Common.Extensions;using MediaBrowser.Model.IO;using Microsoft.Extensions.Logging;@@ -45,8 +44,12 @@ namespace Jellyfin.Api.Helperswhile (!reader.EndOfStream){- var line = await reader.ReadLineAsync().ConfigureAwait(false)- ?? throw new ResourceNotFoundException(nameof(reader));+ var line = await reader.ReadLineAsync().ConfigureAwait(false);+ if (line == null)+ {+ // Nothing currently in buffer.+ continue;+ }if (line.IndexOf("#EXTINF:", StringComparison.OrdinalIgnoreCase) != -1){diff --git a/Jellyfin.Api/Helpers/TranscodingJobHelper.cs b/Jellyfin.Api/Helpers/TranscodingJobHelper.csindex 8466241838..168dc27a83 100644--- a/Jellyfin.Api/Helpers/TranscodingJobHelper.cs+++ b/Jellyfin.Api/Helpers/TranscodingJobHelper.cs@@ -196,7 +196,7 @@ namespace Jellyfin.Api.Helpers/// <param name="state">The state.</param>private async void OnTranscodeKillTimerStopped(object? state){- var job = state as TranscodingJobDto ?? throw new ResourceNotFoundException(nameof(state));+ var job = state as TranscodingJobDto ?? throw new ArgumentException($"{nameof(state)} is not of type {nameof(TranscodingJobDto)}", nameof(state));if (!job.HasExited && job.Type != TranscodingJobType.Progressive){var timeSinceLastPing = (DateTime.UtcNow - job.LastPingDate).TotalMilliseconds;@@ -489,7 +489,7 @@ namespace Jellyfin.Api.HelpersCancellationTokenSource cancellationTokenSource,string? workingDirectory = null){- var directory = Path.GetDirectoryName(outputPath) ?? throw new ResourceNotFoundException(nameof(outputPath));+ var directory = Path.GetDirectoryName(outputPath) ?? throw new ArgumentException($"Provided path ({outputPath}) is not valid.", nameof(outputPath));Directory.CreateDirectory(directory);await AcquireResources(state, cancellationTokenSource).ConfigureAwait(false);diff --git a/Jellyfin.Drawing.Skia/SkiaEncoder.cs b/Jellyfin.Drawing.Skia/SkiaEncoder.csindex 0c90d04a75..ee60748c71 100644--- a/Jellyfin.Drawing.Skia/SkiaEncoder.cs+++ b/Jellyfin.Drawing.Skia/SkiaEncoder.cs@@ -228,7 +228,7 @@ namespace Jellyfin.Drawing.Skia}var tempPath = Path.Combine(_appPaths.TempDirectory, Guid.NewGuid() + Path.GetExtension(path));- var directory = Path.GetDirectoryName(tempPath) ?? throw new ResourceNotFoundException(nameof(tempPath));+ var directory = Path.GetDirectoryName(tempPath) ?? throw new ResourceNotFoundException($"Provided path ({tempPath}) is not valid.");Directory.CreateDirectory(directory);File.Copy(path, tempPath, true);@@ -494,7 +494,7 @@ namespace Jellyfin.Drawing.Skia// If all we're doing is resizing then we can stop nowif (!hasBackgroundColor && !hasForegroundColor && blur == 0 && !hasIndicator){- var outputDirectory = Path.GetDirectoryName(outputPath) ?? throw new ResourceNotFoundException(nameof(outputPath));+ var outputDirectory = Path.GetDirectoryName(outputPath) ?? throw new ArgumentException($"Provided path ({outputPath}) is not valid.", nameof(outputPath));Directory.CreateDirectory(outputDirectory);using var outputStream = new SKFileWStream(outputPath);using var pixmap = new SKPixmap(new SKImageInfo(width, height), resizedBitmap.GetPixels());@@ -542,7 +542,7 @@ namespace Jellyfin.Drawing.SkiaDrawIndicator(canvas, width, height, options);}- var directory = Path.GetDirectoryName(outputPath) ?? throw new ResourceNotFoundException(nameof(outputPath));+ var directory = Path.GetDirectoryName(outputPath) ?? throw new ArgumentException($"Provided path ({outputPath}) is not valid.", nameof(outputPath));Directory.CreateDirectory(directory);using (var outputStream = new SKFileWStream(outputPath)){diff --git a/Jellyfin.Server.Implementations/Users/DefaultPasswordResetProvider.cs b/Jellyfin.Server.Implementations/Users/DefaultPasswordResetProvider.csindex 7f24904049..e71d419e0c 100644--- a/Jellyfin.Server.Implementations/Users/DefaultPasswordResetProvider.cs+++ b/Jellyfin.Server.Implementations/Users/DefaultPasswordResetProvider.cs@@ -58,7 +58,7 @@ namespace Jellyfin.Server.Implementations.Usersawait using (var str = File.OpenRead(resetFile)){spr = await JsonSerializer.DeserializeAsync<SerializablePasswordReset>(str).ConfigureAwait(false)- ?? throw new ResourceNotFoundException(nameof(spr));+ ?? throw new ResourceNotFoundException($"Provided path ({resetFile}) is not valid.");}if (spr.ExpirationDate < DateTime.UtcNow)diff --git a/MediaBrowser.LocalMetadata/Savers/BaseXmlSaver.cs b/MediaBrowser.LocalMetadata/Savers/BaseXmlSaver.csindex 2c9c9ccaa1..396206658d 100644--- a/MediaBrowser.LocalMetadata/Savers/BaseXmlSaver.cs+++ b/MediaBrowser.LocalMetadata/Savers/BaseXmlSaver.cs@@ -128,7 +128,7 @@ namespace MediaBrowser.LocalMetadata.Saversprivate void SaveToFile(Stream stream, string path){- var directory = Path.GetDirectoryName(path) ?? throw new ResourceNotFoundException(nameof(path));+ var directory = Path.GetDirectoryName(path) ?? throw new ArgumentException($"Provided path ({path}) is not valid.", nameof(path));Directory.CreateDirectory(directory);// On Windows, savint the file will fail if the file is hidden or readonlyFileSystem.SetAttributes(path, false, false);