using System;
using System.ComponentModel;
using System.Diagnostics.CodeAnalysis;
using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.Providers;
using MediaBrowser.Model.IO;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
namespace Jellyfin.Api.Controllers
{
///
/// Item Refresh Controller.
///
/// [Authenticated]
[Route("/Items")]
[Authorize]
public class ItemRefreshController : BaseJellyfinApiController
{
private readonly ILibraryManager _libraryManager;
private readonly IProviderManager _providerManager;
private readonly IFileSystem _fileSystem;
///
/// Initializes a new instance of the class.
///
/// Instance of interface.
/// Instance of interface.
/// Instance of interface.
public ItemRefreshController(
ILibraryManager libraryManager,
IProviderManager providerManager,
IFileSystem fileSystem)
{
_libraryManager = libraryManager;
_providerManager = providerManager;
_fileSystem = fileSystem;
}
///
/// Refreshes metadata for an item.
///
/// Item id.
/// (Optional) Specifies the metadata refresh mode.
/// (Optional) Specifies the image refresh mode.
/// (Optional) Determines if metadata should be replaced. Only applicable if mode is FullRefresh.
/// (Optional) Determines if images should be replaced. Only applicable if mode is FullRefresh.
/// (Unused) Indicates if the refresh should occur recursively.
/// Item metadata refresh queued.
/// Item to refresh not found.
/// An on success, or a if the item could not be found.
[HttpPost("{itemId}/Refresh")]
[Description("Refreshes metadata for an item.")]
[ProducesResponseType(StatusCodes.Status204NoContent)]
[ProducesResponseType(StatusCodes.Status404NotFound)]
[SuppressMessage("Microsoft.Performance", "CA1801:ReviewUnusedParameters", MessageId = "recursive", Justification = "Imported from ServiceStack")]
public ActionResult Post(
[FromRoute] Guid itemId,
[FromQuery] MetadataRefreshMode metadataRefreshMode = MetadataRefreshMode.None,
[FromQuery] MetadataRefreshMode imageRefreshMode = MetadataRefreshMode.None,
[FromQuery] bool replaceAllMetadata = false,
[FromQuery] bool replaceAllImages = false,
[FromQuery] bool recursive = false)
{
var item = _libraryManager.GetItemById(itemId);
if (item == null)
{
return NotFound();
}
var refreshOptions = new MetadataRefreshOptions(new DirectoryService(_fileSystem))
{
MetadataRefreshMode = metadataRefreshMode,
ImageRefreshMode = imageRefreshMode,
ReplaceAllImages = replaceAllImages,
ReplaceAllMetadata = replaceAllMetadata,
ForceSave = metadataRefreshMode == MetadataRefreshMode.FullRefresh
|| imageRefreshMode == MetadataRefreshMode.FullRefresh
|| replaceAllImages
|| replaceAllMetadata,
IsAutomated = false
};
_providerManager.QueueRefresh(item.Id, refreshOptions, RefreshPriority.High);
return NoContent();
}
}
}