mirror of
https://github.com/JustArchiNET/ArchiSteamFarm
synced 2024-11-10 07:04:27 +00:00
Add /Api/ASF, #732
This commit is contained in:
parent
4eafb41bb7
commit
1deb5e0d0a
2 changed files with 48 additions and 0 deletions
|
@ -1,5 +1,6 @@
|
|||
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
|
||||
<s:Boolean x:Key="/Default/CodeEditing/TypingAssist/SmartIndentOnEnter/@EntryValue">False</s:Boolean>
|
||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=CF84911C_002D2C4C_002D4195_002D8AF3_002DABBB6D3DE9AA_002Fd_003Awww/@EntryIndexedValue">ExplicitlyExcluded</s:String>
|
||||
<s:Boolean x:Key="/Default/CodeInspection/Highlighting/IncludeWarningsInSwea/@EntryValue">True</s:Boolean>
|
||||
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=AnnotateCanBeNullParameter/@EntryIndexedValue">SUGGESTION</s:String>
|
||||
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=AnnotateCanBeNullTypeMember/@EntryIndexedValue">SUGGESTION</s:String>
|
||||
|
|
|
@ -111,6 +111,8 @@ namespace ArchiSteamFarm {
|
|||
}
|
||||
|
||||
switch (arguments[argumentsIndex]) {
|
||||
case "ASF":
|
||||
return await HandleApiASF(request, response, arguments, ++argumentsIndex).ConfigureAwait(false);
|
||||
case "Bot/":
|
||||
return await HandleApiBot(request, response, arguments, ++argumentsIndex).ConfigureAwait(false);
|
||||
case "Command":
|
||||
|
@ -125,6 +127,34 @@ namespace ArchiSteamFarm {
|
|||
}
|
||||
}
|
||||
|
||||
private static async Task<bool> HandleApiASF(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 HandleApiASFGet(request, response, arguments, argumentsIndex).ConfigureAwait(false);
|
||||
default:
|
||||
await ResponseStatusCode(request, response, HttpStatusCode.MethodNotAllowed).ConfigureAwait(false);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
private static async Task<bool> HandleApiASFGet(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;
|
||||
}
|
||||
|
||||
uint memoryUsage = (uint) GC.GetTotalMemory(true) / 1024;
|
||||
ASFResponse asfResponse = new ASFResponse(memoryUsage, SharedInfo.Version);
|
||||
|
||||
await ResponseJsonObject(request, response, new GenericResponse(true, "OK", asfResponse)).ConfigureAwait(false);
|
||||
return true;
|
||||
}
|
||||
|
||||
private static async Task<bool> HandleApiBot(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));
|
||||
|
@ -626,6 +656,23 @@ namespace ArchiSteamFarm {
|
|||
await ResponseString(request, response, text, "text/plain", statusCode).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
private sealed class ASFResponse {
|
||||
[JsonProperty]
|
||||
internal readonly uint MemoryUsage;
|
||||
|
||||
[JsonProperty]
|
||||
internal readonly Version Version;
|
||||
|
||||
internal ASFResponse(uint memoryUsage, Version version) {
|
||||
if ((memoryUsage == 0) || (version == null)) {
|
||||
throw new ArgumentNullException(nameof(memoryUsage) + " || " + nameof(version));
|
||||
}
|
||||
|
||||
MemoryUsage = memoryUsage;
|
||||
Version = version;
|
||||
}
|
||||
}
|
||||
|
||||
[SuppressMessage("ReSharper", "ClassCannotBeInstantiated")]
|
||||
private sealed class BotRequest {
|
||||
#pragma warning disable 649
|
||||
|
|
Loading…
Reference in a new issue