mirror of
https://github.com/JustArchiNET/ArchiSteamFarm
synced 2024-11-10 07:04:27 +00:00
Add /Api/WWW/Directory
This commit is contained in:
parent
107a75fd61
commit
423200fd38
2 changed files with 69 additions and 0 deletions
|
@ -422,6 +422,7 @@
|
|||
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=WCF/@EntryIndexedValue">WCF</s:String>
|
||||
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=WS/@EntryIndexedValue">WS</s:String>
|
||||
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=WTF/@EntryIndexedValue">WTF</s:String>
|
||||
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=WWW/@EntryIndexedValue">WWW</s:String>
|
||||
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=XML/@EntryIndexedValue">XML</s:String>
|
||||
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/PredefinedNamingRules/=PrivateConstants/@EntryIndexedValue"><Policy Inspect="True" Prefix="" Suffix="" Style="AaBb"><ExtraRule Prefix="I" Suffix="" Style="AaBb" /></Policy></s:String>
|
||||
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/PredefinedNamingRules/=PrivateInstanceFields/@EntryIndexedValue"><Policy Inspect="True" Prefix="" Suffix="" Style="AaBb"><ExtraRule Prefix="_" Suffix="" Style="AaBb" /><ExtraRule Prefix="_" Suffix="" Style="aaBb" /></Policy></s:String>
|
||||
|
|
|
@ -183,6 +183,8 @@ namespace ArchiSteamFarm {
|
|||
return await HandleApiStructure(context.Request, context.Response, arguments, ++argumentsIndex).ConfigureAwait(false);
|
||||
case "Type/":
|
||||
return await HandleApiType(context.Request, context.Response, arguments, ++argumentsIndex).ConfigureAwait(false);
|
||||
case "WWW/":
|
||||
return await HandleApiWWW(context.Request, context.Response, arguments, ++argumentsIndex).ConfigureAwait(false);
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
|
@ -725,6 +727,72 @@ namespace ArchiSteamFarm {
|
|||
return true;
|
||||
}
|
||||
|
||||
private static async Task<bool> HandleApiWWW(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;
|
||||
}
|
||||
|
||||
switch (arguments[argumentsIndex]) {
|
||||
case "Directory/":
|
||||
return await HandleApiWWWDirectory(request, response, arguments, ++argumentsIndex).ConfigureAwait(false);
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private static async Task<bool> HandleApiWWWDirectory(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 HandleApiWWWDirectoryGet(request, response, arguments, argumentsIndex).ConfigureAwait(false);
|
||||
default:
|
||||
await ResponseStatusCode(request, response, HttpStatusCode.MethodNotAllowed).ConfigureAwait(false);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
private static async Task<bool> HandleApiWWWDirectoryGet(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 argument = WebUtility.UrlDecode(string.Join("", arguments.Skip(argumentsIndex)));
|
||||
|
||||
string directory = Path.Combine(SharedInfo.WebsiteDirectory, argument);
|
||||
if (!Directory.Exists(directory)) {
|
||||
await ResponseJsonObject(request, response, new GenericResponse(false, string.Format(Strings.ErrorIsInvalid, nameof(directory))), HttpStatusCode.BadRequest).ConfigureAwait(false);
|
||||
return true;
|
||||
}
|
||||
|
||||
string[] files;
|
||||
|
||||
try {
|
||||
files = Directory.GetFiles(directory);
|
||||
} catch (Exception e) {
|
||||
await ResponseJsonObject(request, response, new GenericResponse(false, string.Format(Strings.ErrorParsingObject, nameof(files)) + Environment.NewLine + e), HttpStatusCode.BadRequest).ConfigureAwait(false);
|
||||
return true;
|
||||
}
|
||||
|
||||
HashSet<string> result = new HashSet<string>(files.Select(Path.GetFileName));
|
||||
|
||||
await ResponseJsonObject(request, response, new GenericResponse(true, "OK", result)).ConfigureAwait(false);
|
||||
return true;
|
||||
}
|
||||
|
||||
private static async Task<bool> HandleFile(HttpListenerRequest request, HttpListenerResponse response, string absolutePath) {
|
||||
if ((request == null) || (response == null) || string.IsNullOrEmpty(absolutePath)) {
|
||||
ASF.ArchiLogger.LogNullError(nameof(request) + " || " + nameof(response) + " || " + nameof(absolutePath));
|
||||
|
|
Loading…
Reference in a new issue