first commit
This commit is contained in:
@@ -0,0 +1,76 @@
|
||||
using System;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Jellyfin.Plugin.JRay.Models;
|
||||
using Jellyfin.Plugin.JRay.Services.Interfaces;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace Jellyfin.Plugin.JRay.Controllers;
|
||||
|
||||
/// <summary>
|
||||
/// Accepts scene-actor-extraction "truth" data pushed directly by a remote
|
||||
/// extraction worker, for servers that cannot run the extraction pipeline
|
||||
/// locally. See SPEC.md.
|
||||
/// </summary>
|
||||
[ApiController]
|
||||
[Route("Plugins/JRay/Items/{itemId}/Truth")]
|
||||
[Authorize(Roles = "Administrator")]
|
||||
public class TruthController : ControllerBase
|
||||
{
|
||||
private const int SupportedSchemaVersion = 1;
|
||||
|
||||
private readonly IManagedTruthStore _managedTruthStore;
|
||||
private readonly ITruthDataService _truthDataService;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="TruthController"/> class.
|
||||
/// </summary>
|
||||
/// <param name="managedTruthStore">The managed truth store.</param>
|
||||
/// <param name="truthDataService">The truth data service.</param>
|
||||
public TruthController(IManagedTruthStore managedTruthStore, ITruthDataService truthDataService)
|
||||
{
|
||||
_managedTruthStore = managedTruthStore;
|
||||
_truthDataService = truthDataService;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Uploads (creates or replaces) the truth data for an item.
|
||||
/// </summary>
|
||||
/// <param name="itemId">The Jellyfin item id.</param>
|
||||
/// <param name="truth">The truth file contents.</param>
|
||||
/// <param name="cancellationToken">Cancellation token.</param>
|
||||
/// <returns>204 on success, or 400 if the schema version is unsupported.</returns>
|
||||
[HttpPut]
|
||||
[ProducesResponseType(StatusCodes.Status204NoContent)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
public async Task<IActionResult> PutTruth(Guid itemId, [FromBody] TruthFile truth, CancellationToken cancellationToken)
|
||||
{
|
||||
if (truth.SchemaVersion != SupportedSchemaVersion)
|
||||
{
|
||||
return BadRequest($"Unsupported schema_version {truth.SchemaVersion}; expected {SupportedSchemaVersion}.");
|
||||
}
|
||||
|
||||
await _managedTruthStore.SaveAsync(itemId, truth, cancellationToken).ConfigureAwait(false);
|
||||
_truthDataService.Invalidate(itemId);
|
||||
|
||||
return NoContent();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Removes any managed truth data for an item. The item falls back to
|
||||
/// its sidecar truth file (if any) on subsequent reads.
|
||||
/// </summary>
|
||||
/// <param name="itemId">The Jellyfin item id.</param>
|
||||
/// <returns>204, whether or not managed data existed.</returns>
|
||||
[HttpDelete]
|
||||
[ProducesResponseType(StatusCodes.Status204NoContent)]
|
||||
public IActionResult DeleteTruth(Guid itemId)
|
||||
{
|
||||
_managedTruthStore.Delete(itemId);
|
||||
_truthDataService.Invalidate(itemId);
|
||||
|
||||
return NoContent();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user