add refresh item api method
This commit is contained in:
parent
b310c98656
commit
95afe143e8
|
@ -96,6 +96,17 @@ namespace MediaBrowser.Api
|
|||
{
|
||||
}
|
||||
|
||||
[Route("/Items/{Id}/Refresh", "POST")]
|
||||
[Api(Description = "Refreshes metadata for an item")]
|
||||
public class RefreshItem : IReturnVoid
|
||||
{
|
||||
[ApiMember(Name = "IsForced", Description = "Indicates if a normal or forced refresh should occur.", IsRequired = true, DataType = "bool", ParameterType = "query", Verb = "POST")]
|
||||
public bool IsForced { get; set; }
|
||||
|
||||
[ApiMember(Name = "Id", Description = "Item Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "POST")]
|
||||
public string Id { get; set; }
|
||||
}
|
||||
|
||||
[Route("/Items/Counts", "GET")]
|
||||
[Api(Description = "Gets counts of various item types")]
|
||||
public class GetItemCounts : IReturn<ItemCounts>
|
||||
|
@ -304,6 +315,17 @@ namespace MediaBrowser.Api
|
|||
return ToOptimizedResult(result);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Posts the specified request.
|
||||
/// </summary>
|
||||
/// <param name="request">The request.</param>
|
||||
public void Post(RefreshItem request)
|
||||
{
|
||||
var item = DtoBuilder.GetItemByClientId(request.Id, _userManager, _libraryManager);
|
||||
|
||||
item.RefreshMetadata(CancellationToken.None, forceRefresh: request.IsForced);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the specified request.
|
||||
/// </summary>
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
using MediaBrowser.Common.Extensions;
|
||||
using MediaBrowser.Common.IO;
|
||||
using MediaBrowser.Common.IO;
|
||||
using MediaBrowser.Common.Net;
|
||||
using MediaBrowser.Controller.Configuration;
|
||||
using MediaBrowser.Controller.Entities;
|
||||
|
@ -97,11 +96,6 @@ namespace MediaBrowser.Server.Implementations.Providers
|
|||
MetadataProviders = providers.OrderBy(e => e.Priority).ToArray();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The _supported providers key
|
||||
/// </summary>
|
||||
private readonly Guid _supportedProvidersKey = "SupportedProviders".GetMD5();
|
||||
|
||||
/// <summary>
|
||||
/// Runs all metadata providers for an entity, and returns true or false indicating if at least one was refreshed and requires persistence
|
||||
/// </summary>
|
||||
|
@ -120,40 +114,10 @@ namespace MediaBrowser.Server.Implementations.Providers
|
|||
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
|
||||
// Determine if supported providers have changed
|
||||
var supportedProviders = MetadataProviders.Where(p => p.Supports(item)).ToList();
|
||||
|
||||
BaseProviderInfo supportedProvidersInfo;
|
||||
|
||||
var supportedProvidersValue = string.Join(string.Empty, supportedProviders.Select(i => i.GetType().Name));
|
||||
var providersChanged = false;
|
||||
|
||||
item.ProviderData.TryGetValue(_supportedProvidersKey, out supportedProvidersInfo);
|
||||
|
||||
var supportedProvidersHash = supportedProvidersValue.GetMD5();
|
||||
|
||||
if (supportedProvidersInfo != null)
|
||||
{
|
||||
// Force refresh if the supported providers have changed
|
||||
providersChanged = force = force || supportedProvidersHash != supportedProvidersInfo.Data;
|
||||
|
||||
// If providers have changed, clear provider info and update the supported providers hash
|
||||
if (providersChanged)
|
||||
{
|
||||
_logger.Debug("Providers changed for {0}. Clearing and forcing refresh.", item.Name);
|
||||
item.ProviderData.Clear();
|
||||
}
|
||||
}
|
||||
|
||||
if (providersChanged)
|
||||
{
|
||||
supportedProvidersInfo.Data = supportedProvidersHash;
|
||||
}
|
||||
|
||||
if (force) item.ClearMetaValues();
|
||||
|
||||
// Run the normal providers sequentially in order of priority
|
||||
foreach (var provider in supportedProviders)
|
||||
foreach (var provider in MetadataProviders.Where(p => p.Supports(item)))
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
|
||||
|
@ -206,12 +170,7 @@ namespace MediaBrowser.Server.Implementations.Providers
|
|||
result |= results.Contains(true);
|
||||
}
|
||||
|
||||
if (providersChanged)
|
||||
{
|
||||
item.ProviderData[_supportedProvidersKey] = supportedProvidersInfo;
|
||||
}
|
||||
|
||||
return result || providersChanged;
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
Loading…
Reference in New Issue
Block a user