mirror of
https://github.com/wabbajack-tools/wabbajack.git
synced 2024-08-30 18:42:17 +00:00
Fix AFKMods.com integration and implement test
This commit is contained in:
parent
e80cbf4535
commit
9316819dd3
@ -28,6 +28,19 @@ namespace Wabbajack.Lib.Downloaders
|
|||||||
|
|
||||||
var absolute = true;
|
var absolute = true;
|
||||||
if (url == null || url.Host != SiteURL.Host) return null;
|
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 (!url.PathAndQuery.StartsWith("/files/file/"))
|
||||||
{
|
{
|
||||||
if (string.IsNullOrWhiteSpace(url.Query)) return null;
|
if (string.IsNullOrWhiteSpace(url.Query)) return null;
|
||||||
@ -103,9 +116,10 @@ namespace Wabbajack.Lib.Downloaders
|
|||||||
if (csrfKey == null)
|
if (csrfKey == null)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
|
var sep = Site.EndsWith("?") ? "&" : "?";
|
||||||
var url = FileID == null
|
var url = FileID == null
|
||||||
? $"{Site}/files/file/{FileName}/?do=download&confirm=1&t=1&csrfKey={csrfKey}"
|
? $"{Site}/files/file/{FileName}/{sep}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&r={FileID}&confirm=1&t=1&csrfKey={csrfKey}";
|
||||||
|
|
||||||
|
|
||||||
var streamResult = await downloader.AuthedClient.GetAsync(url);
|
var streamResult = await downloader.AuthedClient.GetAsync(url);
|
||||||
@ -162,11 +176,22 @@ namespace Wabbajack.Lib.Downloaders
|
|||||||
public override string[] GetMetaIni()
|
public override string[] GetMetaIni()
|
||||||
{
|
{
|
||||||
if (FileID != null)
|
if (FileID != null)
|
||||||
|
{
|
||||||
|
if (Site.EndsWith("?"))
|
||||||
|
{
|
||||||
|
return new[]
|
||||||
|
{
|
||||||
|
"[General]", $"directURL={Site}/files/file/{FileName}&do=download&r={FileID}&confirm=1&t=1"
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
return new[]
|
return new[]
|
||||||
{
|
{
|
||||||
"[General]",
|
"[General]", $"directURL={Site}/files/file/{FileName}/?do=download&r={FileID}&confirm=1&t=1"
|
||||||
$"directURL={Site}/files/file/{FileName}/?do=download&r={FileID}&confirm=1&t=1"
|
|
||||||
};
|
};
|
||||||
|
}
|
||||||
|
|
||||||
return new[]
|
return new[]
|
||||||
{
|
{
|
||||||
"[General]",
|
"[General]",
|
||||||
|
@ -413,6 +413,29 @@ namespace Wabbajack.Test
|
|||||||
CollectionAssert.AreEqual(File.ReadAllBytes(Path.Combine(Game.SkyrimSpecialEdition.MetaData().GameLocation(), "Data/Update.esm")), File.ReadAllBytes(filename));
|
CollectionAssert.AreEqual(File.ReadAllBytes(Path.Combine(Game.SkyrimSpecialEdition.MetaData().GameLocation(), "Data/Update.esm")), File.ReadAllBytes(filename));
|
||||||
Consts.TestMode = true;
|
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]
|
[TestMethod]
|
||||||
public async Task BethesdaNetDownload()
|
public async Task BethesdaNetDownload()
|
||||||
|
Loading…
Reference in New Issue
Block a user