2020-01-18 22:09:32 +00:00
|
|
|
|
using System;
|
2020-02-01 05:41:09 +00:00
|
|
|
|
using System.Collections;
|
|
|
|
|
using System.Collections.Generic;
|
2020-01-22 03:43:53 +00:00
|
|
|
|
using System.IO;
|
2020-02-13 12:29:59 +00:00
|
|
|
|
using System.IO.Compression;
|
2020-01-22 03:43:53 +00:00
|
|
|
|
using System.Linq;
|
2020-01-30 04:29:20 +00:00
|
|
|
|
using System.Net;
|
2020-01-19 05:51:12 +00:00
|
|
|
|
using System.Net.Http;
|
2020-01-18 22:09:32 +00:00
|
|
|
|
using System.Reactive.Linq;
|
2020-02-13 12:29:59 +00:00
|
|
|
|
using System.Text;
|
2020-01-29 23:41:53 +00:00
|
|
|
|
using System.Threading;
|
2020-01-19 05:51:12 +00:00
|
|
|
|
using System.Threading.Tasks;
|
2020-01-18 22:09:32 +00:00
|
|
|
|
using Wabbajack.Common;
|
2020-02-13 12:29:59 +00:00
|
|
|
|
using Wabbajack.Lib.Downloaders;
|
2020-01-22 03:43:53 +00:00
|
|
|
|
using File = Alphaleonis.Win32.Filesystem.File;
|
|
|
|
|
using Path = Alphaleonis.Win32.Filesystem.Path;
|
2020-01-18 22:09:32 +00:00
|
|
|
|
|
|
|
|
|
namespace Wabbajack.Lib.FileUploader
|
|
|
|
|
{
|
|
|
|
|
public class AuthorAPI
|
|
|
|
|
{
|
2020-04-05 21:15:01 +00:00
|
|
|
|
public static IObservable<bool> HaveAuthorAPIKey => Utils.HaveEncryptedJsonObservable(Consts.AuthorAPIKeyFile);
|
2020-01-18 22:09:32 +00:00
|
|
|
|
|
2020-04-10 01:29:53 +00:00
|
|
|
|
public static string? ApiKeyOverride = null;
|
2020-04-08 04:19:36 +00:00
|
|
|
|
|
2020-04-10 01:29:53 +00:00
|
|
|
|
public static async Task<string> GetAPIKey(string? apiKey = null)
|
2020-01-18 22:09:32 +00:00
|
|
|
|
{
|
2020-04-08 04:19:36 +00:00
|
|
|
|
if (ApiKeyOverride != null) return ApiKeyOverride;
|
2020-04-05 21:15:01 +00:00
|
|
|
|
return apiKey ?? (await Consts.LocalAppDataPath.Combine(Consts.AuthorAPIKeyFile).ReadAllTextAsync()).Trim();
|
2020-01-18 22:09:32 +00:00
|
|
|
|
}
|
2020-05-09 22:16:16 +00:00
|
|
|
|
|
2020-06-26 17:08:30 +00:00
|
|
|
|
public static async Task<Wabbajack.Lib.Http.Client> GetAuthorizedClient(string? apiKey = null)
|
2020-02-11 05:04:56 +00:00
|
|
|
|
{
|
2020-06-26 17:08:30 +00:00
|
|
|
|
var client = new Wabbajack.Lib.Http.Client();
|
2020-03-30 20:38:46 +00:00
|
|
|
|
client.Headers.Add(("X-API-KEY", await GetAPIKey(apiKey)));
|
2020-02-11 05:04:56 +00:00
|
|
|
|
return client;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static async Task<string> RunJob(string jobtype)
|
|
|
|
|
{
|
2020-03-25 22:30:43 +00:00
|
|
|
|
var client = await GetAuthorizedClient();
|
2020-04-08 04:19:36 +00:00
|
|
|
|
return await client.GetStringAsync($"{Consts.WabbajackBuildServerUri}jobs/enqueue_job/{jobtype}");
|
2020-02-11 05:04:56 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static async Task<string> UpdateNexusCache()
|
|
|
|
|
{
|
|
|
|
|
return await RunJob("GetNexusUpdatesJob");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static async Task<string> UpdateServerModLists()
|
|
|
|
|
{
|
|
|
|
|
return await RunJob("UpdateModLists");
|
|
|
|
|
}
|
2020-02-13 12:29:59 +00:00
|
|
|
|
|
2020-02-25 23:10:41 +00:00
|
|
|
|
public static async Task<string> GetServerLog()
|
|
|
|
|
{
|
2020-04-30 21:43:54 +00:00
|
|
|
|
return await (await GetAuthorizedClient()).GetStringAsync($"{Consts.WabbajackBuildServerUri}heartbeat/logs");
|
2020-02-25 23:10:41 +00:00
|
|
|
|
}
|
2020-03-02 23:16:15 +00:00
|
|
|
|
|
|
|
|
|
public static async Task<IEnumerable<string>> GetMyFiles()
|
|
|
|
|
{
|
2020-04-30 21:43:54 +00:00
|
|
|
|
return (await (await GetAuthorizedClient()).GetStringAsync($"{Consts.WabbajackBuildServerUri}uploaded_files/list")).FromJsonString<string[]>();
|
2020-03-02 23:16:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static async Task<string> DeleteFile(string name)
|
|
|
|
|
{
|
2020-03-25 22:30:43 +00:00
|
|
|
|
var result = await (await GetAuthorizedClient())
|
2020-04-30 21:43:54 +00:00
|
|
|
|
.DeleteStringAsync($"{Consts.WabbajackBuildServerUri}uploaded_files/{name}");
|
2020-03-02 23:16:15 +00:00
|
|
|
|
return result;
|
|
|
|
|
}
|
2020-07-08 20:48:48 +00:00
|
|
|
|
|
|
|
|
|
public static async Task<string> PurgeNexusModInfo(long modId)
|
|
|
|
|
{
|
|
|
|
|
return await (await GetAuthorizedClient()).GetStringAsync($"{Consts.WabbajackBuildServerUri}purge_nexus_cache/{modId}");
|
|
|
|
|
}
|
2020-08-06 22:40:07 +00:00
|
|
|
|
|
|
|
|
|
public static async Task<string> NoPatch(Hash hash, string rationale)
|
|
|
|
|
{
|
|
|
|
|
var client = await GetAuthorizedClient();
|
|
|
|
|
return await client.GetStringAsync(
|
|
|
|
|
$"{Consts.WabbajackBuildServerUri}mod_upgrade/no_patch/{hash.ToHex()}/{Encoding.UTF8.GetBytes(rationale).ToHex()}");
|
|
|
|
|
}
|
2020-01-18 22:09:32 +00:00
|
|
|
|
}
|
|
|
|
|
}
|