Clean up after last commit

pull/1145/head
Tyrrrz 1 year ago
parent 46ede471a9
commit fb6cde38b6

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

Loading…
Cancel
Save