using Jellyfin.Plugin.Requests.Configuration;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
namespace Jellyfin.Plugin.Requests.Controllers
{
///
/// Controller for handling request URL configurations.
///
[Route("Plugins/Requests/[action]")]
public class RequestsController : ControllerBase
{
private readonly ILogger _logger;
private readonly PluginConfiguration _config;
///
/// Initializes a new instance of the class.
///
/// Logger for this controller.
/// Configuration for request URLs.
public RequestsController(ILogger logger, PluginConfiguration config)
{
_logger = logger;
_config = config;
}
///
/// Retrieves the current Requests URL from the configuration.
///
/// The current Requests URL if available; otherwise, NotFound.
[HttpGet("PublicGetRequestsUrl")]
public ActionResult PublicGetRequestsUrl()
{
if (Plugin.Instance?.Configuration != null)
{
_logger.LogInformation("Fetching Requests URL.");
return Ok(Plugin.Instance.Configuration.RequestsUrl);
}
else
{
_logger.LogError("Plugin configuration is not available.");
return NotFound("Plugin configuration is not available.");
}
}
///
/// Sets a new Requests URL in the configuration.
///
/// The new URL to set.
/// A NoContent result if the URL was successfully set; otherwise, NotFound.
[HttpPost("SetRequestsUrl")]
public ActionResult SetRequestsUrl([FromBody] string url)
{
if (Plugin.Instance?.Configuration != null)
{
_logger.LogInformation($"Setting Requests URL to {url}.");
Plugin.Instance.Configuration.RequestsUrl = url;
Plugin.Instance.UpdateConfiguration(Plugin.Instance.Configuration);
return NoContent();
}
else
{
_logger.LogError("Plugin configuration is not available when attempting to set Requests URL.");
return NotFound("Plugin configuration is not available.");
}
}
}
}