Keeps Radarr/Sonarr quality upgrades out of "Recently Added" by keeping a ledger of the first date added per logical medium (movie or episode, identified by provider ids and the series) and restoring it on upgrades. - core logic without Jellyfin types (Reconciler, MediaKeys, GuardProcessor) - thread-safe ledger with atomic, debounced persistence - event processing via channel and background worker, seed on first start - scheduled task "Ledger synchronisieren", status API, configuration page - xUnit tests and a Jellyfin 12.2 integration test - Gitea workflows: build/test, release with jprm and manifest branch Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
77 lines
2.7 KiB
C#
77 lines
2.7 KiB
C#
using System.Net.Mime;
|
|
using Jellyfin.Plugin.RecentlyAddedGuard.Core;
|
|
using Jellyfin.Plugin.RecentlyAddedGuard.Ledger;
|
|
using Jellyfin.Plugin.RecentlyAddedGuard.Tasks;
|
|
using MediaBrowser.Common.Api;
|
|
using MediaBrowser.Model.Tasks;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Http;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
namespace Jellyfin.Plugin.RecentlyAddedGuard.Api;
|
|
|
|
/// <summary>
|
|
/// Status and actions for the configuration page. Jellyfin adds plugin assemblies as MVC application parts,
|
|
/// so this controller is discovered automatically.
|
|
/// </summary>
|
|
[ApiController]
|
|
[Route("RecentlyAddedGuard")]
|
|
[Authorize(Policy = Policies.RequiresElevation)]
|
|
[Produces(MediaTypeNames.Application.Json)]
|
|
public class GuardController : ControllerBase
|
|
{
|
|
private readonly LedgerStore _store;
|
|
private readonly CorrectionLog _corrections;
|
|
private readonly ITaskManager _taskManager;
|
|
|
|
/// <summary>
|
|
/// Initializes a new instance of the <see cref="GuardController"/> class.
|
|
/// </summary>
|
|
/// <param name="store">The ledger.</param>
|
|
/// <param name="corrections">The correction log.</param>
|
|
/// <param name="taskManager">The task manager.</param>
|
|
public GuardController(LedgerStore store, CorrectionLog corrections, ITaskManager taskManager)
|
|
{
|
|
_store = store;
|
|
_corrections = corrections;
|
|
_taskManager = taskManager;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Gets ledger statistics and the most recent corrections.
|
|
/// </summary>
|
|
/// <response code="200">The status.</response>
|
|
/// <returns>The status.</returns>
|
|
[HttpGet("Status")]
|
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
|
public ActionResult<GuardStatus> GetStatus()
|
|
{
|
|
var statistics = _store.GetStatistics();
|
|
return new GuardStatus
|
|
{
|
|
LedgerEntries = statistics.Entries,
|
|
LiveEntries = statistics.LiveEntries,
|
|
RemovedEntries = statistics.RemovedEntries,
|
|
CorrectionsSinceStart = _corrections.CorrectionsSinceStart,
|
|
DryRunDetectionsSinceStart = _corrections.DryRunDetectionsSinceStart,
|
|
SeedCompleted = _store.SeedCompleted,
|
|
LastSyncUtc = _store.LastSyncUtc,
|
|
DryRun = Plugin.CurrentConfiguration.DryRun,
|
|
RecentCorrections = _corrections.GetRecent()
|
|
};
|
|
}
|
|
|
|
/// <summary>
|
|
/// Queues the scheduled task "Ledger synchronisieren".
|
|
/// </summary>
|
|
/// <response code="204">The task was queued (or is already running).</response>
|
|
/// <returns>No content.</returns>
|
|
[HttpPost("Sync")]
|
|
[ProducesResponseType(StatusCodes.Status204NoContent)]
|
|
public ActionResult StartSync()
|
|
{
|
|
_taskManager.QueueIfNotRunning<SyncLedgerTask>();
|
|
return NoContent();
|
|
}
|
|
}
|