Răsfoiți Sursa

Fix issues and add profile image support

Patrick Barron 5 ani în urmă
părinte
comite
1d1a145ad4

+ 11 - 2
Jellyfin.Data/Entities/ImageInfo.cs

@@ -1,24 +1,33 @@
 using System;
 using System.ComponentModel.DataAnnotations;
+using System.ComponentModel.DataAnnotations.Schema;
 
 namespace Jellyfin.Data.Entities
 {
     public class ImageInfo
     {
-        public ImageInfo(string path)
+        public ImageInfo(string path, int width, int height)
         {
             Path = path;
+            Width = width;
+            Height = height;
             LastModified = DateTime.UtcNow;
         }
 
         [Key]
         [Required]
-
+        [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
         public int Id { get; protected set; }
 
         [Required]
         public string Path { get; set; }
 
+        [Required]
+        public int Width { get; set; }
+
+        [Required]
+        public int Height { get; set; }
+
         [Required]
         public DateTime LastModified { get; set; }
     }

+ 10 - 8
Jellyfin.Data/Entities/Permission.cs

@@ -12,14 +12,7 @@ namespace Jellyfin.Data.Entities
         partial void Init();
 
         /// <summary>
-        /// Default constructor. Protected due to required properties, but present because EF needs it.
-        /// </summary>
-        protected Permission()
-        {
-            Init();
-        }
-
-        /// <summary>
+        /// Initializes a new instance of the <see cref="Permission"/> class.
         /// Public constructor with required data
         /// </summary>
         /// <param name="kind"></param>
@@ -33,6 +26,15 @@ namespace Jellyfin.Data.Entities
             Init();
         }
 
+        /// <summary>
+        /// Initializes a new instance of the <see cref="Permission"/> class.
+        /// Default constructor. Protected due to required properties, but present because EF needs it.
+        /// </summary>
+        protected Permission()
+        {
+            Init();
+        }
+
         /// <summary>
         /// Static create function (for use in LINQ queries, etc.)
         /// </summary>

+ 5 - 3
Jellyfin.Data/Entities/User.cs

@@ -25,7 +25,7 @@ namespace Jellyfin.Data.Entities
         /// </summary>
         /// <param name="username">The username for the new user.</param>
         /// <param name="authenticationProviderId">The authentication provider's Id</param>
-        public User(string username, string authenticationProviderId)
+        public User(string username, string authenticationProviderId, string passwordResetProviderId)
         {
             if (string.IsNullOrEmpty(username))
             {
@@ -39,6 +39,7 @@ namespace Jellyfin.Data.Entities
 
             Username = username;
             AuthenticationProviderId = authenticationProviderId;
+            PasswordResetProviderId = passwordResetProviderId;
 
             Groups = new HashSet<Group>();
             Permissions = new HashSet<Permission>();
@@ -85,10 +86,11 @@ namespace Jellyfin.Data.Entities
         /// </summary>
         /// <param name="username">The username for the created user.</param>
         /// <param name="authenticationProviderId">The Id of the user's authentication provider.</param>
+        /// <param name="passwordResetProviderId">The Id of the user's password reset provider.</param>
         /// <returns>The created instance.</returns>
-        public static User Create(string username, string authenticationProviderId)
+        public static User Create(string username, string authenticationProviderId, string passwordResetProviderId)
         {
-            return new User(username, authenticationProviderId);
+            return new User(username, authenticationProviderId, passwordResetProviderId);
         }
 
         /*************************************************************************

+ 4 - 1
Jellyfin.Server.Implementations/Users/UserManager.cs

@@ -190,7 +190,10 @@ namespace Jellyfin.Server.Implementations.Users
 
             var dbContext = _dbProvider.CreateContext();
 
-            var newUser = new User(name, _defaultAuthenticationProvider.GetType().FullName);
+            var newUser = new User(
+                name,
+                _defaultAuthenticationProvider.GetType().FullName,
+                _defaultPasswordResetProvider.GetType().FullName);
             dbContext.Users.Add(newUser);
             dbContext.SaveChanges();
 

+ 15 - 2
Jellyfin.Server/Migrations/Routines/MigrateUserDb.cs

@@ -7,6 +7,7 @@ using Jellyfin.Data.Enums;
 using Jellyfin.Server.Implementations;
 using Jellyfin.Server.Implementations.Users;
 using MediaBrowser.Controller;
+using MediaBrowser.Controller.Entities;
 using MediaBrowser.Model.Configuration;
 using MediaBrowser.Model.Users;
 using Microsoft.Extensions.Logging;
@@ -84,9 +85,9 @@ namespace Jellyfin.Server.Migrations.Routines
                         StringComparison.Ordinal)
                         ?? typeof(DefaultAuthenticationProvider).FullName;
 
-                    policy.PasswordResetProviderId ??= typeof(DefaultPasswordResetProvider).FullName;
+                    policy.PasswordResetProviderId = typeof(DefaultPasswordResetProvider).FullName;
 
-                    var user = new User(mockup.Name, policy.AuthenticationProviderId)
+                    var user = new User(mockup.Name, policy.AuthenticationProviderId, string.Empty)
                     {
                         Id = entry[1].ReadGuidFromBlob(),
                         InternalId = entry[0].ToInt64(),
@@ -113,6 +114,16 @@ namespace Jellyfin.Server.Migrations.Routines
                         LastActivityDate = mockup.LastActivityDate ?? DateTime.MinValue
                     };
 
+                    if (mockup.ImageInfos.Length > 0)
+                    {
+                        ItemImageInfo info = mockup.ImageInfos[0];
+
+                        user.ProfileImage = new ImageInfo(info.Path, info.Width, info.Height)
+                        {
+                            LastModified = info.DateModified
+                        };
+                    }
+
                     user.SetPermission(PermissionKind.IsAdministrator, policy.IsAdministrator);
                     user.SetPermission(PermissionKind.IsHidden, policy.IsHidden);
                     user.SetPermission(PermissionKind.IsDisabled, policy.IsDisabled);
@@ -184,6 +195,8 @@ namespace Jellyfin.Server.Migrations.Routines
             public DateTime? LastActivityDate { get; set; }
 
             public string Name { get; set; }
+
+            public ItemImageInfo[] ImageInfos { get; set; }
         }
     }
 }

+ 2 - 1
MediaBrowser.Api/Images/ImageService.cs

@@ -17,6 +17,7 @@ using MediaBrowser.Model.Drawing;
 using MediaBrowser.Model.Dto;
 using MediaBrowser.Model.Entities;
 using MediaBrowser.Model.IO;
+using MediaBrowser.Model.Net;
 using MediaBrowser.Model.Services;
 using Microsoft.Extensions.Logging;
 using Microsoft.Net.Http.Headers;
@@ -887,7 +888,7 @@ namespace MediaBrowser.Api.Images
             var userDataPath = Path.Combine(ServerConfigurationManager.ApplicationPaths.UserConfigurationDirectoryPath, user.Username);
 
             await _providerManager
-                .SaveImage(user, memoryStream, mimeType, Path.Combine(userDataPath, _imageProcessor.GetImageCacheTag(user)))
+                .SaveImage(user, memoryStream, mimeType, Path.Combine(userDataPath, "profile" + MimeTypes.ToExtension(mimeType)))
                 .ConfigureAwait(false);
             await _userManager.UpdateUserAsync(user);
         }

+ 2 - 7
MediaBrowser.Providers/Manager/ImageSaver.cs

@@ -131,7 +131,7 @@ namespace MediaBrowser.Providers.Manager
 
             var currentImage = GetCurrentImage(item, type, index);
             var currentImageIsLocalFile = currentImage != null && currentImage.IsLocalFile;
-            var currentImagePath = currentImage == null ? null : currentImage.Path;
+            var currentImagePath = currentImage?.Path;
 
             var savedPaths = new List<string>();
 
@@ -179,13 +179,8 @@ namespace MediaBrowser.Providers.Manager
             }
         }
 
-        public async Task SaveImage(User user, Stream source, string mimeType, string path)
+        public async Task SaveImage(User user, Stream source, string path)
         {
-            if (string.IsNullOrEmpty(mimeType))
-            {
-                throw new ArgumentNullException(nameof(mimeType));
-            }
-
             await SaveImageToLocation(source, path, path, CancellationToken.None).ConfigureAwait(false);
         }
 

+ 1 - 1
MediaBrowser.Providers/Manager/ProviderManager.cs

@@ -191,7 +191,7 @@ namespace MediaBrowser.Providers.Manager
         public Task SaveImage(User user, Stream source, string mimeType, string path)
         {
             return new ImageSaver(_configurationManager, _libraryMonitor, _fileSystem, _logger)
-                .SaveImage(user, source, mimeType, path);
+                .SaveImage(user, source, path);
         }
 
         public async Task<IEnumerable<RemoteImageInfo>> GetAvailableRemoteImages(BaseItem item, RemoteImageQuery query, CancellationToken cancellationToken)