initial
This commit is contained in:
44
Pixiview/Utils/Stores.cs
Normal file
44
Pixiview/Utils/Stores.cs
Normal file
@@ -0,0 +1,44 @@
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.IO;
|
||||
using System.Net;
|
||||
using System.Net.Http;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Pixiview.Utils
|
||||
{
|
||||
public class Stores
|
||||
{
|
||||
public static readonly string PersonalFolder = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
|
||||
//public static readonly string CacheFolder = Environment.GetFolderPath(Environment.SpecialFolder.InternetCache);
|
||||
public const string ImageFolder = "images";
|
||||
|
||||
[SuppressMessage("Style", "IDE0063:Use simple 'using' statement", Justification = "<Pending>")]
|
||||
public static async Task DownloadImage(string url)
|
||||
{
|
||||
var uri = new Uri(url);
|
||||
var handler = new HttpClientHandler
|
||||
{
|
||||
Proxy = new WebProxy("10.0.10.100", 8088),
|
||||
UseProxy = true
|
||||
};
|
||||
var client = new HttpClient(handler)
|
||||
{
|
||||
BaseAddress = new Uri($"{uri.Scheme}://{uri.Host}")
|
||||
};
|
||||
using (var request = new HttpRequestMessage(HttpMethod.Get, uri.PathAndQuery)
|
||||
{
|
||||
Version = new Version(2, 0)
|
||||
})
|
||||
{
|
||||
request.Headers.Referrer = new Uri("https://www.pixiv.net/");
|
||||
var file = Path.Combine(PersonalFolder, ImageFolder, Path.GetFileName(uri.LocalPath));
|
||||
using (var response = await client.SendAsync(request))
|
||||
using (var fs = File.OpenWrite(file))
|
||||
{
|
||||
await response.Content.CopyToAsync(fs);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user