mirror of
https://github.com/JustArchiNET/ArchiSteamFarm.git
synced 2026-01-16 08:25:28 +00:00
Closes #1314
This commit is contained in:
@@ -23,6 +23,7 @@ using System;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Threading.Tasks;
|
||||
using ArchiSteamFarm.IPC.Requests;
|
||||
using ArchiSteamFarm.IPC.Responses;
|
||||
using ArchiSteamFarm.Localization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
@@ -37,14 +38,19 @@ namespace ArchiSteamFarm.IPC.Controllers.Api {
|
||||
/// This API endpoint is supposed to be entirely replaced by ASF actions available under /Api/ASF/{action} and /Api/Bot/{bot}/{action}.
|
||||
/// You should use "given bot" commands when executing this endpoint, omitting targets of the command will cause the command to be executed on first defined bot
|
||||
/// </remarks>
|
||||
[HttpPost("{command:required}")]
|
||||
[Consumes("application/json")]
|
||||
[HttpPost]
|
||||
[ProducesResponseType(typeof(GenericResponse<string>), (int) HttpStatusCode.OK)]
|
||||
[ProducesResponseType(typeof(GenericResponse), (int) HttpStatusCode.BadRequest)]
|
||||
public async Task<ActionResult<GenericResponse>> CommandPost(string command) {
|
||||
if (string.IsNullOrEmpty(command)) {
|
||||
ASF.ArchiLogger.LogNullError(nameof(command));
|
||||
public async Task<ActionResult<GenericResponse>> CommandPost([FromBody] CommandRequest request) {
|
||||
if (request == null) {
|
||||
ASF.ArchiLogger.LogNullError(nameof(request));
|
||||
|
||||
return BadRequest(new GenericResponse(false, string.Format(Strings.ErrorIsEmpty, nameof(command))));
|
||||
return BadRequest(new GenericResponse(false, string.Format(Strings.ErrorIsEmpty, nameof(request))));
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(request.Command)) {
|
||||
return BadRequest(new GenericResponse(false, string.Format(Strings.ErrorIsEmpty, nameof(request.Command))));
|
||||
}
|
||||
|
||||
if (ASF.GlobalConfig.SteamOwnerID == 0) {
|
||||
@@ -57,6 +63,8 @@ namespace ArchiSteamFarm.IPC.Controllers.Api {
|
||||
return BadRequest(new GenericResponse(false, Strings.ErrorNoBotsDefined));
|
||||
}
|
||||
|
||||
string command = request.Command;
|
||||
|
||||
if (!string.IsNullOrEmpty(ASF.GlobalConfig.CommandPrefix) && command.StartsWith(ASF.GlobalConfig.CommandPrefix, StringComparison.Ordinal)) {
|
||||
command = command.Substring(ASF.GlobalConfig.CommandPrefix.Length);
|
||||
|
||||
@@ -69,5 +77,26 @@ namespace ArchiSteamFarm.IPC.Controllers.Api {
|
||||
|
||||
return Ok(new GenericResponse<string>(response));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Executes a command.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This API endpoint is supposed to be entirely replaced by ASF actions available under /Api/ASF/{action} and /Api/Bot/{bot}/{action}.
|
||||
/// You should use "given bot" commands when executing this endpoint, omitting targets of the command will cause the command to be executed on first defined bot
|
||||
/// </remarks>
|
||||
[HttpPost("{command:required}")]
|
||||
[Obsolete]
|
||||
[ProducesResponseType(typeof(GenericResponse<string>), (int) HttpStatusCode.OK)]
|
||||
[ProducesResponseType(typeof(GenericResponse), (int) HttpStatusCode.BadRequest)]
|
||||
public async Task<ActionResult<GenericResponse>> ObsoleteCommandPost(string command) {
|
||||
if (string.IsNullOrEmpty(command)) {
|
||||
ASF.ArchiLogger.LogNullError(nameof(command));
|
||||
|
||||
return BadRequest(new GenericResponse(false, string.Format(Strings.ErrorIsEmpty, nameof(command))));
|
||||
}
|
||||
|
||||
return await CommandPost(new CommandRequest(command)).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user