fixes #152 - Gallery Images – some show, others don’t
This commit is contained in:
parent
27b1bdbf55
commit
7aa9e10821
|
@ -168,7 +168,9 @@ namespace MediaBrowser.Api
|
||||||
{
|
{
|
||||||
var dtoBuilder = new UserDtoBuilder(Logger);
|
var dtoBuilder = new UserDtoBuilder(Logger);
|
||||||
|
|
||||||
var users = _userManager.Users.OrderBy(u => u.Name).Select(dtoBuilder.GetUserDto).ToArray();
|
var tasks = _userManager.Users.OrderBy(u => u.Name).Select(dtoBuilder.GetUserDto);
|
||||||
|
|
||||||
|
var users = tasks.Select(i => i.Result).ToList();
|
||||||
|
|
||||||
return ToOptimizedResult(users);
|
return ToOptimizedResult(users);
|
||||||
}
|
}
|
||||||
|
@ -189,7 +191,7 @@ namespace MediaBrowser.Api
|
||||||
|
|
||||||
var dtoBuilder = new UserDtoBuilder(Logger);
|
var dtoBuilder = new UserDtoBuilder(Logger);
|
||||||
|
|
||||||
var result = dtoBuilder.GetUserDto(user);
|
var result = dtoBuilder.GetUserDto(user).Result;
|
||||||
|
|
||||||
return ToOptimizedResult(result);
|
return ToOptimizedResult(result);
|
||||||
}
|
}
|
||||||
|
@ -305,7 +307,7 @@ namespace MediaBrowser.Api
|
||||||
|
|
||||||
var dtoBuilder = new UserDtoBuilder(Logger);
|
var dtoBuilder = new UserDtoBuilder(Logger);
|
||||||
|
|
||||||
var result = dtoBuilder.GetUserDto(newUser);
|
var result = dtoBuilder.GetUserDto(newUser).Result;
|
||||||
|
|
||||||
return ToOptimizedResult(result);
|
return ToOptimizedResult(result);
|
||||||
}
|
}
|
||||||
|
|
|
@ -137,7 +137,7 @@ namespace MediaBrowser.Controller.Drawing
|
||||||
_logger.Error("Error enhancing image", ex);
|
_logger.Error("Error enhancing image", ex);
|
||||||
}
|
}
|
||||||
|
|
||||||
var originalImageSize = GetImageSize(originalImagePath, dateModified);
|
var originalImageSize = await GetImageSize(originalImagePath, dateModified).ConfigureAwait(false);
|
||||||
|
|
||||||
// Determine the output size based on incoming parameters
|
// Determine the output size based on incoming parameters
|
||||||
var newSize = DrawingUtils.Resize(originalImageSize, width, height, maxWidth, maxHeight);
|
var newSize = DrawingUtils.Resize(originalImageSize, width, height, maxWidth, maxHeight);
|
||||||
|
@ -149,16 +149,6 @@ namespace MediaBrowser.Controller.Drawing
|
||||||
|
|
||||||
var cacheFilePath = GetCacheFilePath(originalImagePath, newSize, quality.Value, dateModified);
|
var cacheFilePath = GetCacheFilePath(originalImagePath, newSize, quality.Value, dateModified);
|
||||||
|
|
||||||
// Grab the cache file if it already exists
|
|
||||||
if (File.Exists(cacheFilePath))
|
|
||||||
{
|
|
||||||
using (var fileStream = new FileStream(cacheFilePath, FileMode.Open, FileAccess.Read, FileShare.Read, StreamDefaults.DefaultFileStreamBufferSize, FileOptions.Asynchronous))
|
|
||||||
{
|
|
||||||
await fileStream.CopyToAsync(toStream).ConfigureAwait(false);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var semaphore = GetLock(cacheFilePath);
|
var semaphore = GetLock(cacheFilePath);
|
||||||
|
|
||||||
await semaphore.WaitAsync().ConfigureAwait(false);
|
await semaphore.WaitAsync().ConfigureAwait(false);
|
||||||
|
@ -279,7 +269,7 @@ namespace MediaBrowser.Controller.Drawing
|
||||||
/// <param name="dateModified">The date modified.</param>
|
/// <param name="dateModified">The date modified.</param>
|
||||||
/// <returns>Task{ImageSize}.</returns>
|
/// <returns>Task{ImageSize}.</returns>
|
||||||
/// <exception cref="System.ArgumentNullException">imagePath</exception>
|
/// <exception cref="System.ArgumentNullException">imagePath</exception>
|
||||||
public ImageSize GetImageSize(string imagePath, DateTime dateModified)
|
public async Task<ImageSize> GetImageSize(string imagePath, DateTime dateModified)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(imagePath))
|
if (string.IsNullOrEmpty(imagePath))
|
||||||
{
|
{
|
||||||
|
@ -288,7 +278,16 @@ namespace MediaBrowser.Controller.Drawing
|
||||||
|
|
||||||
var name = imagePath + "datemodified=" + dateModified.Ticks;
|
var name = imagePath + "datemodified=" + dateModified.Ticks;
|
||||||
|
|
||||||
return _cachedImagedSizes.GetOrAdd(name, keyName => GetImageSize(keyName, imagePath));
|
ImageSize size;
|
||||||
|
|
||||||
|
if (!_cachedImagedSizes.TryGetValue(name, out size))
|
||||||
|
{
|
||||||
|
size = await GetImageSize(name, imagePath).ConfigureAwait(false);
|
||||||
|
|
||||||
|
_cachedImagedSizes.AddOrUpdate(name, size, (keyName, oldValue) => size);
|
||||||
|
}
|
||||||
|
|
||||||
|
return size;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected readonly CultureInfo UsCulture = new CultureInfo("en-US");
|
protected readonly CultureInfo UsCulture = new CultureInfo("en-US");
|
||||||
|
@ -299,30 +298,41 @@ namespace MediaBrowser.Controller.Drawing
|
||||||
/// <param name="keyName">Name of the key.</param>
|
/// <param name="keyName">Name of the key.</param>
|
||||||
/// <param name="imagePath">The image path.</param>
|
/// <param name="imagePath">The image path.</param>
|
||||||
/// <returns>ImageSize.</returns>
|
/// <returns>ImageSize.</returns>
|
||||||
private ImageSize GetImageSize(string keyName, string imagePath)
|
private async Task<ImageSize> GetImageSize(string keyName, string imagePath)
|
||||||
{
|
{
|
||||||
// Now check the file system cache
|
// Now check the file system cache
|
||||||
var fullCachePath = ImageSizeCache.GetResourcePath(keyName, ".txt");
|
var fullCachePath = ImageSizeCache.GetResourcePath(keyName, ".txt");
|
||||||
|
|
||||||
|
var semaphore = GetLock(fullCachePath);
|
||||||
|
|
||||||
|
await semaphore.WaitAsync().ConfigureAwait(false);
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var result = File.ReadAllText(fullCachePath).Split('|').Select(i => double.Parse(i, UsCulture)).ToArray();
|
try
|
||||||
|
{
|
||||||
|
var result = File.ReadAllText(fullCachePath).Split('|').Select(i => double.Parse(i, UsCulture)).ToArray();
|
||||||
|
|
||||||
return new ImageSize { Width = result[0], Height = result[1] };
|
return new ImageSize { Width = result[0], Height = result[1] };
|
||||||
|
}
|
||||||
|
catch (FileNotFoundException)
|
||||||
|
{
|
||||||
|
// Cache file doesn't exist no biggie
|
||||||
|
}
|
||||||
|
|
||||||
|
_logger.Debug("Getting image size for {0}", imagePath);
|
||||||
|
|
||||||
|
var size = ImageHeader.GetDimensions(imagePath, _logger);
|
||||||
|
|
||||||
|
// Update the file system cache
|
||||||
|
File.WriteAllText(fullCachePath, size.Width.ToString(UsCulture) + @"|" + size.Height.ToString(UsCulture));
|
||||||
|
|
||||||
|
return new ImageSize { Width = size.Width, Height = size.Height };
|
||||||
}
|
}
|
||||||
catch (FileNotFoundException)
|
finally
|
||||||
{
|
{
|
||||||
// Cache file doesn't exist no biggie
|
semaphore.Release();
|
||||||
}
|
}
|
||||||
|
|
||||||
_logger.Debug("Getting image size for {0}", imagePath);
|
|
||||||
|
|
||||||
var size = ImageHeader.GetDimensions(imagePath, _logger);
|
|
||||||
|
|
||||||
// Update the file system cache
|
|
||||||
File.WriteAllText(fullCachePath, size.Width.ToString(UsCulture) + @"|" + size.Height.ToString(UsCulture));
|
|
||||||
|
|
||||||
return new ImageSize { Width = size.Width, Height = size.Height };
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -445,11 +455,6 @@ namespace MediaBrowser.Controller.Drawing
|
||||||
|
|
||||||
var croppedImagePath = CroppedImageCache.GetResourcePath(name, Path.GetExtension(originalImagePath));
|
var croppedImagePath = CroppedImageCache.GetResourcePath(name, Path.GetExtension(originalImagePath));
|
||||||
|
|
||||||
if (CroppedImageCache.ContainsFilePath(croppedImagePath))
|
|
||||||
{
|
|
||||||
return croppedImagePath;
|
|
||||||
}
|
|
||||||
|
|
||||||
var semaphore = GetLock(croppedImagePath);
|
var semaphore = GetLock(croppedImagePath);
|
||||||
|
|
||||||
await semaphore.WaitAsync().ConfigureAwait(false);
|
await semaphore.WaitAsync().ConfigureAwait(false);
|
||||||
|
@ -529,11 +534,6 @@ namespace MediaBrowser.Controller.Drawing
|
||||||
// All enhanced images are saved as png to allow transparency
|
// All enhanced images are saved as png to allow transparency
|
||||||
var enhancedImagePath = EnhancedImageCache.GetResourcePath(cacheGuid + ".png");
|
var enhancedImagePath = EnhancedImageCache.GetResourcePath(cacheGuid + ".png");
|
||||||
|
|
||||||
if (EnhancedImageCache.ContainsFilePath(enhancedImagePath))
|
|
||||||
{
|
|
||||||
return enhancedImagePath;
|
|
||||||
}
|
|
||||||
|
|
||||||
var semaphore = GetLock(enhancedImagePath);
|
var semaphore = GetLock(enhancedImagePath);
|
||||||
|
|
||||||
await semaphore.WaitAsync().ConfigureAwait(false);
|
await semaphore.WaitAsync().ConfigureAwait(false);
|
||||||
|
|
|
@ -75,7 +75,7 @@ namespace MediaBrowser.Controller.Dto
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
AttachPrimaryImageAspectRatio(dto, item, _logger);
|
await AttachPrimaryImageAspectRatio(dto, item, _logger).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
@ -138,7 +138,7 @@ namespace MediaBrowser.Controller.Dto
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
AttachPrimaryImageAspectRatio(dto, item, _logger);
|
await AttachPrimaryImageAspectRatio(dto, item, _logger).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
@ -198,9 +198,9 @@ namespace MediaBrowser.Controller.Dto
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="dto">The dto.</param>
|
/// <param name="dto">The dto.</param>
|
||||||
/// <param name="item">The item.</param>
|
/// <param name="item">The item.</param>
|
||||||
/// <param name="_logger">The _logger.</param>
|
/// <param name="logger">The _logger.</param>
|
||||||
/// <returns>Task.</returns>
|
/// <returns>Task.</returns>
|
||||||
internal static void AttachPrimaryImageAspectRatio(IItemDto dto, BaseItem item, ILogger _logger)
|
internal static async Task AttachPrimaryImageAspectRatio(IItemDto dto, BaseItem item, ILogger logger)
|
||||||
{
|
{
|
||||||
var path = item.PrimaryImagePath;
|
var path = item.PrimaryImagePath;
|
||||||
|
|
||||||
|
@ -218,16 +218,16 @@ namespace MediaBrowser.Controller.Dto
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
size = Kernel.Instance.ImageManager.GetImageSize(path, dateModified);
|
size = await Kernel.Instance.ImageManager.GetImageSize(path, dateModified).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
catch (FileNotFoundException)
|
catch (FileNotFoundException)
|
||||||
{
|
{
|
||||||
_logger.Error("Image file does not exist: {0}", path);
|
logger.Error("Image file does not exist: {0}", path);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
_logger.ErrorException("Failed to determine primary image aspect ratio for {0}", ex, path);
|
logger.ErrorException("Failed to determine primary image aspect ratio for {0}", ex, path);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,7 @@ using MediaBrowser.Model.Dto;
|
||||||
using MediaBrowser.Model.Entities;
|
using MediaBrowser.Model.Entities;
|
||||||
using MediaBrowser.Model.Logging;
|
using MediaBrowser.Model.Logging;
|
||||||
using System;
|
using System;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace MediaBrowser.Controller.Dto
|
namespace MediaBrowser.Controller.Dto
|
||||||
{
|
{
|
||||||
|
@ -31,7 +32,7 @@ namespace MediaBrowser.Controller.Dto
|
||||||
/// <param name="user">The user.</param>
|
/// <param name="user">The user.</param>
|
||||||
/// <returns>DtoUser.</returns>
|
/// <returns>DtoUser.</returns>
|
||||||
/// <exception cref="System.ArgumentNullException">user</exception>
|
/// <exception cref="System.ArgumentNullException">user</exception>
|
||||||
public UserDto GetUserDto(User user)
|
public async Task<UserDto> GetUserDto(User user)
|
||||||
{
|
{
|
||||||
if (user == null)
|
if (user == null)
|
||||||
{
|
{
|
||||||
|
@ -56,7 +57,7 @@ namespace MediaBrowser.Controller.Dto
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
DtoBuilder.AttachPrimaryImageAspectRatio(dto, user, _logger);
|
await DtoBuilder.AttachPrimaryImageAspectRatio(dto, user, _logger).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
|
|
@ -241,9 +241,9 @@ namespace MediaBrowser.ServerApplication.EntryPoints
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="sender">The sender.</param>
|
/// <param name="sender">The sender.</param>
|
||||||
/// <param name="e">The e.</param>
|
/// <param name="e">The e.</param>
|
||||||
void userManager_UserUpdated(object sender, GenericEventArgs<User> e)
|
async void userManager_UserUpdated(object sender, GenericEventArgs<User> e)
|
||||||
{
|
{
|
||||||
var dto = new UserDtoBuilder(_logger).GetUserDto(e.Argument);
|
var dto = await new UserDtoBuilder(_logger).GetUserDto(e.Argument).ConfigureAwait(false);
|
||||||
|
|
||||||
_serverManager.SendWebSocketMessage("UserUpdated", dto);
|
_serverManager.SendWebSocketMessage("UserUpdated", dto);
|
||||||
}
|
}
|
||||||
|
|
|
@ -61,7 +61,7 @@ namespace MediaBrowser.WebDashboard.Api
|
||||||
/// <returns>Task{IEnumerable{TaskInfo}}.</returns>
|
/// <returns>Task{IEnumerable{TaskInfo}}.</returns>
|
||||||
protected override Task<DashboardInfo> GetDataToSend(object state)
|
protected override Task<DashboardInfo> GetDataToSend(object state)
|
||||||
{
|
{
|
||||||
return Task.FromResult(DashboardService.GetDashboardInfo(_appHost, Logger, _taskManager, _userManager, _libraryManager));
|
return DashboardService.GetDashboardInfo(_appHost, Logger, _taskManager, _userManager, _libraryManager);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -177,7 +177,9 @@ namespace MediaBrowser.WebDashboard.Api
|
||||||
/// <returns>System.Object.</returns>
|
/// <returns>System.Object.</returns>
|
||||||
public object Get(GetDashboardInfo request)
|
public object Get(GetDashboardInfo request)
|
||||||
{
|
{
|
||||||
return GetDashboardInfo(_appHost, Logger, _taskManager, _userManager, _libraryManager);
|
var result = GetDashboardInfo(_appHost, Logger, _taskManager, _userManager, _libraryManager).Result;
|
||||||
|
|
||||||
|
return ResultFactory.GetOptimizedResult(RequestContext, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -189,13 +191,15 @@ namespace MediaBrowser.WebDashboard.Api
|
||||||
/// <param name="userManager">The user manager.</param>
|
/// <param name="userManager">The user manager.</param>
|
||||||
/// <param name="libraryManager">The library manager.</param>
|
/// <param name="libraryManager">The library manager.</param>
|
||||||
/// <returns>DashboardInfo.</returns>
|
/// <returns>DashboardInfo.</returns>
|
||||||
public static DashboardInfo GetDashboardInfo(IServerApplicationHost appHost, ILogger logger, ITaskManager taskManager, IUserManager userManager, ILibraryManager libraryManager)
|
public static async Task<DashboardInfo> GetDashboardInfo(IServerApplicationHost appHost, ILogger logger, ITaskManager taskManager, IUserManager userManager, ILibraryManager libraryManager)
|
||||||
{
|
{
|
||||||
var connections = userManager.RecentConnections.ToArray();
|
var connections = userManager.RecentConnections.ToArray();
|
||||||
|
|
||||||
var dtoBuilder = new UserDtoBuilder(logger);
|
var dtoBuilder = new UserDtoBuilder(logger);
|
||||||
|
|
||||||
var users = userManager.Users.Where(u => connections.Any(c => new Guid(c.UserId) == u.Id)).Select(dtoBuilder.GetUserDto);
|
var tasks = userManager.Users.Where(u => connections.Any(c => new Guid(c.UserId) == u.Id)).Select(dtoBuilder.GetUserDto);
|
||||||
|
|
||||||
|
var users = await Task.WhenAll(tasks).ConfigureAwait(false);
|
||||||
|
|
||||||
return new DashboardInfo
|
return new DashboardInfo
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue
Block a user