|
|
|
@ -12,6 +12,8 @@ using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Threading;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using CommonIO;
|
|
|
|
|
using MediaBrowser.Controller.Providers;
|
|
|
|
|
|
|
|
|
|
namespace MediaBrowser.Api.UserLibrary
|
|
|
|
|
{
|
|
|
|
@ -262,14 +264,16 @@ namespace MediaBrowser.Api.UserLibrary
|
|
|
|
|
private readonly ILibraryManager _libraryManager;
|
|
|
|
|
private readonly IDtoService _dtoService;
|
|
|
|
|
private readonly IUserViewManager _userViewManager;
|
|
|
|
|
private readonly IFileSystem _fileSystem;
|
|
|
|
|
|
|
|
|
|
public UserLibraryService(IUserManager userManager, ILibraryManager libraryManager, IUserDataManager userDataRepository, IDtoService dtoService, IUserViewManager userViewManager)
|
|
|
|
|
public UserLibraryService(IUserManager userManager, ILibraryManager libraryManager, IUserDataManager userDataRepository, IDtoService dtoService, IUserViewManager userViewManager, IFileSystem fileSystem)
|
|
|
|
|
{
|
|
|
|
|
_userManager = userManager;
|
|
|
|
|
_libraryManager = libraryManager;
|
|
|
|
|
_userDataRepository = userDataRepository;
|
|
|
|
|
_dtoService = dtoService;
|
|
|
|
|
_userViewManager = userViewManager;
|
|
|
|
|
_fileSystem = fileSystem;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
@ -426,12 +430,14 @@ namespace MediaBrowser.Api.UserLibrary
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="request">The request.</param>
|
|
|
|
|
/// <returns>System.Object.</returns>
|
|
|
|
|
public object Get(GetItem request)
|
|
|
|
|
public async Task<object> Get(GetItem request)
|
|
|
|
|
{
|
|
|
|
|
var user = _userManager.GetUserById(request.UserId);
|
|
|
|
|
|
|
|
|
|
var item = string.IsNullOrEmpty(request.Id) ? user.RootFolder : _libraryManager.GetItemById(request.Id);
|
|
|
|
|
|
|
|
|
|
await RefreshItemOnDemandIfNeeded(item).ConfigureAwait(false);
|
|
|
|
|
|
|
|
|
|
var dtoOptions = GetDtoOptions(request);
|
|
|
|
|
|
|
|
|
|
var result = _dtoService.GetBaseItemDto(item, dtoOptions, user);
|
|
|
|
@ -439,6 +445,35 @@ namespace MediaBrowser.Api.UserLibrary
|
|
|
|
|
return ToOptimizedSerializedResultUsingCache(result);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private async Task RefreshItemOnDemandIfNeeded(BaseItem item)
|
|
|
|
|
{
|
|
|
|
|
if (item is Person)
|
|
|
|
|
{
|
|
|
|
|
var hasMetdata = !string.IsNullOrWhiteSpace(item.Overview) && item.HasImage(ImageType.Primary);
|
|
|
|
|
var performFullRefresh = !hasMetdata && (DateTime.UtcNow - item.DateLastRefreshed).TotalDays >= 7;
|
|
|
|
|
|
|
|
|
|
if (!hasMetdata)
|
|
|
|
|
{
|
|
|
|
|
var defaultMetadataRefreshMode = performFullRefresh
|
|
|
|
|
? MetadataRefreshMode.FullRefresh
|
|
|
|
|
: MetadataRefreshMode.Default;
|
|
|
|
|
|
|
|
|
|
var imageRefreshMode = performFullRefresh
|
|
|
|
|
? ImageRefreshMode.FullRefresh
|
|
|
|
|
: ImageRefreshMode.Default;
|
|
|
|
|
|
|
|
|
|
var options = new MetadataRefreshOptions(_fileSystem)
|
|
|
|
|
{
|
|
|
|
|
MetadataRefreshMode = defaultMetadataRefreshMode,
|
|
|
|
|
ImageRefreshMode = imageRefreshMode,
|
|
|
|
|
ForceSave = performFullRefresh
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
await item.RefreshMetadata(options, CancellationToken.None).ConfigureAwait(false);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the specified request.
|
|
|
|
|
/// </summary>
|
|
|
|
|