From d636d06ced71e3af09096e8382189299502be2c1 Mon Sep 17 00:00:00 2001 From: Timothy Baldridge Date: Fri, 22 Nov 2019 15:00:34 -0700 Subject: [PATCH] Added extensions to the game enum, fixed the cache server (again) --- Wabbajack.CacheServer/NexusCacheModule.cs | 43 +++++++++++++++-------- Wabbajack.Common/GameMetaData.cs | 8 +++++ Wabbajack.Lib/NexusApi/NexusApi.cs | 2 +- 3 files changed, 37 insertions(+), 16 deletions(-) diff --git a/Wabbajack.CacheServer/NexusCacheModule.cs b/Wabbajack.CacheServer/NexusCacheModule.cs index 88213c19..e0d3cfde 100644 --- a/Wabbajack.CacheServer/NexusCacheModule.cs +++ b/Wabbajack.CacheServer/NexusCacheModule.cs @@ -75,24 +75,37 @@ namespace Wabbajack.CacheServer private string HandleCacheCall(dynamic arg) { - string param = (string)arg.request; - var url = new Uri(Encoding.UTF8.GetString(param.FromHex())); - var path = Path.Combine(NexusApiClient.LocalCacheDir, arg.request + ".json"); - - if (!File.Exists(path)) + try { - Utils.Log($"{DateTime.Now} - Not Cached - {url}"); - var client = new HttpClient(); - var builder = new UriBuilder(url) {Host = "localhost", Port = Request.Url.Port ?? 80}; - client.DefaultRequestHeaders.Add("apikey", Request.Headers["apikey"]); - client.GetStringSync(builder.Uri.ToString()); + string param = (string)arg.request; + var url = new Uri(Encoding.UTF8.GetString(param.FromHex())); + var path = Path.Combine(NexusApiClient.LocalCacheDir, arg.request + ".json"); + if (!File.Exists(path)) - throw new InvalidDataException("Invalid Data"); + { + Utils.Log($"{DateTime.Now} - Not Cached - {url}"); + var client = new HttpClient(); + var builder = new UriBuilder(url) {Host = "localhost", Port = Request.Url.Port ?? 8080, Scheme = "http"}; + client.DefaultRequestHeaders.Add("apikey", Request.Headers["apikey"]); + client.GetStringSync(builder.Uri.ToString()); + if (!File.Exists(path)) + { + Utils.Log($"Still not cached : {path}"); + throw new InvalidDataException("Invalid Data"); + } + + Utils.Log($"Is Now Cached : {path}"); + + } + + Utils.Log($"{DateTime.Now} - From Cached - {url}"); + return File.ReadAllText(path); + } + catch (Exception ex) + { + Utils.Log(ex.ToString()); + return "ERROR"; } - - Utils.Log($"{DateTime.Now} - From Cached - {url}"); - return File.ReadAllText(path); - } } } diff --git a/Wabbajack.Common/GameMetaData.cs b/Wabbajack.Common/GameMetaData.cs index ffbc8015..c3789ecb 100644 --- a/Wabbajack.Common/GameMetaData.cs +++ b/Wabbajack.Common/GameMetaData.cs @@ -41,6 +41,14 @@ namespace Wabbajack.Common Witcher3 } + public static class GameExtentions + { + public static GameMetaData MetaData(this Game game) + { + return GameRegistry.Games[game]; + } + } + public class GameMetaData { public ModManager SupportedModManager { get; internal set; } diff --git a/Wabbajack.Lib/NexusApi/NexusApi.cs b/Wabbajack.Lib/NexusApi/NexusApi.cs index 5beef59a..91c02f90 100644 --- a/Wabbajack.Lib/NexusApi/NexusApi.cs +++ b/Wabbajack.Lib/NexusApi/NexusApi.cs @@ -303,7 +303,7 @@ namespace Wabbajack.Lib.NexusApi public ModInfo GetModInfo(Game game, string modId) { - var url = $"https://api.nexusmods.com/v1/games/{GameRegistry.Games[game].NexusName}/mods/{modId}.json"; + var url = $"https://api.nexusmods.com/v1/games/{game.MetaData().NexusName}/mods/{modId}.json"; return GetCached(url); }