tgstation-server 6.19.0
The /tg/station 13 server suite
Loading...
Searching...
No Matches
AdministrationController.cs
Go to the documentation of this file.
1using System;
2using System.IO;
3using System.Linq;
6
11
25
27{
31 [Authorize]
34 {
39
44
49
54
59
95
105 [HttpGet]
111 this,
112 authority => authority.GetUpdateInformation(fresh ?? false, cancellationToken));
113
125 [HttpPost]
132 {
133 ArgumentNullException.ThrowIfNull(model);
134
135 if (model.NewVersion == null)
136 return BadRequest(new ErrorMessageResponse(ErrorCode.ModelValidationFailure)
137 {
138 AdditionalData = "newVersion is required!",
139 });
140
142 this,
143 authority => authority.TriggerServerVersionChange(model.NewVersion, model.UploadZip ?? false, cancellationToken));
144 }
145
152 [HttpDelete]
156#pragma warning disable API1001 // Action returns undeclared success result
158 this,
159 authority => authority.TriggerServerRestart());
160#pragma warning restore API1001 // Action returns undeclared success result
161
172 [TgsAuthorize(AdministrationRights.DownloadLogs)]
176 => Paginated(
177 async () =>
178 {
180 try
181 {
182 var files = await ioManager.GetFiles(path, cancellationToken);
183 var tasks = files.Select(
185 {
186 Name = ioManager.GetFileName(file),
187 LastModified = await ioManager
188 .GetLastModified(
190 cancellationToken),
191 })
192 .ToList();
193
194 await Task.WhenAll(tasks);
195
197 tasks
198 .AsQueryable()
199 .Select(x => x.Result)
200 .OrderByDescending(x => x.Name));
201 }
202 catch (IOException ex)
203 {
205 Conflict(new ErrorMessageResponse(ErrorCode.IOError)
206 {
207 AdditionalData = ex.ToString(),
208 }));
209 }
210 },
211 null,
212 page,
213 pageSize,
214 cancellationToken);
215
224 [HttpGet(Routes.Logs + "/{*path}")]
225 [TgsAuthorize(AdministrationRights.DownloadLogs)]
228 public ValueTask<IActionResult> GetLog(string path, CancellationToken cancellationToken)
230 this,
231 authority => authority.GetLog(path, cancellationToken));
232 }
233}
Represents an error message returned by the server.
Routes to a server actions.
Definition Routes.cs:9
const string Administration
The server administration controller.
Definition Routes.cs:28
const string Logs
The endpoint to download server logs.
Definition Routes.cs:33
AdministrationController(IDatabaseContext databaseContext, IAuthenticationContext authenticationContext, IApiHeadersProvider apiHeadersProvider, ILogger< AdministrationController > logger, IRestAuthorityInvoker< IAdministrationAuthority > administrationAuthority, IAssemblyInformationProvider assemblyInformationProvider, IIOManager ioManager, IPlatformIdentifier platformIdentifier, IOptions< FileLoggingConfiguration > fileLoggingConfigurationOptions)
Initializes a new instance of the AdministrationController class.
readonly IRestAuthorityInvoker< IAdministrationAuthority > administrationAuthority
The IRestAuthorityInvoker<TAuthority> for the IAdministrationAuthority.
ValueTask< IActionResult > Read([FromQuery] bool? fresh, CancellationToken cancellationToken)
Get AdministrationResponse server information.
ValueTask< IActionResult > ListLogs([FromQuery] int? page, [FromQuery] int? pageSize, CancellationToken cancellationToken)
List LogFileResponses present.
ValueTask< IActionResult > AdministrationResponse(this, authority=> authority.GetUpdateInformation(fresh ?? false, cancellationToken))
readonly IAssemblyInformationProvider assemblyInformationProvider
The IAssemblyInformationProvider for the AdministrationController.
ValueTask< IActionResult > LogFileResponse(this, authority=> authority.GetLog(path, cancellationToken))
ValueTask< IActionResult > Delete()
Attempts to restart the server.
async ValueTask< IActionResult > Update([FromBody] ServerUpdateRequest model, CancellationToken cancellationToken)
Attempt to perform a server upgrade.
ValueTask< IActionResult > GetLog(string path, CancellationToken cancellationToken)
Download a LogFileResponse.
readonly IOptions< FileLoggingConfiguration > fileLoggingConfigurationOptions
The IOptions<TOptions> FileLoggingConfiguration for the AdministrationController.
readonly IPlatformIdentifier platformIdentifier
The IPlatformIdentifier for the AdministrationController.
readonly IIOManager ioManager
The IIOManager for the AdministrationController.
Base Controller for API functions.
Invokes TAuthority methods and generates IActionResult responses.
ValueTask< IActionResult > Invoke(ApiController controller, Func< TAuthority, RequirementsGated< AuthorityResponse > > authorityInvoker)
Invoke a TAuthority method with no success result.
Interface for using filesystems.
Definition IIOManager.cs:14
Task< IReadOnlyList< string > > GetFiles(string path, CancellationToken cancellationToken)
Returns full file names in a given path .
string GetFileName(string path)
Gets the file name portion of a path .
string ConcatPath(params string[] paths)
Combines an array of strings into a path.
For creating and accessing authentication contexts.
For identifying the current platform.
ErrorCode
Types of Response.ErrorMessageResponses that the API may return.
Definition ErrorCode.cs:12
@ List
User may list files if the Models.Instance allows it.
AdministrationRights
Administration rights for the server.