More cleanup

This commit is contained in:
Tyrrrz 2023-10-11 01:20:30 +03:00
parent fb6cde38b6
commit 033d83bc4f

View file

@ -101,9 +101,11 @@ internal partial class ExportAssetDownloader
}
internal partial class ExportAssetDownloader
{
private static string GetUrlHash(string url)
{
// Remove signature parameters from Discord CDN URLs to normalize them
private static string StripUrlSignatureParameters(string url)
static string NormalizeUrl(string url)
{
var uri = new Uri(url);
if (!string.Equals(uri.Host, "cdn.discordapp.com", StringComparison.OrdinalIgnoreCase))
@ -117,12 +119,8 @@ internal partial class ExportAssetDownloader
return uri.GetLeftPart(UriPartial.Path) + query;
}
private static string GetUrlHash(string url)
{
var normalizedUrl = StripUrlSignatureParameters(url);
return SHA256
.HashData(Encoding.UTF8.GetBytes(normalizedUrl))
.HashData(Encoding.UTF8.GetBytes(NormalizeUrl(url)))
.ToHex()
// 5 chars ought to be enough for anybody
.Truncate(5);