2using System.Collections.Generic;
3using System.Globalization;
5using System.Threading.Tasks;
7using Microsoft.AspNetCore.Hosting;
8using Microsoft.AspNetCore.Mvc;
9using Microsoft.AspNetCore.Mvc.Filters;
10using Microsoft.Extensions.Logging;
11using Microsoft.Extensions.Options;
12using Microsoft.Extensions.Primitives;
13using Microsoft.Net.Http.Headers;
24 [Route(ControlPanelRoute)]
25 [ApiExplorerSettings(IgnoreApi =
true)]
56 readonly ILogger<ControlPanelController>
logger;
67 ILogger<ControlPanelController>
logger)
71 this.logger =
logger ??
throw new ArgumentNullException(nameof(
logger));
84 logger.LogDebug(
"Not serving channel.json as control panel is disabled.");
89 logger.LogTrace(
"Generating channel.json for channel \"{channel}\"...", controlPanelChannel);
91 if (controlPanelChannel ==
"local")
93 else if (String.IsNullOrWhiteSpace(controlPanelChannel))
94 controlPanelChannel =
null;
96 controlPanelChannel = controlPanelChannel
97 .Replace(
"${Major}",
ApiHeaders.
Version.Major.ToString(CultureInfo.InvariantCulture), StringComparison.Ordinal)
98 .Replace(
"${Minor}",
ApiHeaders.
Version.Minor.ToString(CultureInfo.InvariantCulture), StringComparison.Ordinal)
99 .Replace(
"${Patch}",
ApiHeaders.
Version.Build.ToString(CultureInfo.InvariantCulture), StringComparison.Ordinal);
104 Channel = controlPanelChannel,
112 ArgumentNullException.ThrowIfNull(context);
115 var headers = context.HttpContext.Response.Headers;
116 if (headers.TryGetValue(HeaderNames.Vary, out var oldValues))
117 headers.Remove(HeaderNames.Vary);
119 newValues.AddRange(oldValues);
121 headers.Add(HeaderNames.Vary,
new StringValues(newValues.ToArray()));
123 return base.OnActionExecutionAsync(context, next);
131 [Route(
"{**appRoute}")]
133 public IActionResult
Get([FromRoute]
string appRoute)
137 logger.LogDebug(
"Not serving static files as control panel is disabled.");
145 if (foundFile !=
null)
148 logger.LogTrace(
"Requested static file \"{filename}\" does not exist! Redirecting to index...", appRoute);
150 return File(
"index.html", MediaTypeNames.Text.Html);
Controller for the web control panel.
IActionResult GetChannelJson()
Returns the ControlPanelConfiguration.Channel.
readonly IOptionsSnapshot< ControlPanelConfiguration > controlPanelConfigurationOptions
The ControlPanelConfiguration for the ControlPanelController.
readonly IWebHostEnvironment hostEnvironment
The IWebHostEnvironment for the ControlPanelController.
const string ControlPanelRoute
Route to the ControlPanelController.
IActionResult Get([FromRoute] string appRoute)
Handle a GET request to the control panel route. Route to static files if they exist,...
override Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next)
const string FetchChannelVaryHeader
Header for forcing channel.json to be fetched.
readonly ILogger< ControlPanelController > logger
The ILogger for the ControlPanelController.
ControlPanelController(IWebHostEnvironment hostEnvironment, IOptionsSnapshot< ControlPanelConfiguration > controlPanelConfigurationOptions, ILogger< ControlPanelController > logger)
Initializes a new instance of the ControlPanelController class.
const string ChannelJsonRoute
The route to the control panel channel .json.