Remove date-modified header fallback for attachment timestamp

pull/1321/head
Ritiek Malhotra 5 months ago
parent 9311820002
commit 57f5289b42
No known key found for this signature in database
GPG Key ID: ECAA33C16AE3563A

@ -49,41 +49,12 @@ internal partial class ExportAssetDownloader(string workingDirPath, bool reuse)
await using (var output = File.Create(filePath))
await response.Content.CopyToAsync(output, innerCancellationToken);
// Try to set the file date according to the last-modified header
try
// Try to set the file date according to the message timestamp
if (timestamp is not null)
{
if (timestamp is null)
{
var lastModified = response
.Content.Headers.TryGetValue("Last-Modified")
?.Pipe(s =>
DateTimeOffset.TryParse(
s,
CultureInfo.InvariantCulture,
DateTimeStyles.None,
out var instant
)
? instant
: (DateTimeOffset?)null
);
if (lastModified is not null)
{
timestamp = lastModified;
}
}
if (timestamp is not null)
{
File.SetCreationTimeUtc(filePath, timestamp.Value.UtcDateTime);
File.SetLastWriteTimeUtc(filePath, timestamp.Value.UtcDateTime);
File.SetLastAccessTimeUtc(filePath, timestamp.Value.UtcDateTime);
}
}
catch
{
// This can apparently fail for some reason.
// Updating the file date is not a critical task, so we'll just ignore exceptions thrown here.
// https://github.com/Tyrrrz/DiscordChatExporter/issues/585
File.SetCreationTimeUtc(filePath, timestamp.Value.UtcDateTime);
File.SetLastWriteTimeUtc(filePath, timestamp.Value.UtcDateTime);
File.SetLastAccessTimeUtc(filePath, timestamp.Value.UtcDateTime);
}
},
cancellationToken

Loading…
Cancel
Save