diff --git a/back/src/Directory.Build.props b/back/src/Directory.Build.props index a3c3d9d6..1d56c929 100644 --- a/back/src/Directory.Build.props +++ b/back/src/Directory.Build.props @@ -1,7 +1,7 @@ net7.0 - default + preview Kyoo Kyoo Copyright (c) Kyoo diff --git a/back/src/Kyoo.Abstractions/Models/Exceptions/ItemNotFoundException.cs b/back/src/Kyoo.Abstractions/Models/Exceptions/ItemNotFoundException.cs index f8a79486..0fd5825f 100644 --- a/back/src/Kyoo.Abstractions/Models/Exceptions/ItemNotFoundException.cs +++ b/back/src/Kyoo.Abstractions/Models/Exceptions/ItemNotFoundException.cs @@ -30,7 +30,8 @@ namespace Kyoo.Abstractions.Models.Exceptions /// /// Create a default with no message. /// - public ItemNotFoundException() { } + public ItemNotFoundException() + : base("Item not found") { } /// /// Create a new with a message diff --git a/back/src/Kyoo.Core/Controllers/ThumbnailsManager.cs b/back/src/Kyoo.Core/Controllers/ThumbnailsManager.cs index fe0bda25..c1cbd727 100644 --- a/back/src/Kyoo.Core/Controllers/ThumbnailsManager.cs +++ b/back/src/Kyoo.Core/Controllers/ThumbnailsManager.cs @@ -219,17 +219,18 @@ namespace Kyoo.Core.Controllers try { await using FileStream img = File.Open( - $"/metadata/user/${userId}.webp", + $"/metadata/user/{userId}.webp", FileMode.Open ); return img; } catch (FileNotFoundException) { } + catch (DirectoryNotFoundException) { } User user = await users.Value.Get(userId); if (user.Email == null) throw new ItemNotFoundException(); using MD5 md5 = MD5.Create(); - string hash = Convert.ToHexString(md5.ComputeHash(Encoding.ASCII.GetBytes(user.Email))); + string hash = Convert.ToHexString(md5.ComputeHash(Encoding.ASCII.GetBytes(user.Email))).ToLower(); try { HttpClient client = clientFactory.CreateClient(); @@ -250,7 +251,8 @@ namespace Kyoo.Core.Controllers info.ColorType = SKColorType.Rgba8888; using SKBitmap original = SKBitmap.Decode(codec, info); using SKBitmap ret = original.Resize(new SKSizeI(250, 250), SKFilterQuality.High); - await _WriteTo(ret, $"/metadata/user/${userId}.webp", 75); + Directory.CreateDirectory("/metadata/user"); + await _WriteTo(ret, $"/metadata/user/{userId}.webp", 75); } } } diff --git a/back/src/Kyoo.Core/ExceptionFilter.cs b/back/src/Kyoo.Core/ExceptionFilter.cs index 98101283..cc625641 100644 --- a/back/src/Kyoo.Core/ExceptionFilter.cs +++ b/back/src/Kyoo.Core/ExceptionFilter.cs @@ -30,19 +30,12 @@ namespace Kyoo.Core /// /// A middleware to handle errors globally. /// - public class ExceptionFilter : IExceptionFilter + /// + /// Initializes a new instance of the class. + /// + /// The logger used to log errors. + public class ExceptionFilter(ILogger logger) : IExceptionFilter { - private readonly ILogger _logger; - - /// - /// Initializes a new instance of the class. - /// - /// The logger used to log errors. - public ExceptionFilter(ILogger logger) - { - _logger = logger; - } - /// public void OnException(ExceptionContext context) { @@ -65,7 +58,7 @@ namespace Kyoo.Core context.Result = new UnauthorizedObjectResult(new RequestError(ex.Message)); break; case Exception ex: - _logger.LogError(ex, "Unhandled error"); + logger.LogError(ex, "Unhandled error"); context.Result = new ServerErrorObjectResult( new RequestError("Internal Server Error") );