Skip to content

Commit

Permalink
Update turboGPT.js
Browse files Browse the repository at this point in the history
  • Loading branch information
14-3dgar committed Jul 31, 2023
1 parent abdb1c8 commit e3c8c8e
Showing 1 changed file with 7 additions and 13 deletions.
20 changes: 7 additions & 13 deletions extensions/lolemo/turboGPT.js
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@

exportChat(args) {
const chatID = args.chatID;
if (this.chatHistories.hasOwnProperty(chatID)) {
if (this.chatHistories[chatID] !== undefined) {
const chatHistory = this.chatHistories[chatID];
const json = JSON.stringify(chatHistory);
return json;
Expand Down Expand Up @@ -328,37 +328,31 @@

exportAll() {
const allChats = {};
for (const chatID in this.chatHistories) {
if (this.chatHistories.hasOwnProperty(chatID)) {
allChats[chatID] = this.chatHistories[chatID];
}
const chatIDs = Object.keys(this.chatHistories);
for (const chatID of chatIDs) {
allChats[chatID] = this.chatHistories[chatID];
}

const json = JSON.stringify(allChats);
return json;
}

importAll(args) {
const json = args.json;
const mergeOption = args.merge.toLowerCase();

let importedChats;

try {
importedChats = JSON.parse(json);
} catch (error) {
console.error('Error parsing JSON:', error.message);
return;
}

if (typeof importedChats === 'object' && importedChats !== null) {
if (mergeOption === 'remove all and import') {
this.chatHistories = importedChats;
} else if (mergeOption === 'merge with existing chats') {
for (const chatID in importedChats) {
if (importedChats.hasOwnProperty(chatID)) {
this.chatHistories[chatID] = importedChats[chatID];
}
const importedChatIDs = Object.keys(importedChats);
for (const chatID of importedChatIDs) {
this.chatHistories[chatID] = importedChats[chatID];
}
} else {
console.error('Invalid merge option. Expected "remove all and import" or "merge with existing chats".');
Expand Down

0 comments on commit e3c8c8e

Please sign in to comment.