mirror of
https://github.com/Tyrrrz/DiscordChatExporter.git
synced 2025-05-28 13:44:12 -04:00
Set last write time on downloaded media to the value provided in the Last-Modified header (#459)
This commit is contained in:
parent
0e67dcbf2e
commit
69acb5bf76
1 changed files with 13 additions and 4 deletions
|
@ -1,4 +1,7 @@
|
|||
using System.IO;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net.Http;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
|
@ -8,11 +11,17 @@ namespace DiscordChatExporter.Domain.Internal.Extensions
|
|||
{
|
||||
public static async ValueTask DownloadAsync(this HttpClient httpClient, string uri, string outputFilePath)
|
||||
{
|
||||
await using var input = await httpClient.GetStreamAsync(uri);
|
||||
using var response = await httpClient.GetAsync(uri);
|
||||
var output = File.Create(outputFilePath);
|
||||
|
||||
await input.CopyToAsync(output);
|
||||
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()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue