From 7d9d54d2ecad14eaec14b00ca73c479d4d64c34f Mon Sep 17 00:00:00 2001 From: Patrick Barron Date: Wed, 20 May 2020 12:09:52 -0400 Subject: [PATCH] Fix profile images. --- Jellyfin.Data/Entities/ImageInfo.cs | 12 +++--------- .../Migrations/Routines/MigrateUserDb.cs | 2 +- MediaBrowser.Api/Images/ImageService.cs | 13 ++++++++++++- MediaBrowser.Controller/Drawing/ImageHelper.cs | 1 + MediaBrowser.Model/Entities/ImageType.cs | 7 ++++++- 5 files changed, 23 insertions(+), 12 deletions(-) diff --git a/Jellyfin.Data/Entities/ImageInfo.cs b/Jellyfin.Data/Entities/ImageInfo.cs index 6593695450..8bbce95e4b 100644 --- a/Jellyfin.Data/Entities/ImageInfo.cs +++ b/Jellyfin.Data/Entities/ImageInfo.cs @@ -6,11 +6,9 @@ namespace Jellyfin.Data.Entities { public class ImageInfo { - public ImageInfo(string path, int width, int height) + public ImageInfo(string path) { Path = path; - Width = width; - Height = height; LastModified = DateTime.UtcNow; } @@ -20,14 +18,10 @@ namespace Jellyfin.Data.Entities public int Id { get; protected set; } [Required] + [MaxLength(512)] + [StringLength(512)] public string Path { get; set; } - [Required] - public int Width { get; set; } - - [Required] - public int Height { get; set; } - [Required] public DateTime LastModified { get; set; } } diff --git a/Jellyfin.Server/Migrations/Routines/MigrateUserDb.cs b/Jellyfin.Server/Migrations/Routines/MigrateUserDb.cs index 987c85f4c3..a1895247f2 100644 --- a/Jellyfin.Server/Migrations/Routines/MigrateUserDb.cs +++ b/Jellyfin.Server/Migrations/Routines/MigrateUserDb.cs @@ -118,7 +118,7 @@ namespace Jellyfin.Server.Migrations.Routines { ItemImageInfo info = mockup.ImageInfos[0]; - user.ProfileImage = new ImageInfo(info.Path, info.Width, info.Height) + user.ProfileImage = new ImageInfo(info.Path) { LastModified = info.DateModified }; diff --git a/MediaBrowser.Api/Images/ImageService.cs b/MediaBrowser.Api/Images/ImageService.cs index 1392184df4..149c4cb9bf 100644 --- a/MediaBrowser.Api/Images/ImageService.cs +++ b/MediaBrowser.Api/Images/ImageService.cs @@ -471,8 +471,17 @@ namespace MediaBrowser.Api.Images AssertCanUpdateUser(_authContext, _userManager, userId, true); var user = _userManager.GetUserById(userId); + try + { + File.Delete(user.ProfileImage.Path); + } + catch (IOException e) + { + // TODO: Log this + } user.ProfileImage = null; + _userManager.UpdateUser(user); } /// @@ -639,6 +648,7 @@ namespace MediaBrowser.Api.Images IDictionary headers, bool isHeadRequest) { + info.Type = ImageType.Profile; var options = new ImageProcessingOptions { CropWhiteSpace = true, @@ -886,9 +896,10 @@ namespace MediaBrowser.Api.Images // Handle image/png; charset=utf-8 mimeType = mimeType.Split(';').FirstOrDefault(); var userDataPath = Path.Combine(ServerConfigurationManager.ApplicationPaths.UserConfigurationDirectoryPath, user.Username); + user.ProfileImage = new Jellyfin.Data.Entities.ImageInfo(Path.Combine(userDataPath, "profile" + MimeTypes.ToExtension(mimeType))); await _providerManager - .SaveImage(user, memoryStream, mimeType, Path.Combine(userDataPath, "profile" + MimeTypes.ToExtension(mimeType))) + .SaveImage(user, memoryStream, mimeType, user.ProfileImage.Path) .ConfigureAwait(false); await _userManager.UpdateUserAsync(user); } diff --git a/MediaBrowser.Controller/Drawing/ImageHelper.cs b/MediaBrowser.Controller/Drawing/ImageHelper.cs index d5a5f547ea..c87a248b58 100644 --- a/MediaBrowser.Controller/Drawing/ImageHelper.cs +++ b/MediaBrowser.Controller/Drawing/ImageHelper.cs @@ -57,6 +57,7 @@ namespace MediaBrowser.Controller.Drawing case ImageType.BoxRear: case ImageType.Disc: case ImageType.Menu: + case ImageType.Profile: return 1; case ImageType.Logo: return 2.58; diff --git a/MediaBrowser.Model/Entities/ImageType.cs b/MediaBrowser.Model/Entities/ImageType.cs index d89a4b3adb..6ea9ee419e 100644 --- a/MediaBrowser.Model/Entities/ImageType.cs +++ b/MediaBrowser.Model/Entities/ImageType.cs @@ -63,6 +63,11 @@ namespace MediaBrowser.Model.Entities /// /// The box rear. /// - BoxRear = 11 + BoxRear = 11, + + /// + /// The user profile image. + /// + Profile = 12 } }