mirror of
https://github.com/wabbajack-tools/wabbajack.git
synced 2024-08-30 18:42:17 +00:00
Bugfixes to get the code to work on the server box
This commit is contained in:
parent
c45bd2928b
commit
936fee5d0c
@ -15,9 +15,13 @@ namespace Wabbajack.CacheServer
|
||||
Utils.LogMessages.Subscribe(Console.WriteLine);
|
||||
using (var server = new Server("http://localhost:8080"))
|
||||
{
|
||||
//ListValidationService.Start();
|
||||
var tsk = JobQueueEndpoints.StartJobQueue();
|
||||
Consts.WabbajackCacheHostname = "localhost";
|
||||
Consts.WabbajackCachePort = 8080;
|
||||
server.Start();
|
||||
|
||||
ListValidationService.Start();
|
||||
var tsk = JobQueueEndpoints.StartJobQueue();
|
||||
|
||||
Console.ReadLine();
|
||||
}
|
||||
}
|
||||
|
@ -26,7 +26,7 @@ namespace Wabbajack.CacheServer
|
||||
public Server(string address)
|
||||
{
|
||||
Address = address;
|
||||
_config = new HostConfiguration {MaximumConnectionCount = 24, RewriteLocalhost = true};
|
||||
_config = new HostConfiguration {MaximumConnectionCount = 200, RewriteLocalhost = true};
|
||||
//_config.UrlReservations.CreateAutomatically = true;
|
||||
_server = new NancyHost(_config, new Uri(address));
|
||||
|
||||
|
@ -92,6 +92,8 @@ namespace Wabbajack.Common
|
||||
public static string LocalAppDataPath => Path.Combine(KnownFolders.LocalAppData.Path, "Wabbajack");
|
||||
|
||||
public static string WabbajackCacheLocation = "http://build.wabbajack.org/nexus_api_cache/";
|
||||
|
||||
public static string WabbajackCacheHostname = "build.wabbajack.org";
|
||||
public static int WabbajackCachePort = 80;
|
||||
}
|
||||
}
|
||||
|
@ -139,7 +139,7 @@ namespace Wabbajack.Lib.Downloaders
|
||||
try
|
||||
{
|
||||
var client = await NexusApiClient.Get();
|
||||
url = await client.GetNexusDownloadLink(this, false);
|
||||
url = await client.GetNexusDownloadLink(this);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
@ -259,50 +259,24 @@ namespace Wabbajack.Lib.NexusApi
|
||||
{
|
||||
try
|
||||
{
|
||||
var builder = new UriBuilder(url) { Host = Consts.WabbajackCacheHostname, Port = 80, Scheme = "http" };
|
||||
var builder = new UriBuilder(url) { Host = Consts.WabbajackCacheHostname, Port = Consts.WabbajackCachePort, Scheme = "http" };
|
||||
return await Get<T>(builder.ToString());
|
||||
}
|
||||
catch (Exception)
|
||||
catch (Exception ex)
|
||||
{
|
||||
return await Get<T>(url);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public async Task<string> GetNexusDownloadLink(NexusDownloader.State archive, bool cache = false)
|
||||
public async Task<string> GetNexusDownloadLink(NexusDownloader.State archive)
|
||||
{
|
||||
if (cache)
|
||||
{
|
||||
var result = await TryGetCachedLink(archive);
|
||||
if (result.Succeeded)
|
||||
{
|
||||
return result.Value;
|
||||
}
|
||||
}
|
||||
|
||||
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
|
||||
|
||||
var url = $"https://api.nexusmods.com/v1/games/{ConvertGameName(archive.GameName)}/mods/{archive.ModID}/files/{archive.FileID}/download_link.json";
|
||||
return (await Get<List<DownloadLink>>(url)).First().URI;
|
||||
}
|
||||
|
||||
private async Task<GetResponse<string>> TryGetCachedLink(NexusDownloader.State archive)
|
||||
{
|
||||
if (!Directory.Exists(Consts.NexusCacheDirectory))
|
||||
Directory.CreateDirectory(Consts.NexusCacheDirectory);
|
||||
|
||||
var path = Path.Combine(Consts.NexusCacheDirectory, $"link-{archive.GameName}-{archive.ModID}-{archive.FileID}.txt");
|
||||
if (!File.Exists(path) || (DateTime.Now - new FileInfo(path).LastWriteTime).TotalHours > 24)
|
||||
{
|
||||
File.Delete(path);
|
||||
var result = await GetNexusDownloadLink(archive);
|
||||
File.WriteAllText(path, result);
|
||||
return GetResponse<string>.Succeed(result);
|
||||
}
|
||||
|
||||
return GetResponse<string>.Succeed(File.ReadAllText(path));
|
||||
}
|
||||
|
||||
public async Task<NexusFileInfo> GetFileInfo(NexusDownloader.State mod)
|
||||
{
|
||||
var url = $"https://api.nexusmods.com/v1/games/{ConvertGameName(mod.GameName)}/mods/{mod.ModID}/files/{mod.FileID}.json";
|
||||
|
Loading…
Reference in New Issue
Block a user