refac/pref: chat import optimization
Co-Authored-By: G30 <50341825+silentoplayz@users.noreply.github.com>
This commit is contained in:
@@ -16,8 +16,8 @@
|
||||
deleteAllChats,
|
||||
getAllChats,
|
||||
getChatList,
|
||||
importChat,
|
||||
getPinnedChatList
|
||||
getPinnedChatList,
|
||||
importChats
|
||||
} from '$lib/apis/chats';
|
||||
import { getImportOrigin, convertOpenAIChats } from '$lib/utils';
|
||||
import { onMount, getContext } from 'svelte';
|
||||
@@ -52,7 +52,7 @@
|
||||
console.log('Unable to import chats:', error);
|
||||
}
|
||||
}
|
||||
importChats(chats);
|
||||
importChatsHandler(chats);
|
||||
};
|
||||
|
||||
if (importFiles.length > 0) {
|
||||
@@ -60,24 +60,33 @@
|
||||
}
|
||||
}
|
||||
|
||||
const importChats = async (_chats) => {
|
||||
for (const chat of _chats) {
|
||||
console.log(chat);
|
||||
|
||||
const importChatsHandler = async (_chats) => {
|
||||
const chats = _chats.map((chat) => {
|
||||
if (chat.chat) {
|
||||
await importChat(
|
||||
localStorage.token,
|
||||
chat.chat,
|
||||
chat.meta ?? {},
|
||||
false,
|
||||
null,
|
||||
chat?.created_at ?? null,
|
||||
chat?.updated_at ?? null
|
||||
);
|
||||
return {
|
||||
chat: chat.chat,
|
||||
meta: chat.meta ?? {},
|
||||
pinned: false,
|
||||
folder_id: chat?.folder_id ?? null,
|
||||
created_at: chat?.created_at ?? null,
|
||||
updated_at: chat?.updated_at ?? null
|
||||
};
|
||||
} else {
|
||||
// Legacy format
|
||||
await importChat(localStorage.token, chat, {}, false, null);
|
||||
return {
|
||||
chat: chat,
|
||||
meta: {},
|
||||
pinned: false,
|
||||
folder_id: null,
|
||||
created_at: chat?.created_at ?? null,
|
||||
updated_at: chat?.updated_at ?? null
|
||||
};
|
||||
}
|
||||
});
|
||||
|
||||
const res = await importChats(localStorage.token, chats);
|
||||
if (res) {
|
||||
toast.success(`Successfully imported ${res.length} chats.`);
|
||||
}
|
||||
|
||||
currentChatPage.set(1);
|
||||
|
||||
Reference in New Issue
Block a user