From cbe4bc593c7773e0b864298d83060aafb68255cf Mon Sep 17 00:00:00 2001 From: Tyrrrz Date: Mon, 14 Jun 2021 20:38:19 +0300 Subject: [PATCH] [HTML] Prefer proxy URLs for resolving embed media Closes #590 --- .../Discord/Data/EmbedAuthor.cs | 8 ++++++-- .../Discord/Data/EmbedFooter.cs | 8 ++++++-- .../Discord/Data/EmbedImage.cs | 8 ++++++-- .../Writers/Html/MessageGroupTemplate.cshtml | 16 ++++++++-------- 4 files changed, 26 insertions(+), 14 deletions(-) diff --git a/DiscordChatExporter.Core/Discord/Data/EmbedAuthor.cs b/DiscordChatExporter.Core/Discord/Data/EmbedAuthor.cs index 7b73d00f..ed3d19f7 100644 --- a/DiscordChatExporter.Core/Discord/Data/EmbedAuthor.cs +++ b/DiscordChatExporter.Core/Discord/Data/EmbedAuthor.cs @@ -12,11 +12,14 @@ namespace DiscordChatExporter.Core.Discord.Data public string? IconUrl { get; } - public EmbedAuthor(string? name, string? url, string? iconUrl) + public string? IconProxyUrl { get; } + + public EmbedAuthor(string? name, string? url, string? iconUrl, string? iconProxyUrl) { Name = name; Url = url; IconUrl = iconUrl; + IconProxyUrl = iconProxyUrl; } public override string ToString() => Name ?? ""; @@ -29,8 +32,9 @@ namespace DiscordChatExporter.Core.Discord.Data var name = json.GetPropertyOrNull("name")?.GetString(); var url = json.GetPropertyOrNull("url")?.GetString(); var iconUrl = json.GetPropertyOrNull("icon_url")?.GetString(); + var iconProxyUrl = json.GetPropertyOrNull("proxy_icon_url")?.GetString(); - return new EmbedAuthor(name, url, iconUrl); + return new EmbedAuthor(name, url, iconUrl, iconProxyUrl); } } } \ No newline at end of file diff --git a/DiscordChatExporter.Core/Discord/Data/EmbedFooter.cs b/DiscordChatExporter.Core/Discord/Data/EmbedFooter.cs index a8f0864a..37fafb83 100644 --- a/DiscordChatExporter.Core/Discord/Data/EmbedFooter.cs +++ b/DiscordChatExporter.Core/Discord/Data/EmbedFooter.cs @@ -10,10 +10,13 @@ namespace DiscordChatExporter.Core.Discord.Data public string? IconUrl { get; } - public EmbedFooter(string text, string? iconUrl) + public string? IconProxyUrl { get; } + + public EmbedFooter(string text, string? iconUrl, string? iconProxyUrl) { Text = text; IconUrl = iconUrl; + IconProxyUrl = iconProxyUrl; } public override string ToString() => Text; @@ -25,8 +28,9 @@ namespace DiscordChatExporter.Core.Discord.Data { var text = json.GetProperty("text").GetString(); var iconUrl = json.GetPropertyOrNull("icon_url")?.GetString(); + var iconProxyUrl = json.GetPropertyOrNull("proxy_icon_url")?.GetString(); - return new EmbedFooter(text, iconUrl); + return new EmbedFooter(text, iconUrl, iconProxyUrl); } } } \ No newline at end of file diff --git a/DiscordChatExporter.Core/Discord/Data/EmbedImage.cs b/DiscordChatExporter.Core/Discord/Data/EmbedImage.cs index e8b31f6b..0ec33e19 100644 --- a/DiscordChatExporter.Core/Discord/Data/EmbedImage.cs +++ b/DiscordChatExporter.Core/Discord/Data/EmbedImage.cs @@ -8,13 +8,16 @@ namespace DiscordChatExporter.Core.Discord.Data { public string? Url { get; } + public string? ProxyUrl { get; } + public int? Width { get; } public int? Height { get; } - public EmbedImage(string? url, int? width, int? height) + public EmbedImage(string? url, string? proxyUrl, int? width, int? height) { Url = url; + ProxyUrl = proxyUrl; Height = height; Width = width; } @@ -25,10 +28,11 @@ namespace DiscordChatExporter.Core.Discord.Data public static EmbedImage Parse(JsonElement json) { var url = json.GetPropertyOrNull("url")?.GetString(); + var proxyUrl = json.GetPropertyOrNull("proxy_url")?.GetString(); var width = json.GetPropertyOrNull("width")?.GetInt32(); var height = json.GetPropertyOrNull("height")?.GetInt32(); - return new EmbedImage(url, width, height); + return new EmbedImage(url, proxyUrl, width, height); } } } \ No newline at end of file diff --git a/DiscordChatExporter.Core/Exporting/Writers/Html/MessageGroupTemplate.cshtml b/DiscordChatExporter.Core/Exporting/Writers/Html/MessageGroupTemplate.cshtml index 1b9055b4..4eb1acf6 100644 --- a/DiscordChatExporter.Core/Exporting/Writers/Html/MessageGroupTemplate.cshtml +++ b/DiscordChatExporter.Core/Exporting/Writers/Html/MessageGroupTemplate.cshtml @@ -180,7 +180,7 @@
@if (!string.IsNullOrWhiteSpace(embed.Author.IconUrl)) { - Author icon + Author icon } @if (!string.IsNullOrWhiteSpace(embed.Author.Name)) @@ -249,21 +249,21 @@ }
- @if (embed.Thumbnail is not null) + @if (embed.Thumbnail is not null && !string.IsNullOrWhiteSpace(embed.Thumbnail.Url)) { } - @if (embed.Image is not null) + @if (embed.Image is not null && !string.IsNullOrWhiteSpace(embed.Image.Url)) { } @@ -273,7 +273,7 @@