@@ -958,27 +958,27 @@ class ChatStore {
958958 * @param convId - The conversation ID to download
959959 */
960960 async downloadConversation ( convId : string ) : Promise < void > {
961- if ( ! this . activeConversation || this . activeConversation . id !== convId ) {
962- // Load the conversation if not currently active
963- const conversation = await DatabaseStore . getConversation ( convId ) ;
964- if ( ! conversation ) return ;
965-
966- const messages = await DatabaseStore . getConversationMessages ( convId ) ;
967- const conversationData = {
968- conv : conversation ,
969- messages
970- } ;
961+ if ( ! this . activeConversation || this . activeConversation . id !== convId ) {
962+ // Load the conversation if not currently active
963+ const conversation = await DatabaseStore . getConversation ( convId ) ;
964+ if ( ! conversation ) return ;
971965
972- this . triggerDownload ( conversationData ) ;
973- } else {
974- // Use current active conversation data
975- const conversationData : ExportedConversations = {
976- conv : this . activeConversation ! ,
977- messages : this . activeMessages
978- } ;
966+ const messages = await DatabaseStore . getConversationMessages ( convId ) ;
967+ const conversationData = {
968+ conv : conversation ,
969+ messages
970+ } ;
979971
980- this . triggerDownload ( conversationData ) ;
981- }
972+ this . triggerDownload ( conversationData ) ;
973+ } else {
974+ // Use current active conversation data
975+ const conversationData : ExportedConversations = {
976+ conv : this . activeConversation ! ,
977+ messages : this . activeMessages
978+ } ;
979+
980+ this . triggerDownload ( conversationData ) ;
981+ }
982982 }
983983
984984 /**
@@ -987,20 +987,24 @@ class ChatStore {
987987 * @param filename - Optional filename
988988 */
989989 private triggerDownload ( data : ExportedConversations , filename ?: string ) : void {
990- const conversation = 'conv' in data ? data . conv : ( Array . isArray ( data ) ? data [ 0 ] ?. conv : undefined ) ;
990+ const conversation =
991+ 'conv' in data ? data . conv : Array . isArray ( data ) ? data [ 0 ] ?. conv : undefined ;
991992 if ( ! conversation ) {
992993 console . error ( 'Invalid data: missing conversation' ) ;
993994 return ;
994995 }
995996 const conversationName = conversation . name ? conversation . name . trim ( ) : '' ;
996997 const convId = conversation . id || 'unknown' ;
997- const truncatedSuffix = conversationName . toLowerCase ( )
998- . replace ( / [ ^ a - z 0 - 9 ] / gi, '_' ) . replace ( / _ + / g, '_' ) . substring ( 0 , 20 ) ;
998+ const truncatedSuffix = conversationName
999+ . toLowerCase ( )
1000+ . replace ( / [ ^ a - z 0 - 9 ] / gi, '_' )
1001+ . replace ( / _ + / g, '_' )
1002+ . substring ( 0 , 20 ) ;
9991003 const downloadFilename = filename || `conversation_${ convId } _${ truncatedSuffix } .json` ;
10001004
10011005 const conversationJson = JSON . stringify ( data , null , 2 ) ;
10021006 const blob = new Blob ( [ conversationJson ] , {
1003- type : 'application/json' ,
1007+ type : 'application/json'
10041008 } ) ;
10051009 const url = URL . createObjectURL ( blob ) ;
10061010 const a = document . createElement ( 'a' ) ;
@@ -1073,11 +1077,18 @@ class ChatStore {
10731077
10741078 if ( Array . isArray ( parsedData ) ) {
10751079 importedData = parsedData ;
1076- } else if ( parsedData && typeof parsedData === 'object' && 'conv' in parsedData && 'messages' in parsedData ) {
1080+ } else if (
1081+ parsedData &&
1082+ typeof parsedData === 'object' &&
1083+ 'conv' in parsedData &&
1084+ 'messages' in parsedData
1085+ ) {
10771086 // Single conversation object
10781087 importedData = [ parsedData ] ;
10791088 } else {
1080- throw new Error ( 'Invalid file format: expected array of conversations or single conversation object' ) ;
1089+ throw new Error (
1090+ 'Invalid file format: expected array of conversations or single conversation object'
1091+ ) ;
10811092 }
10821093
10831094 const result = await DatabaseStore . importConversations ( importedData ) ;
0 commit comments