mirror of
https://github.com/jellyfin/jellyfin.git
synced 2025-12-22 16:54:46 +03:00
Migrate to file-scoped namespaces
This commit is contained in:
@@ -14,103 +14,102 @@ using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace Jellyfin.Api.Controllers
|
||||
namespace Jellyfin.Api.Controllers;
|
||||
|
||||
/// <summary>
|
||||
/// The dashboard controller.
|
||||
/// </summary>
|
||||
[Route("")]
|
||||
public class DashboardController : BaseJellyfinApiController
|
||||
{
|
||||
private readonly ILogger<DashboardController> _logger;
|
||||
private readonly IPluginManager _pluginManager;
|
||||
|
||||
/// <summary>
|
||||
/// The dashboard controller.
|
||||
/// Initializes a new instance of the <see cref="DashboardController"/> class.
|
||||
/// </summary>
|
||||
[Route("")]
|
||||
public class DashboardController : BaseJellyfinApiController
|
||||
/// <param name="logger">Instance of <see cref="ILogger{DashboardController}"/> interface.</param>
|
||||
/// <param name="pluginManager">Instance of <see cref="IPluginManager"/> interface.</param>
|
||||
public DashboardController(
|
||||
ILogger<DashboardController> logger,
|
||||
IPluginManager pluginManager)
|
||||
{
|
||||
private readonly ILogger<DashboardController> _logger;
|
||||
private readonly IPluginManager _pluginManager;
|
||||
_logger = logger;
|
||||
_pluginManager = pluginManager;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="DashboardController"/> class.
|
||||
/// </summary>
|
||||
/// <param name="logger">Instance of <see cref="ILogger{DashboardController}"/> interface.</param>
|
||||
/// <param name="pluginManager">Instance of <see cref="IPluginManager"/> interface.</param>
|
||||
public DashboardController(
|
||||
ILogger<DashboardController> logger,
|
||||
IPluginManager pluginManager)
|
||||
/// <summary>
|
||||
/// Gets the configuration pages.
|
||||
/// </summary>
|
||||
/// <param name="enableInMainMenu">Whether to enable in the main menu.</param>
|
||||
/// <response code="200">ConfigurationPages returned.</response>
|
||||
/// <response code="404">Server still loading.</response>
|
||||
/// <returns>An <see cref="IEnumerable{ConfigurationPageInfo}"/> with infos about the plugins.</returns>
|
||||
[HttpGet("web/ConfigurationPages")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
||||
[Authorize(Policy = Policies.DefaultAuthorization)]
|
||||
public ActionResult<IEnumerable<ConfigurationPageInfo>> GetConfigurationPages(
|
||||
[FromQuery] bool? enableInMainMenu)
|
||||
{
|
||||
var configPages = _pluginManager.Plugins.SelectMany(GetConfigPages).ToList();
|
||||
|
||||
if (enableInMainMenu.HasValue)
|
||||
{
|
||||
_logger = logger;
|
||||
_pluginManager = pluginManager;
|
||||
configPages = configPages.Where(p => p.EnableInMainMenu == enableInMainMenu.Value).ToList();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the configuration pages.
|
||||
/// </summary>
|
||||
/// <param name="enableInMainMenu">Whether to enable in the main menu.</param>
|
||||
/// <response code="200">ConfigurationPages returned.</response>
|
||||
/// <response code="404">Server still loading.</response>
|
||||
/// <returns>An <see cref="IEnumerable{ConfigurationPageInfo}"/> with infos about the plugins.</returns>
|
||||
[HttpGet("web/ConfigurationPages")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
||||
[Authorize(Policy = Policies.DefaultAuthorization)]
|
||||
public ActionResult<IEnumerable<ConfigurationPageInfo>> GetConfigurationPages(
|
||||
[FromQuery] bool? enableInMainMenu)
|
||||
return configPages;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a dashboard configuration page.
|
||||
/// </summary>
|
||||
/// <param name="name">The name of the page.</param>
|
||||
/// <response code="200">ConfigurationPage returned.</response>
|
||||
/// <response code="404">Plugin configuration page not found.</response>
|
||||
/// <returns>The configuration page.</returns>
|
||||
[HttpGet("web/ConfigurationPage")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
||||
[ProducesFile(MediaTypeNames.Text.Html, "application/x-javascript")]
|
||||
public ActionResult GetDashboardConfigurationPage([FromQuery] string? name)
|
||||
{
|
||||
var altPage = GetPluginPages().FirstOrDefault(p => string.Equals(p.Item1.Name, name, StringComparison.OrdinalIgnoreCase));
|
||||
if (altPage is null)
|
||||
{
|
||||
var configPages = _pluginManager.Plugins.SelectMany(GetConfigPages).ToList();
|
||||
|
||||
if (enableInMainMenu.HasValue)
|
||||
{
|
||||
configPages = configPages.Where(p => p.EnableInMainMenu == enableInMainMenu.Value).ToList();
|
||||
}
|
||||
|
||||
return configPages;
|
||||
return NotFound();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a dashboard configuration page.
|
||||
/// </summary>
|
||||
/// <param name="name">The name of the page.</param>
|
||||
/// <response code="200">ConfigurationPage returned.</response>
|
||||
/// <response code="404">Plugin configuration page not found.</response>
|
||||
/// <returns>The configuration page.</returns>
|
||||
[HttpGet("web/ConfigurationPage")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
||||
[ProducesFile(MediaTypeNames.Text.Html, "application/x-javascript")]
|
||||
public ActionResult GetDashboardConfigurationPage([FromQuery] string? name)
|
||||
IPlugin plugin = altPage.Item2;
|
||||
string resourcePath = altPage.Item1.EmbeddedResourcePath;
|
||||
Stream? stream = plugin.GetType().Assembly.GetManifestResourceStream(resourcePath);
|
||||
if (stream is null)
|
||||
{
|
||||
var altPage = GetPluginPages().FirstOrDefault(p => string.Equals(p.Item1.Name, name, StringComparison.OrdinalIgnoreCase));
|
||||
if (altPage is null)
|
||||
{
|
||||
return NotFound();
|
||||
}
|
||||
|
||||
IPlugin plugin = altPage.Item2;
|
||||
string resourcePath = altPage.Item1.EmbeddedResourcePath;
|
||||
Stream? stream = plugin.GetType().Assembly.GetManifestResourceStream(resourcePath);
|
||||
if (stream is null)
|
||||
{
|
||||
_logger.LogError("Failed to get resource {Resource} from plugin {Plugin}", resourcePath, plugin.Name);
|
||||
return NotFound();
|
||||
}
|
||||
|
||||
return File(stream, MimeTypes.GetMimeType(resourcePath));
|
||||
_logger.LogError("Failed to get resource {Resource} from plugin {Plugin}", resourcePath, plugin.Name);
|
||||
return NotFound();
|
||||
}
|
||||
|
||||
private IEnumerable<ConfigurationPageInfo> GetConfigPages(LocalPlugin plugin)
|
||||
return File(stream, MimeTypes.GetMimeType(resourcePath));
|
||||
}
|
||||
|
||||
private IEnumerable<ConfigurationPageInfo> GetConfigPages(LocalPlugin plugin)
|
||||
{
|
||||
return GetPluginPages(plugin).Select(i => new ConfigurationPageInfo(plugin.Instance, i.Item1));
|
||||
}
|
||||
|
||||
private IEnumerable<Tuple<PluginPageInfo, IPlugin>> GetPluginPages(LocalPlugin plugin)
|
||||
{
|
||||
if (plugin.Instance is not IHasWebPages hasWebPages)
|
||||
{
|
||||
return GetPluginPages(plugin).Select(i => new ConfigurationPageInfo(plugin.Instance, i.Item1));
|
||||
return Enumerable.Empty<Tuple<PluginPageInfo, IPlugin>>();
|
||||
}
|
||||
|
||||
private IEnumerable<Tuple<PluginPageInfo, IPlugin>> GetPluginPages(LocalPlugin plugin)
|
||||
{
|
||||
if (plugin.Instance is not IHasWebPages hasWebPages)
|
||||
{
|
||||
return Enumerable.Empty<Tuple<PluginPageInfo, IPlugin>>();
|
||||
}
|
||||
return hasWebPages.GetPages().Select(i => new Tuple<PluginPageInfo, IPlugin>(i, plugin.Instance));
|
||||
}
|
||||
|
||||
return hasWebPages.GetPages().Select(i => new Tuple<PluginPageInfo, IPlugin>(i, plugin.Instance));
|
||||
}
|
||||
|
||||
private IEnumerable<Tuple<PluginPageInfo, IPlugin>> GetPluginPages()
|
||||
{
|
||||
return _pluginManager.Plugins.SelectMany(GetPluginPages);
|
||||
}
|
||||
private IEnumerable<Tuple<PluginPageInfo, IPlugin>> GetPluginPages()
|
||||
{
|
||||
return _pluginManager.Plugins.SelectMany(GetPluginPages);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user