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)]
46 readonly ILogger<ControlPanelController>
logger;
61 IOptions<ControlPanelConfiguration> controlPanelConfigurationOptions,
62 ILogger<ControlPanelController>
logger)
65 controlPanelConfiguration = controlPanelConfigurationOptions?.Value ??
throw new ArgumentNullException(nameof(controlPanelConfigurationOptions));
66 this.logger =
logger ??
throw new ArgumentNullException(nameof(
logger));
73 [Route(
"channel.json")]
79 logger.LogDebug(
"Not serving channel.json as control panel is disabled.");
84 logger.LogTrace(
"Generating channel.json for channel \"{channel}\"...", controlPanelChannel);
86 if (controlPanelChannel ==
"local")
88 else if (String.IsNullOrWhiteSpace(controlPanelChannel))
89 controlPanelChannel =
null;
91 controlPanelChannel = controlPanelChannel
92 .Replace(
"${Major}",
ApiHeaders.
Version.Major.ToString(CultureInfo.InvariantCulture), StringComparison.Ordinal)
93 .Replace(
"${Minor}",
ApiHeaders.
Version.Minor.ToString(CultureInfo.InvariantCulture), StringComparison.Ordinal)
94 .Replace(
"${Patch}",
ApiHeaders.
Version.Build.ToString(CultureInfo.InvariantCulture), StringComparison.Ordinal);
99 Channel = controlPanelChannel,
107 ArgumentNullException.ThrowIfNull(context);
110 var headers = context.HttpContext.Response.Headers;
111 if (headers.TryGetValue(HeaderNames.Vary, out var oldValues))
112 headers.Remove(HeaderNames.Vary);
114 newValues.AddRange(oldValues);
116 headers.Add(HeaderNames.Vary,
new StringValues(newValues.ToArray()));
118 return base.OnActionExecutionAsync(context, next);
126 [Route(
"{**appRoute}")]
128 public IActionResult
Get([FromRoute]
string appRoute)
132 logger.LogDebug(
"Not serving static files as control panel is disabled.");
140 if (foundFile !=
null)
143 logger.LogTrace(
"Requested static file \"{filename}\" does not exist! Redirecting to index...", appRoute);
145 return File(
"index.html", MediaTypeNames.Text.Html);
Configuration options for the web control panel.
bool Enable
If the control panel is enabled.
string? PublicPath
The public path to the TGS control panel from a wider network.
string? Channel
The channel to retrieve the webpanel from. "local" uses the bundled version.
Controller for the web control panel.
IActionResult GetChannelJson()
Returns the ControlPanelConfiguration.Channel.
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.
readonly ControlPanelConfiguration controlPanelConfiguration
The ControlPanelConfiguration for the ControlPanelController.
ControlPanelController(IWebHostEnvironment hostEnvironment, IOptions< ControlPanelConfiguration > controlPanelConfigurationOptions, ILogger< ControlPanelController > logger)
Initializes a new instance of the ControlPanelController class.