Skip to content

Commit

Permalink
'#1859 Reverts to old (redundant) style that creates a sub item for the
Browse files Browse the repository at this point in the history
json entry, with the HTML of the chat.
  • Loading branch information
patrickdalla committed Nov 13, 2023
1 parent ae1bdd1 commit 695d57e
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 8 deletions.
2 changes: 1 addition & 1 deletion iped-app/resources/config/conf/MakePreviewConfig.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ supportedMimes = application/x-prefetch; text/x-vcard; application/x-bittorrent-

# List of mimetypes which parsers insert links to other case items into preview
supportedMimesWithLinks = application/x-emule; application/x-emule-part-met; application/x-ares-galaxy; application/x-shareaza-library-dat
supportedMimesWithLinks = application/x-discord-chat+json
supportedMimesWithLinks = application/x-discord-chat
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,11 @@ public byte[] convertToHTML(List<DiscordRoot> drl, IItemSearcher searcher,
out.println("<HEAD>");
out.println(" <meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\" />\n");
out.println("<style>" + CSS + "</style>");
out.println("<style>" + iped.parsers.whatsapp.Util.readResourceAsString("css/whatsapp.css") + "</style>");
out.println("<script>"); //$NON-NLS-1$
out.println(iped.parsers.whatsapp.Util.readResourceAsString("js/whatsapp.js"));
out.println("</script>"); //$NON-NLS-1$

out.println("</HEAD>");
out.println("<BODY>");
}
Expand All @@ -395,10 +400,27 @@ public byte[] convertToHTML(List<DiscordRoot> drl, IItemSearcher searcher,
out.println(" <TABLE class='title'>");
out.println(" <TR>");
out.println(" <TD>");

if (dr.getAuthor().getAvatarBytes() == null) {
out.println(" <img src='https://cdn.discordapp.com/avatars/" + format(dr.getAuthor().getId()) + "/" + format(dr.getAuthor().getAvatar()) + ".png' alt='' width='50' height='50'>");
String avatar = dr.getAuthor().getAvatar();
if (avatar == null || avatar.trim().equals("")) {
String defaultAvatar;
if (me != null && dr.getAuthor().getId().equals(me.getId())) {
defaultAvatar = defaultAvatarMe;
} else {
defaultAvatar = defaultAvatarOther;
}
out.println(" <img src='data:image/jpeg;base64, " + defaultAvatar
+ "' alt='' width='50' height='50'>");
} else {
out.println(" <img src='https://cdn.discordapp.com/avatars/"
+ format(dr.getAuthor().getId()) + "/" + format(dr.getAuthor().getAvatar())
+ ".png' alt='' width='50' height='50'>");
}
} else {
out.println(" <img src='data:image/jpeg;base64, " + Base64.getEncoder().encodeToString(dr.getAuthor().getAvatarBytes()) + "' alt='' width='50' height='50'>");
out.println(" <img src='data:image/jpeg;base64, "
+ Base64.getEncoder().encodeToString(dr.getAuthor().getAvatarBytes())
+ "' alt='' width='50' height='50'>");
}

out.println(" </TD>");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ public class DiscordParser extends AbstractParser {
public static final String DATA_MIME_TYPE_V2_1 = "data-v21/x-discord-chat";

public static final String CHAT_MIME_TYPE = "application/x-discord-chat+json";
public static final String CHAT_MIME_TYPE_HTML = "application/x-discord-chat";
public static final String MSG_MIME_TYPE = "message/x-discord-message";
public static final String CALL_MIME_TYPE = "call/x-discord-call";
public static final String ATTACH_MIME_TYPE = "message/x-discord-attachment";
Expand Down Expand Up @@ -202,9 +203,11 @@ public void parseDiscord(InputStream indexFile, ContentHandler handler, Metadata

DiscordAuthor me = extractAccount(searcher, commonQuery, mapper, avatarCache, handler, extractor);

metadata.set("URL", item.getName());
metadata.set(TikaCoreProperties.TITLE, chatName);
metadata.set(StandardParser.INDEXER_CONTENT_TYPE, CHAT_MIME_TYPE);
Metadata chatmetadata = new Metadata();

chatmetadata.set("URL", item.getName());
chatmetadata.set(TikaCoreProperties.TITLE, chatName);
chatmetadata.set(StandardParser.INDEXER_CONTENT_TYPE, CHAT_MIME_TYPE_HTML);

for (DiscordRoot dr : discordRoot) {
for (DiscordAttachment da : dr.getAttachments()) {
Expand All @@ -224,7 +227,7 @@ public void parseDiscord(InputStream indexFile, ContentHandler handler, Metadata
}

if (da.getMediaHash() != null) {
metadata.add(ExtraProperties.LINKED_ITEMS, BasicProps.HASH + ":" + da.getMediaHash());
chatmetadata.add(ExtraProperties.LINKED_ITEMS, BasicProps.HASH + ":" + da.getMediaHash());
}

}
Expand All @@ -234,7 +237,8 @@ public void parseDiscord(InputStream indexFile, ContentHandler handler, Metadata
Collections.sort(discordRoot);

XHTMLContentHandler xhtml = new XHTMLContentHandler(handler, metadata);
new DiscordHTMLReport(me).printHTML(discordRoot, xhtml, searcher);
byte[] relatorio = new DiscordHTMLReport(me).convertToHTML(discordRoot, searcher);
extractor.parseEmbedded(new ByteArrayInputStream(relatorio), handler, chatmetadata, false);

extractMessages(chatName, discordRoot, handler, extractor, 0);
}
Expand Down

0 comments on commit 695d57e

Please sign in to comment.