mirror of
https://github.com/JustArchiNET/ArchiSteamFarm.git
synced 2026-01-12 22:50:39 +00:00
Add GET /Api/Structure
This commit is contained in:
@@ -138,9 +138,6 @@ namespace ArchiSteamFarm {
|
||||
[JsonProperty]
|
||||
internal string SteamPassword { get; set; }
|
||||
|
||||
// This constructor is used only by deserializer
|
||||
private BotConfig() { }
|
||||
|
||||
public bool ShouldSerializeSteamLogin() => false;
|
||||
public bool ShouldSerializeSteamParentalPIN() => false;
|
||||
public bool ShouldSerializeSteamPassword() => false;
|
||||
|
||||
@@ -119,9 +119,6 @@ namespace ArchiSteamFarm {
|
||||
[JsonProperty(Required = Required.DisallowNull)]
|
||||
internal ProtocolTypes SteamProtocols { get; private set; } = ProtocolTypes.Tcp;
|
||||
|
||||
// This constructor is used only by deserializer
|
||||
private GlobalConfig() { }
|
||||
|
||||
internal static GlobalConfig Load(string filePath) {
|
||||
if (string.IsNullOrEmpty(filePath)) {
|
||||
ASF.ArchiLogger.LogNullError(nameof(filePath));
|
||||
|
||||
@@ -115,6 +115,8 @@ namespace ArchiSteamFarm {
|
||||
case "Command":
|
||||
case "Command/":
|
||||
return await HandleApiCommand(request, response, arguments, ++argumentsIndex).ConfigureAwait(false);
|
||||
case "Structure/":
|
||||
return await HandleApiStructure(request, response, arguments, ++argumentsIndex).ConfigureAwait(false);
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
@@ -321,6 +323,51 @@ namespace ArchiSteamFarm {
|
||||
return true;
|
||||
}
|
||||
|
||||
private static async Task<bool> HandleApiStructure(HttpListenerRequest request, HttpListenerResponse response, string[] arguments, byte argumentsIndex) {
|
||||
if ((request == null) || (response == null) || (arguments == null) || (argumentsIndex == 0)) {
|
||||
ASF.ArchiLogger.LogNullError(nameof(request) + " || " + nameof(response) + " || " + nameof(arguments) + " || " + nameof(argumentsIndex));
|
||||
return false;
|
||||
}
|
||||
|
||||
switch (request.HttpMethod) {
|
||||
case HttpMethods.Get:
|
||||
return await HandleApiStructureGet(request, response, arguments, argumentsIndex).ConfigureAwait(false);
|
||||
default:
|
||||
await ResponseStatusCode(request, response, HttpStatusCode.MethodNotAllowed).ConfigureAwait(false);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
private static async Task<bool> HandleApiStructureGet(HttpListenerRequest request, HttpListenerResponse response, string[] arguments, byte argumentsIndex) {
|
||||
if ((request == null) || (response == null) || (arguments == null) || (argumentsIndex == 0)) {
|
||||
ASF.ArchiLogger.LogNullError(nameof(request) + " || " + nameof(response) + " || " + nameof(arguments) + " || " + nameof(argumentsIndex));
|
||||
return false;
|
||||
}
|
||||
|
||||
if (arguments.Length <= argumentsIndex) {
|
||||
return false;
|
||||
}
|
||||
|
||||
string structure = WebUtility.UrlDecode(arguments[argumentsIndex]);
|
||||
|
||||
object obj;
|
||||
|
||||
switch (structure) {
|
||||
case nameof(BotConfig):
|
||||
obj = new BotConfig();
|
||||
break;
|
||||
case nameof(GlobalConfig):
|
||||
obj = new GlobalConfig();
|
||||
break;
|
||||
default:
|
||||
await ResponseJsonObject(request, response, new GenericResponse(false, string.Format(Strings.ErrorIsInvalid, nameof(structure))), HttpStatusCode.NotAcceptable).ConfigureAwait(false);
|
||||
return true;
|
||||
}
|
||||
|
||||
await ResponseJsonObject(request, response, new GenericResponse(true, "OK", obj)).ConfigureAwait(false);
|
||||
return true;
|
||||
}
|
||||
|
||||
private static async Task<bool> HandleAuthenticatedRequest(HttpListenerRequest request, HttpListenerResponse response) {
|
||||
if ((request == null) || (response == null)) {
|
||||
ASF.ArchiLogger.LogNullError(nameof(request) + " || " + nameof(response));
|
||||
|
||||
Reference in New Issue
Block a user