Merge pull request #508 from wabbajack-tools/issue-479

Fix AFKMods.com integration and implement test
This commit is contained in:
Timothy Baldridge 2020-02-11 15:55:11 -07:00 committed by GitHub
commit 19d21e1f90
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 52 additions and 4 deletions

View File

@ -28,6 +28,19 @@ namespace Wabbajack.Lib.Downloaders
var absolute = true;
if (url == null || url.Host != SiteURL.Host) return null;
if (url.PathAndQuery.StartsWith("/index.php?"))
{
var id2 = HttpUtility.ParseQueryString(url.Query)["r"];
var parsed = HttpUtility.ParseQueryString(url.Query);
var name = parsed[null].Split("/", StringSplitOptions.RemoveEmptyEntries).Last();
return new TState
{
FileID = id2,
FileName = name
};
}
if (!url.PathAndQuery.StartsWith("/files/file/"))
{
if (string.IsNullOrWhiteSpace(url.Query)) return null;
@ -103,9 +116,10 @@ namespace Wabbajack.Lib.Downloaders
if (csrfKey == null)
return null;
var sep = Site.EndsWith("?") ? "&" : "?";
var url = FileID == null
? $"{Site}/files/file/{FileName}/?do=download&confirm=1&t=1&csrfKey={csrfKey}"
: $"{Site}/files/file/{FileName}/?do=download&r={FileID}&confirm=1&t=1&csrfKey={csrfKey}";
? $"{Site}/files/file/{FileName}/{sep}do=download&confirm=1&t=1&csrfKey={csrfKey}"
: $"{Site}/files/file/{FileName}/{sep}do=download&r={FileID}&confirm=1&t=1&csrfKey={csrfKey}";
var streamResult = await downloader.AuthedClient.GetAsync(url);
@ -162,11 +176,22 @@ namespace Wabbajack.Lib.Downloaders
public override string[] GetMetaIni()
{
if (FileID != null)
{
if (Site.EndsWith("?"))
{
return new[]
{
"[General]", $"directURL={Site}/files/file/{FileName}&do=download&r={FileID}&confirm=1&t=1"
};
}
return new[]
{
"[General]",
$"directURL={Site}/files/file/{FileName}/?do=download&r={FileID}&confirm=1&t=1"
"[General]", $"directURL={Site}/files/file/{FileName}/?do=download&r={FileID}&confirm=1&t=1"
};
}
return new[]
{
"[General]",

View File

@ -413,6 +413,29 @@ namespace Wabbajack.Test
CollectionAssert.AreEqual(File.ReadAllBytes(Path.Combine(Game.SkyrimSpecialEdition.MetaData().GameLocation(), "Data/Update.esm")), File.ReadAllBytes(filename));
Consts.TestMode = true;
}
[TestMethod]
public async Task AFKModsDownloadTest()
{
await DownloadDispatcher.GetInstance<AFKModsDownloader>().Prepare();
const string ini = "[General]\n" +
"directURL=https://www.afkmods.com/index.php?/files/file/2120-skyrim-save-system-overhaul/&do=download&r=20112&confirm=1&t=1&csrfKey=840a4a373144097693171a79df77d521";
var state = (AbstractDownloadState)await DownloadDispatcher.ResolveArchive(ini.LoadIniString());
Assert.IsNotNull(state);
var converted = await state.RoundTripState();
Assert.IsTrue(await converted.Verify(new Archive{Size = 20}));
var filename = Guid.NewGuid().ToString();
Assert.IsTrue(converted.IsWhitelisted(new ServerWhitelist { AllowedPrefixes = new List<string>() }));
await converted.Download(new Archive { Name = "AFKMods Test.zip" }, filename);
Assert.AreEqual("GtjxHazwZ6s=", filename.FileHash());
}
[TestMethod]
public async Task BethesdaNetDownload()