Browse Source

Add DownloadService.GetContentAsync

pull/438/head
ionite34 11 months ago
parent
commit
332f39725f
No known key found for this signature in database
GPG Key ID: B3404C5F3827849B
  1. 12
      StabilityMatrix.Core/Services/DownloadService.cs
  2. 2
      StabilityMatrix.Core/Services/IDownloadService.cs

12
StabilityMatrix.Core/Services/DownloadService.cs

@ -305,6 +305,18 @@ public class DownloadService : IDownloadService
}
}
public async Task<Stream> GetContentAsync(string url, CancellationToken cancellationToken = default)
{
using var client = httpClientFactory.CreateClient();
client.Timeout = TimeSpan.FromSeconds(10);
client.DefaultRequestHeaders.UserAgent.Add(new ProductInfoHeaderValue("StabilityMatrix", "2.0"));
await AddConditionalHeaders(client, new Uri(url)).ConfigureAwait(false);
var response = await client.GetAsync(url, cancellationToken).ConfigureAwait(false);
return await response.Content.ReadAsStreamAsync(cancellationToken).ConfigureAwait(false);
}
/// <summary>
/// Adds conditional headers to the HttpClient for the given URL
/// </summary>

2
StabilityMatrix.Core/Services/IDownloadService.cs

@ -28,4 +28,6 @@ public interface IDownloadService
);
Task<Stream?> GetImageStreamFromUrl(string url);
Task<Stream> GetContentAsync(string url, CancellationToken cancellationToken = default);
}

Loading…
Cancel
Save