mirror of
https://github.com/wabbajack-tools/wabbajack.git
synced 2024-08-30 18:42:17 +00:00
fixes #95
This commit is contained in:
parent
fc60eadab3
commit
e4c1e264cd
@ -61,5 +61,7 @@ namespace Wabbajack.Common
|
||||
return headerString;
|
||||
}
|
||||
}
|
||||
|
||||
public static TimeSpan NexusCacheExpiry = new TimeSpan(1, 0, 0, 0);
|
||||
}
|
||||
}
|
@ -128,6 +128,8 @@ namespace Wabbajack.Test
|
||||
|
||||
var converted = state.ViaJSON();
|
||||
Assert.IsTrue(converted.Verify());
|
||||
// Exercise the cache code
|
||||
Assert.IsTrue(converted.Verify());
|
||||
var filename = Guid.NewGuid().ToString();
|
||||
|
||||
Assert.IsTrue(converted.IsWhitelisted(new ServerWhitelist { AllowedPrefixes = new List<string> () }));
|
||||
|
@ -103,8 +103,8 @@ namespace Wabbajack.Downloaders
|
||||
{
|
||||
try
|
||||
{
|
||||
new NexusApiClient().GetNexusDownloadLink(this, true);
|
||||
return true;
|
||||
var info = new NexusApiClient().GetFileInfo(this);
|
||||
return info.category_name != null;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
@ -9,7 +9,9 @@ using System.Net;
|
||||
using System.Net.Http;
|
||||
using System.Net.Http.Headers;
|
||||
using System.Reflection;
|
||||
using System.Runtime.Serialization.Json;
|
||||
using System.Security.Authentication;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Wabbajack.Common;
|
||||
using Wabbajack.Downloaders;
|
||||
@ -190,6 +192,20 @@ namespace Wabbajack.NexusApi
|
||||
}
|
||||
}
|
||||
|
||||
private T GetCached<T>(string url)
|
||||
{
|
||||
var code = Encoding.UTF8.GetBytes(url).ToHEX();
|
||||
var cache_file = Path.Combine(Consts.NexusCacheDirectory, code + ".json");
|
||||
if (File.Exists(cache_file) && DateTime.Now - File.GetLastWriteTime(cache_file) < Consts.NexusCacheExpiry)
|
||||
{
|
||||
return cache_file.FromJSON<T>();
|
||||
}
|
||||
|
||||
var result = Get<T>(url);
|
||||
result.ToJSON(cache_file);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
public string GetNexusDownloadLink(NexusDownloader.State archive, bool cache = false)
|
||||
{
|
||||
@ -223,7 +239,7 @@ namespace Wabbajack.NexusApi
|
||||
public NexusFileInfo GetFileInfo(NexusDownloader.State mod)
|
||||
{
|
||||
var url = $"https://api.nexusmods.com/v1/games/{ConvertGameName(mod.GameName)}/mods/{mod.ModID}/files/{mod.FileID}.json";
|
||||
return Get<NexusFileInfo>(url);
|
||||
return GetCached<NexusFileInfo>(url);
|
||||
}
|
||||
|
||||
public ModInfo GetModInfo(string gameName, string modId)
|
||||
|
Loading…
Reference in New Issue
Block a user