From 2e7ece886ef0c4cc7d6a3d5016ebce8799acb6b1 Mon Sep 17 00:00:00 2001 From: Pionxzh Date: Thu, 20 Apr 2023 14:24:10 +0800 Subject: [PATCH] fix: some chats cannot be exported because of missing message parts --- packages/userscript/src/exporter/html.ts | 2 +- packages/userscript/src/exporter/markdown.ts | 2 +- packages/userscript/src/exporter/text.ts | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/userscript/src/exporter/html.ts b/packages/userscript/src/exporter/html.ts index 5a114c9..42cf45a 100644 --- a/packages/userscript/src/exporter/html.ts +++ b/packages/userscript/src/exporter/html.ts @@ -71,7 +71,7 @@ function conversationToHtml(conversation: ConversationResult, avatar: string, me const avatarEl = author === 'ChatGPT' ? '' : `${author}` - const content = item.message?.content.parts.join('\n') ?? '' + const content = item.message?.content.parts?.join('\n') ?? '' let conversationContent = content if (author === 'ChatGPT') { diff --git a/packages/userscript/src/exporter/markdown.ts b/packages/userscript/src/exporter/markdown.ts index 0d1616e..ba9598c 100644 --- a/packages/userscript/src/exporter/markdown.ts +++ b/packages/userscript/src/exporter/markdown.ts @@ -79,7 +79,7 @@ function conversationToMarkdown(conversation: ConversationResult, metaList?: Exp const content = conversationNodes.map((item) => { const author = item.message?.author.role === 'assistant' ? 'ChatGPT' : 'You' - const content = item.message?.content.parts.join('\n') ?? '' + const content = item.message?.content.parts?.join('\n') ?? '' let message = content // User's message will not be reformatted diff --git a/packages/userscript/src/exporter/text.ts b/packages/userscript/src/exporter/text.ts index aba0164..0bb15f5 100644 --- a/packages/userscript/src/exporter/text.ts +++ b/packages/userscript/src/exporter/text.ts @@ -18,7 +18,7 @@ export async function exportToText() { const { conversationNodes } = processConversation(rawConversation, conversationChoices) const text = conversationNodes.map((item) => { const author = item.message?.author.role === 'assistant' ? 'ChatGPT' : 'You' - const content = item.message?.content.parts.join('\n') ?? '' + const content = item.message?.content.parts?.join('\n') ?? '' let message = content // User's message will not be reformatted @@ -53,7 +53,7 @@ export async function exportToTextFromIndex(index: number) { const conversationChoices = getConversationChoice() const { conversationNodes } = processConversation(rawConversation, conversationChoices) - const text = conversationNodes[index].message?.content.parts.join('\n') ?? '' + const text = conversationNodes[index].message?.content.parts?.join('\n') ?? '' copyToClipboard(standardizeLineBreaks(text)) return true