mirror of
https://github.com/Tyrrrz/DiscordChatExporter.git
synced 2026-03-17 20:32:34 +00:00
Refactor last PR
This commit is contained in:
@@ -1,27 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net.Http;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DiscordChatExporter.Domain.Internal.Extensions
|
||||
{
|
||||
internal static class HttpClientExtensions
|
||||
{
|
||||
public static async ValueTask DownloadAsync(this HttpClient httpClient, string uri, string outputFilePath)
|
||||
{
|
||||
using var response = await httpClient.GetAsync(uri);
|
||||
var output = File.Create(outputFilePath);
|
||||
|
||||
await response.Content.CopyToAsync(output);
|
||||
|
||||
IEnumerable<string> lastModifiedHeaderValues;
|
||||
if (response.Content.Headers.TryGetValues("Last-Modified", out lastModifiedHeaderValues))
|
||||
{
|
||||
await output.DisposeAsync();
|
||||
File.SetLastWriteTime(outputFilePath, DateTime.Parse(lastModifiedHeaderValues.First()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
using System.Net.Http.Headers;
|
||||
|
||||
namespace DiscordChatExporter.Domain.Internal.Extensions
|
||||
{
|
||||
internal static class HttpExtensions
|
||||
{
|
||||
public static string? TryGetValue(this HttpContentHeaders headers, string name) =>
|
||||
headers.TryGetValues(name, out var values)
|
||||
? string.Concat(values)
|
||||
: null;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user