Clean up after last commit

pull/1145/head
Tyrrrz 12 months ago
parent 46ede471a9
commit fb6cde38b6

@ -102,28 +102,27 @@ internal partial class ExportAssetDownloader
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)
// Strip out ex, is and hm query params from Discord CDN URLs to create a consistent hash
if (
url.Contains("cdn.discordapp.com")
&& url.Contains("ex")
&& url.Contains("is")
&& url.Contains("hm")
)
{ {
var uriBuilder = new UriBuilder(url); var uri = new Uri(url);
var query = HttpUtility.ParseQueryString(uriBuilder.Query); if (!string.Equals(uri.Host, "cdn.discordapp.com", StringComparison.OrdinalIgnoreCase))
return url;
var query = HttpUtility.ParseQueryString(uri.Query);
query.Remove("ex"); query.Remove("ex");
query.Remove("is"); query.Remove("is");
query.Remove("hm"); query.Remove("hm");
uriBuilder.Query = query.ToString();
url = uriBuilder.ToString(); return uri.GetLeftPart(UriPartial.Path) + query;
url = url.Replace(":443", "");
} }
private static string GetUrlHash(string url)
{
var normalizedUrl = StripUrlSignatureParameters(url);
return SHA256 return SHA256
.HashData(Encoding.UTF8.GetBytes(url)) .HashData(Encoding.UTF8.GetBytes(normalizedUrl))
.ToHex() .ToHex()
// 5 chars ought to be enough for anybody // 5 chars ought to be enough for anybody
.Truncate(5); .Truncate(5);

Loading…
Cancel
Save