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.AspNetCore.StaticFiles;
11using Microsoft.Extensions.Options;
12using Microsoft.Extensions.Primitives;
13using Microsoft.Net.Http.Headers;
23 [Route(ControlPanelRoute)]
24 [ApiExplorerSettings(IgnoreApi =
true)]
55 controlPanelConfiguration = controlPanelConfigurationOptions?.Value ??
throw new ArgumentNullException(nameof(controlPanelConfigurationOptions));
62 [Route(
"channel.json")]
70 if (controlPanelChannel ==
"local")
72 else if (String.IsNullOrWhiteSpace(controlPanelChannel))
73 controlPanelChannel =
null;
75 controlPanelChannel = controlPanelChannel
76 .Replace(
"${Major}",
ApiHeaders.
Version.Major.ToString(CultureInfo.InvariantCulture), StringComparison.Ordinal)
77 .Replace(
"${Minor}",
ApiHeaders.
Version.Minor.ToString(CultureInfo.InvariantCulture), StringComparison.Ordinal)
78 .Replace(
"${Patch}",
ApiHeaders.
Version.Build.ToString(CultureInfo.InvariantCulture), StringComparison.Ordinal);
83 Channel = controlPanelChannel,
91 ArgumentNullException.ThrowIfNull(context);
94 var headers = context.HttpContext.Response.Headers;
95 if (headers.TryGetValue(HeaderNames.Vary, out var oldValues))
96 headers.Remove(HeaderNames.Vary);
98 newValues.AddRange(oldValues);
100 headers.Add(HeaderNames.Vary,
new StringValues(newValues.ToArray()));
102 return base.OnActionExecutionAsync(context, next);
110 [Route(
"{**appRoute}")]
112 public IActionResult
Get([FromRoute]
string appRoute)
120 var fileInfo =
hostEnvironment.WebRootFileProvider.GetFileInfo(appRoute);
123 var contentTypeProvider =
new FileExtensionContentTypeProvider();
124 if (!contentTypeProvider.TryGetContentType(fileInfo.Name, out var contentType))
125 contentType = MediaTypeNames.Application.Octet;
126 else if (contentType == MediaTypeNames.Application.Json)
127 Response.Headers.Add(
128 HeaderNames.CacheControl,
129 new StringValues(
new[] {
"public",
"max-age=31536000",
"immutable" }));
131 return File(appRoute, contentType);
134 return File(
"index.html", MediaTypeNames.Text.Html);
Configuration options for the web control panel.
bool Enable
If the control panel is enabled.
string Channel
The channel to retrieve the webpanel from. "local" uses the bundled version.
string PublicPath
The public path to the TGS control panel from a wider network.
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 ControlPanelConfiguration controlPanelConfiguration
The ControlPanelConfiguration for the ControlPanelController.
ControlPanelController(IWebHostEnvironment hostEnvironment, IOptions< ControlPanelConfiguration > controlPanelConfigurationOptions)
Initializes a new instance of the ControlPanelController class.