mirror of
https://github.com/Tyrrrz/DiscordChatExporter.git
synced 2025-06-03 08:08:40 -04:00
Add support for non-image attachments
This commit is contained in:
parent
a209252259
commit
d17fef6721
3 changed files with 21 additions and 10 deletions
|
@ -8,14 +8,14 @@
|
||||||
|
|
||||||
public string FileName { get; }
|
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;
|
Id = id;
|
||||||
Url = url;
|
Url = url;
|
||||||
FileName = fileName;
|
FileName = fileName;
|
||||||
ContentLength = contentLength;
|
IsImage = isImage;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -37,9 +37,9 @@ namespace DiscordChatExporter.Services
|
||||||
string attachmentId = attachmentJson.Value<string>("id");
|
string attachmentId = attachmentJson.Value<string>("id");
|
||||||
string attachmentUrl = attachmentJson.Value<string>("url");
|
string attachmentUrl = attachmentJson.Value<string>("url");
|
||||||
string attachmentFileName = attachmentJson.Value<string>("filename");
|
string attachmentFileName = attachmentJson.Value<string>("filename");
|
||||||
long attachmentContentLength = attachmentJson.Value<long>("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);
|
attachments.Add(attachment);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -164,11 +164,22 @@ namespace DiscordChatExporter.Services
|
||||||
// Attachments
|
// Attachments
|
||||||
foreach (var attachment in message.Attachments)
|
foreach (var attachment in message.Attachments)
|
||||||
{
|
{
|
||||||
messageBodyHtml.AppendChild(
|
if (attachment.IsImage)
|
||||||
HtmlNode.CreateNode("<div class=\"msg-attachment\">" +
|
{
|
||||||
$"<a href=\"{attachment.Url}\">" +
|
messageBodyHtml.AppendChild(
|
||||||
$"<img class=\"msg-attachment\" src=\"{attachment.Url}\" />" +
|
HtmlNode.CreateNode("<div class=\"msg-attachment\">" +
|
||||||
"</a></div>"));
|
$"<a href=\"{attachment.Url}\">" +
|
||||||
|
$"<img class=\"msg-attachment\" src=\"{attachment.Url}\" />" +
|
||||||
|
"</a></div>"));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
messageBodyHtml.AppendChild(
|
||||||
|
HtmlNode.CreateNode("<div class=\"msg-attachment\">" +
|
||||||
|
$"<a href=\"{attachment.Url}\">" +
|
||||||
|
$"Attachment: {attachment.FileName}" +
|
||||||
|
"</a></div>"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue