Added extensions to the game enum, fixed the cache server (again)

This commit is contained in:
Timothy Baldridge 2019-11-22 15:00:34 -07:00
parent 29f829329f
commit d636d06ced
3 changed files with 37 additions and 16 deletions

View File

@ -74,6 +74,8 @@ namespace Wabbajack.CacheServer
} }
private string HandleCacheCall(dynamic arg) private string HandleCacheCall(dynamic arg)
{
try
{ {
string param = (string)arg.request; string param = (string)arg.request;
var url = new Uri(Encoding.UTF8.GetString(param.FromHex())); var url = new Uri(Encoding.UTF8.GetString(param.FromHex()));
@ -83,16 +85,27 @@ namespace Wabbajack.CacheServer
{ {
Utils.Log($"{DateTime.Now} - Not Cached - {url}"); Utils.Log($"{DateTime.Now} - Not Cached - {url}");
var client = new HttpClient(); var client = new HttpClient();
var builder = new UriBuilder(url) {Host = "localhost", Port = Request.Url.Port ?? 80}; var builder = new UriBuilder(url) {Host = "localhost", Port = Request.Url.Port ?? 8080, Scheme = "http"};
client.DefaultRequestHeaders.Add("apikey", Request.Headers["apikey"]); client.DefaultRequestHeaders.Add("apikey", Request.Headers["apikey"]);
client.GetStringSync(builder.Uri.ToString()); client.GetStringSync(builder.Uri.ToString());
if (!File.Exists(path)) if (!File.Exists(path))
{
Utils.Log($"Still not cached : {path}");
throw new InvalidDataException("Invalid Data"); throw new InvalidDataException("Invalid Data");
} }
Utils.Log($"Is Now Cached : {path}");
}
Utils.Log($"{DateTime.Now} - From Cached - {url}"); Utils.Log($"{DateTime.Now} - From Cached - {url}");
return File.ReadAllText(path); return File.ReadAllText(path);
}
catch (Exception ex)
{
Utils.Log(ex.ToString());
return "ERROR";
}
} }
} }
} }

View File

@ -41,6 +41,14 @@ namespace Wabbajack.Common
Witcher3 Witcher3
} }
public static class GameExtentions
{
public static GameMetaData MetaData(this Game game)
{
return GameRegistry.Games[game];
}
}
public class GameMetaData public class GameMetaData
{ {
public ModManager SupportedModManager { get; internal set; } public ModManager SupportedModManager { get; internal set; }

View File

@ -303,7 +303,7 @@ namespace Wabbajack.Lib.NexusApi
public ModInfo GetModInfo(Game game, string modId) 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<ModInfo>(url); return GetCached<ModInfo>(url);
} }