Don't attempt to infer asset timestamp from message timestamp (#1352)

This is inaccurate and somewhat works only for attachments anyway. Not worth the overhead.
This commit is contained in:
Oleksii Holub 2025-03-13 21:43:19 +02:00 committed by GitHub
parent 9e115562dc
commit 62babc0de5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 7 additions and 26 deletions

View file

@ -1,6 +1,5 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Globalization;
using System.IO; using System.IO;
using System.Security.Cryptography; using System.Security.Cryptography;
using System.Text; using System.Text;
@ -23,8 +22,7 @@ internal partial class ExportAssetDownloader(string workingDirPath, bool reuse)
public async ValueTask<string> DownloadAsync( public async ValueTask<string> DownloadAsync(
string url, string url,
CancellationToken cancellationToken = default, CancellationToken cancellationToken = default
DateTimeOffset? timestamp = null
) )
{ {
var fileName = GetFileNameFromUrl(url); var fileName = GetFileNameFromUrl(url);
@ -46,16 +44,8 @@ internal partial class ExportAssetDownloader(string workingDirPath, bool reuse)
{ {
// Download the file // Download the file
using var response = await Http.Client.GetAsync(url, innerCancellationToken); using var response = await Http.Client.GetAsync(url, innerCancellationToken);
await using (var output = File.Create(filePath)) await using var output = File.Create(filePath);
await response.Content.CopyToAsync(output, innerCancellationToken); await response.Content.CopyToAsync(output, innerCancellationToken);
// Try to set the file date according to the message timestamp
if (timestamp is not null)
{
File.SetCreationTimeUtc(filePath, timestamp.Value.UtcDateTime);
File.SetLastWriteTimeUtc(filePath, timestamp.Value.UtcDateTime);
File.SetLastAccessTimeUtc(filePath, timestamp.Value.UtcDateTime);
}
}, },
cancellationToken cancellationToken
); );

View file

@ -106,8 +106,7 @@ internal class ExportContext(DiscordClient discord, ExportRequest request)
public async ValueTask<string> ResolveAssetUrlAsync( public async ValueTask<string> ResolveAssetUrlAsync(
string url, string url,
CancellationToken cancellationToken = default, CancellationToken cancellationToken = default
DateTimeOffset? timestamp = null
) )
{ {
if (!Request.ShouldDownloadAssets) if (!Request.ShouldDownloadAssets)
@ -115,7 +114,7 @@ internal class ExportContext(DiscordClient discord, ExportRequest request)
try try
{ {
var filePath = await _assetDownloader.DownloadAsync(url, cancellationToken, timestamp); var filePath = await _assetDownloader.DownloadAsync(url, cancellationToken);
var relativeFilePath = Path.GetRelativePath(Request.OutputDirPath, filePath); var relativeFilePath = Path.GetRelativePath(Request.OutputDirPath, filePath);
// Prefer the relative path so that the export package can be copied around without breaking references. // Prefer the relative path so that the export package can be copied around without breaking references.

View file

@ -435,11 +435,7 @@ internal class JsonMessageWriter(Stream stream, ExportContext context)
_writer.WriteString("id", attachment.Id.ToString()); _writer.WriteString("id", attachment.Id.ToString());
_writer.WriteString( _writer.WriteString(
"url", "url",
await Context.ResolveAssetUrlAsync( await Context.ResolveAssetUrlAsync(attachment.Url, cancellationToken)
attachment.Url,
cancellationToken,
message.Timestamp
)
); );
_writer.WriteString("fileName", attachment.FileName); _writer.WriteString("fileName", attachment.FileName);
_writer.WriteNumber("fileSizeBytes", attachment.FileSize.TotalBytes); _writer.WriteNumber("fileSizeBytes", attachment.FileSize.TotalBytes);
@ -469,11 +465,7 @@ internal class JsonMessageWriter(Stream stream, ExportContext context)
_writer.WriteString("format", sticker.Format.ToString()); _writer.WriteString("format", sticker.Format.ToString());
_writer.WriteString( _writer.WriteString(
"sourceUrl", "sourceUrl",
await Context.ResolveAssetUrlAsync( await Context.ResolveAssetUrlAsync(sticker.SourceUrl, cancellationToken)
sticker.SourceUrl,
cancellationToken,
message.Timestamp
)
); );
_writer.WriteEndObject(); _writer.WriteEndObject();