From d17fef6721b798679bf0ec4b8da6b24346c8a9cc Mon Sep 17 00:00:00 2001 From: Alexey Golub Date: Wed, 12 Jul 2017 20:35:49 +0300 Subject: [PATCH] Add support for non-image attachments --- DiscordChatExporter/Models/Attachment.cs | 6 +++--- .../Services/DiscordApiService.cs | 4 ++-- DiscordChatExporter/Services/ExportService.cs | 21 ++++++++++++++----- 3 files changed, 21 insertions(+), 10 deletions(-) diff --git a/DiscordChatExporter/Models/Attachment.cs b/DiscordChatExporter/Models/Attachment.cs index bbd3dfe8..130d780d 100644 --- a/DiscordChatExporter/Models/Attachment.cs +++ b/DiscordChatExporter/Models/Attachment.cs @@ -8,14 +8,14 @@ public string FileName { get; } - public long ContentLength { get; } + public bool IsImage { get; } - public Attachment(string id, string url, string fileName, long contentLength) + public Attachment(string id, string url, string fileName, bool isImage) { Id = id; Url = url; FileName = fileName; - ContentLength = contentLength; + IsImage = isImage; } } } \ No newline at end of file diff --git a/DiscordChatExporter/Services/DiscordApiService.cs b/DiscordChatExporter/Services/DiscordApiService.cs index db1a6064..2a9469cc 100644 --- a/DiscordChatExporter/Services/DiscordApiService.cs +++ b/DiscordChatExporter/Services/DiscordApiService.cs @@ -37,9 +37,9 @@ namespace DiscordChatExporter.Services string attachmentId = attachmentJson.Value("id"); string attachmentUrl = attachmentJson.Value("url"); string attachmentFileName = attachmentJson.Value("filename"); - long attachmentContentLength = attachmentJson.Value("size"); + bool attachmentIsImage = attachmentJson["width"] != null; - var attachment = new Attachment(attachmentId, attachmentUrl, attachmentFileName, attachmentContentLength); + var attachment = new Attachment(attachmentId, attachmentUrl, attachmentFileName, attachmentIsImage); attachments.Add(attachment); } diff --git a/DiscordChatExporter/Services/ExportService.cs b/DiscordChatExporter/Services/ExportService.cs index 9cb38a70..8eb4053e 100644 --- a/DiscordChatExporter/Services/ExportService.cs +++ b/DiscordChatExporter/Services/ExportService.cs @@ -164,11 +164,22 @@ namespace DiscordChatExporter.Services // Attachments foreach (var attachment in message.Attachments) { - messageBodyHtml.AppendChild( - HtmlNode.CreateNode("")); + if (attachment.IsImage) + { + messageBodyHtml.AppendChild( + HtmlNode.CreateNode("")); + } + else + { + messageBodyHtml.AppendChild( + HtmlNode.CreateNode("")); + } } } }