2020-02-27 13:46:34 +00:00
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using Wabbajack.Common;
|
2020-03-31 22:05:36 +00:00
|
|
|
|
using Wabbajack.Lib.Exceptions;
|
2020-02-27 13:46:34 +00:00
|
|
|
|
|
|
|
|
|
namespace Wabbajack.Lib
|
|
|
|
|
{
|
|
|
|
|
public class ClientAPI
|
|
|
|
|
{
|
|
|
|
|
public static Common.Http.Client GetClient()
|
|
|
|
|
{
|
|
|
|
|
var client = new Common.Http.Client();
|
2020-03-02 23:16:15 +00:00
|
|
|
|
if (Utils.HaveEncryptedJson(Consts.MetricsKeyHeader))
|
|
|
|
|
client.Headers.Add((Consts.MetricsKeyHeader, Utils.FromEncryptedJson<string>(Consts.MetricsKeyHeader)));
|
2020-02-27 13:46:34 +00:00
|
|
|
|
return client;
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-22 15:50:53 +00:00
|
|
|
|
public static async Task<Archive> GetModUpgrade(Hash hash)
|
2020-02-27 13:46:34 +00:00
|
|
|
|
{
|
|
|
|
|
using var response = await GetClient()
|
2020-04-10 03:54:02 +00:00
|
|
|
|
.GetAsync($"{Consts.WabbajackBuildServerUri}alternative/{hash.ToHex()}");
|
|
|
|
|
if (response.IsSuccessStatusCode)
|
|
|
|
|
{
|
|
|
|
|
return (await response.Content.ReadAsStringAsync()).FromJsonString<Archive>();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Utils.Log($"No Upgrade for {hash}");
|
|
|
|
|
Utils.Log(await response.Content.ReadAsStringAsync());
|
|
|
|
|
return null;
|
2020-02-27 13:46:34 +00:00
|
|
|
|
}
|
2020-03-31 22:05:36 +00:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Given an archive hash, search the Wabbajack server for a matching .ini file
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="hash"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public static async Task<string> GetModIni(Hash hash)
|
|
|
|
|
{
|
|
|
|
|
var client = new Common.Http.Client();
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
return await client.GetStringAsync(
|
|
|
|
|
$"{Consts.WabbajackBuildServerUri}indexed_files/{hash.ToHex()}/meta.ini");
|
|
|
|
|
}
|
|
|
|
|
catch (HttpException)
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-04-02 21:16:46 +00:00
|
|
|
|
|
|
|
|
|
public class NexusCacheStats
|
|
|
|
|
{
|
|
|
|
|
public long CachedCount { get; set; }
|
|
|
|
|
public long ForwardCount { get; set; }
|
|
|
|
|
public double CacheRatio { get; set; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static async Task<NexusCacheStats> GetNexusCacheStats()
|
|
|
|
|
{
|
|
|
|
|
return await GetClient()
|
|
|
|
|
.GetJsonAsync<NexusCacheStats>($"{Consts.WabbajackBuildServerUri}nexus_cache/stats");
|
|
|
|
|
}
|
2020-02-27 13:46:34 +00:00
|
|
|
|
}
|
|
|
|
|
}
|