From 9e4c5ca4ff9b1c6b8eab24a1c7624cd9624f5d83 Mon Sep 17 00:00:00 2001 From: KhanKudo <37520008+KhanKudo@users.noreply.github.com> Date: Tue, 18 Apr 2023 16:18:08 +0200 Subject: [PATCH] Fixed: site cannot open if imported json invalid (#579) --- utils/app/clean.ts | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/utils/app/clean.ts b/utils/app/clean.ts index c194e02..7130eef 100644 --- a/utils/app/clean.ts +++ b/utils/app/clean.ts @@ -8,6 +8,7 @@ export const cleanSelectedConversation = (conversation: Conversation) => { // added system prompt for each conversation (3/21/23) // added folders (3/23/23) // added prompts (3/26/23) + // added messages (4/16/23) let updatedConversation = conversation; @@ -41,6 +42,13 @@ export const cleanSelectedConversation = (conversation: Conversation) => { }; } + if (!updatedConversation.messages) { + updatedConversation = { + ...updatedConversation, + messages: updatedConversation.messages || [], + }; + } + return updatedConversation; }; @@ -49,6 +57,7 @@ export const cleanConversationHistory = (history: any[]): Conversation[] => { // added system prompt for each conversation (3/21/23) // added folders (3/23/23) // added prompts (3/26/23) + // added messages (4/16/23) if (!Array.isArray(history)) { console.warn('history is not an array. Returning an empty array.'); @@ -73,6 +82,10 @@ export const cleanConversationHistory = (history: any[]): Conversation[] => { conversation.folderId = null; } + if (!conversation.messages) { + conversation.messages = []; + } + acc.push(conversation); return acc; } catch (error) {