Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prototype to use ManualBlobDownload for LL #2681

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 32 additions & 6 deletions Wabbajack.Downloaders.Manual/ManualDownloader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,28 @@ public ManualDownloader(ILogger<ManualDownloader> logger, IUserInterventionHandl
_interventionHandler = interventionHandler;
_downloader = downloader;
}
public override async Task<Hash> Download(Archive archive, DTOs.DownloadStates.Manual state, AbsolutePath destination, IJob job, CancellationToken token)

public override Task<Hash> Download(Archive archive, DTOs.DownloadStates.Manual state, AbsolutePath destination, IJob job, CancellationToken token)
{
_logger.LogInformation("Starting manual download of {Url}", state.Url);

if (ShouldUseBlobDownload(state.Url))
{
return DoManualBlobDownload(archive, destination, token);
}
else
{
return DoManualDownload(archive, destination, job, token);
}
}

private bool ShouldUseBlobDownload(Uri url)
{
return url.Host.EndsWith("loverslab.com");
}

private async Task<Hash> DoManualDownload(Archive archive, AbsolutePath destination, IJob job, CancellationToken token)
{
var intervention = new ManualDownload(archive);
_interventionHandler.Raise(intervention);
var browserState = await intervention.Task;
Expand All @@ -38,6 +55,15 @@ public override async Task<Hash> Download(Archive archive, DTOs.DownloadStates.M
return await _downloader.Download(msg, destination, job, token);
}

private async Task<Hash> DoManualBlobDownload(Archive archive, AbsolutePath destination, CancellationToken token)
{
var intervention = new ManualBlobDownload(archive, destination);
_interventionHandler.Raise(intervention);
await intervention.Task;

await using var file = destination.Open(FileMode.Open);
return await file.Hash(token);
}

public override Task<bool> Prepare()
{
Expand All @@ -46,15 +72,15 @@ public override Task<bool> Prepare()

public override bool IsAllowed(ServerAllowList allowList, IDownloadState state)
{
return allowList.AllowedPrefixes.Any(p => ((DTOs.DownloadStates.Manual) state).Url.ToString().StartsWith(p));
return allowList.AllowedPrefixes.Any(p => ((DTOs.DownloadStates.Manual)state).Url.ToString().StartsWith(p));
}

public override IDownloadState? Resolve(IReadOnlyDictionary<string, string> iniData)
{
if (iniData.ContainsKey("manualURL") && Uri.TryCreate(iniData["manualURL"].CleanIniString(), UriKind.Absolute, out var uri))
{
iniData.TryGetValue("prompt", out var prompt);

var state = new DTOs.DownloadStates.Manual
{
Url = uri,
Expand All @@ -76,12 +102,12 @@ public override Task<bool> Verify(Archive archive, DTOs.DownloadStates.Manual ar
public override IEnumerable<string> MetaIni(Archive a, DTOs.DownloadStates.Manual state)
{

return new[] {$"manualURL={state.Url}", $"prompt={state.Prompt}"};
return new[] { $"manualURL={state.Url}", $"prompt={state.Prompt}" };
}

public IDownloadState? Parse(Uri uri)
{
return new DTOs.DownloadStates.Manual() {Url = uri};
return new DTOs.DownloadStates.Manual() { Url = uri };
}

public Uri UnParse(IDownloadState state)
Expand Down
Loading