2using System.Collections.Generic;
3using System.Linq.Expressions;
5using Microsoft.AspNetCore.Authorization;
6using Microsoft.AspNetCore.Hosting;
7using Microsoft.AspNetCore.Mvc;
8using Microsoft.Extensions.Logging;
9using Microsoft.Extensions.Options;
23 [ApiExplorerSettings(IgnoreApi =
true)]
54 readonly ILogger<RootController>
logger;
78 var memberSelectorExpression = (MethodCallExpression)actionExpression.Body;
79 var method = memberSelectorExpression.Method;
83 const string ControllerSuffix = nameof(
Controller);
84 if (controllerName.EndsWith(ControllerSuffix, StringComparison.Ordinal))
85 controllerName = controllerName.Substring(0, controllerName.Length - ControllerSuffix.Length);
87 var actionName = method.Name;
89 return Tuple.Create<string,
string?>(controllerName, actionName);
106 ILogger<RootController>
logger,
107 IOptions<GeneralConfiguration> generalConfigurationOptions,
108 IOptions<ControlPanelConfiguration> controlPanelConfigurationOptions,
109 IOptionsSnapshot<InternalConfiguration> internalConfigurationOptions)
114 this.logger =
logger ??
throw new ArgumentNullException(nameof(
logger));
115 generalConfiguration = generalConfigurationOptions?.Value ??
throw new ArgumentNullException(nameof(generalConfigurationOptions));
116 controlPanelConfiguration = controlPanelConfigurationOptions?.Value ??
throw new ArgumentNullException(nameof(controlPanelConfigurationOptions));
117 internalConfiguration = internalConfigurationOptions?.Value ??
throw new ArgumentNullException(nameof(internalConfigurationOptions));
131 var controlPanelRoute = $
"{ControlPanelController.ControlPanelRoute.TrimStart('/')}/";
132 if (panelEnabled && !apiDocsEnabled)
133 return Redirect(controlPanelRoute);
135 Dictionary<string, string>? links =
null;
137 if (panelEnabled || apiDocsEnabled)
139 links =
new Dictionary<string, string>();
142 links.Add(
"Web Control Panel", controlPanelRoute);
168 [HttpGet(
"logo.svg")]
181 return (IActionResult?)this.TryServeFile(
hostEnvironment,
logger, $
"{LogoSvgLinuxName}.svg") ?? NotFound();
193 return RedirectToActionPermanent(
Routes to a server actions.
const string GraphQL
The GraphQL route.
Configuration options for the web control panel.
bool Enable
If the control panel is enabled.
General configuration options.
bool HostApiDocumentation
If the swagger documentation and UI should be made avaiable.
Unstable configuration options used internally by TGS.
bool EnableGraphQL
Enables hosting the experimental GraphQL API in Release builds.
Controller for the web control panel.
const string ChannelJsonRoute
The route to the control panel channel .json.
The root path Controller.
const string LogoSvgWindowsName
The name of the TGS logo .svg in the IWebHostEnvironment.WebRootPath on Windows.
readonly IPlatformIdentifier platformIdentifier
The IPlatformIdentifier for the RootController.
readonly InternalConfiguration internalConfiguration
The InternalConfiguration for the RootController.
readonly ILogger< RootController > logger
The ILogger for the RootController.
readonly GeneralConfiguration generalConfiguration
The GeneralConfiguration for the RootController.
RedirectToActionResult WebpanelChannelRedirect()
Workaround for the webpanel always expecting a trailing slash.
IActionResult Index()
Gets the server's homepage.
readonly IAssemblyInformationProvider assemblyInformationProvider
The IAssemblyInformationProvider for the RootController.
RootController(IAssemblyInformationProvider assemblyInformationProvider, IPlatformIdentifier platformIdentifier, IWebHostEnvironment hostEnvironment, ILogger< RootController > logger, IOptions< GeneralConfiguration > generalConfigurationOptions, IOptions< ControlPanelConfiguration > controlPanelConfigurationOptions, IOptionsSnapshot< InternalConfiguration > internalConfigurationOptions)
Initializes a new instance of the RootController class.
const string LogoSvgLinuxName
The name of the TGS logo .svg in the IWebHostEnvironment.WebRootPath on Linux.
readonly IWebHostEnvironment hostEnvironment
THe IWebHostEnvironment for the RootController.
static Tuple< string, string?> GetControlPanelActionLink(Expression< Func< ControlPanelController, IActionResult > > actionExpression)
Gets a Tuple<T1, T2> giving the ControlPanelController and action names for a given actionExpression ...
IActionResult GetLogo()
Retrieve the logo .svg for the webpanel.
readonly ControlPanelConfiguration controlPanelConfiguration
The ControlPanelConfiguration for the RootController.
Implements various filters for Swashbuckle.
const string DocumentationSiteRouteExtension
The path to the hosted documentation site.