Fix profile images.

pull/3423/head
Patrick Barron 4 years ago
parent 623dcde65c
commit 7d9d54d2ec

@ -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; }
}

@ -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
};

@ -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);
}
/// <summary>
@ -639,6 +648,7 @@ namespace MediaBrowser.Api.Images
IDictionary<string, string> 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);
}

@ -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;

@ -63,6 +63,11 @@ namespace MediaBrowser.Model.Entities
/// <summary>
/// The box rear.
/// </summary>
BoxRear = 11
BoxRear = 11,
/// <summary>
/// The user profile image.
/// </summary>
Profile = 12
}
}

Loading…
Cancel
Save