Add target channel to update command and public API

This commit is contained in:
Archi
2022-12-23 22:12:18 +01:00
parent 4f5dfce269
commit 8d5653b41e
5 changed files with 73 additions and 9 deletions

View File

@@ -173,8 +173,14 @@ public sealed class ASFController : ArchiController {
/// </summary>
[HttpPost("Update")]
[ProducesResponseType(typeof(GenericResponse<string>), (int) HttpStatusCode.OK)]
public async Task<ActionResult<GenericResponse<string>>> UpdatePost() {
(bool success, string? message, Version? version) = await Actions.Update().ConfigureAwait(false);
public async Task<ActionResult<GenericResponse<string>>> UpdatePost([FromBody] UpdateRequest request) {
ArgumentNullException.ThrowIfNull(request);
if (request.Channel.HasValue && !Enum.IsDefined(request.Channel.Value)) {
return BadRequest(new GenericResponse(false, string.Format(CultureInfo.CurrentCulture, Strings.ErrorIsInvalid, nameof(request.Channel))));
}
(bool success, string? message, Version? version) = await Actions.Update(request.Channel).ConfigureAwait(false);
if (string.IsNullOrEmpty(message)) {
message = success ? Strings.Success : Strings.WarningFailed;

View File

@@ -0,0 +1,38 @@
// _ _ _ ____ _ _____
// / \ _ __ ___ | |__ (_)/ ___| | |_ ___ __ _ _ __ ___ | ___|__ _ _ __ _ __ ___
// / _ \ | '__|/ __|| '_ \ | |\___ \ | __|/ _ \ / _` || '_ ` _ \ | |_ / _` || '__|| '_ ` _ \
// / ___ \ | | | (__ | | | || | ___) || |_| __/| (_| || | | | | || _|| (_| || | | | | | | |
// /_/ \_\|_| \___||_| |_||_||____/ \__|\___| \__,_||_| |_| |_||_| \__,_||_| |_| |_| |_|
// |
// Copyright 2015-2022 Łukasz "JustArchi" Domeradzki
// Contact: JustArchi@JustArchi.net
// |
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// |
// http://www.apache.org/licenses/LICENSE-2.0
// |
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
using System.Diagnostics.CodeAnalysis;
using ArchiSteamFarm.Storage;
using Newtonsoft.Json;
namespace ArchiSteamFarm.IPC.Requests;
[SuppressMessage("ReSharper", "ClassCannotBeInstantiated")]
public sealed class UpdateRequest {
/// <summary>
/// Target update channel. Not required, will default to UpdateChannel in GlobalConfig if not provided.
/// </summary>
[JsonProperty(Required = Required.DisallowNull)]
public GlobalConfig.EUpdateChannel? Channel { get; private set; }
[JsonConstructor]
private UpdateRequest() { }
}