feat: export conversations (#228)

This commit is contained in:
josc146
2023-04-21 21:21:21 +08:00
parent d615739f5b
commit 2f832a0f5b
4 changed files with 16 additions and 3 deletions
+2 -1
View File
@@ -102,5 +102,6 @@
"Keep Conversation Window in Background": "Keep conversation window in background, so that you can use shortcut keys to call it up in any program",
"Max Response Token Length": "Max Response Token Length",
"Max Conversation Length": "Max Conversation Length",
"Always pin the floating window": "Always pin the floating window"
"Always pin the floating window": "Always pin the floating window",
"Export": "Export"
}
+2 -1
View File
@@ -102,5 +102,6 @@
"Keep Conversation Window in Background": "保持对话窗口在后台, 以便在任何程序中使用快捷键呼出",
"Max Response Token Length": "响应的最大token长度",
"Max Conversation Length": "对话处理的最大长度",
"Always pin the floating window": "总是固定浮动窗口"
"Always pin the floating window": "总是固定浮动窗口",
"Export": "导出"
}
+2 -1
View File
@@ -102,5 +102,6 @@
"Keep Conversation Window in Background": "保持對話窗口在後臺, 以便在任何程序中使用快捷鍵呼出",
"Max Response Token Length": "響應的最大token長度",
"Max Conversation Length": "對話處理的最大長度",
"Always pin the floating window": "總是固定浮動視窗"
"Always pin the floating window": "總是固定浮動視窗",
"Export": "導出"
}
+10
View File
@@ -15,6 +15,7 @@ import ConversationCard from '../../components/ConversationCard'
import DeleteButton from '../../components/DeleteButton'
import { openUrl } from '../../utils/index.mjs'
import Browser from 'webextension-polyfill'
import FileSaver from 'file-saver'
function App() {
const { t } = useTranslation()
@@ -81,6 +82,12 @@ function App() {
await setSessionIdSafe(session.sessionId)
}
const exportConversations = async () => {
const sessions = await getSessions()
const blob = new Blob([JSON.stringify(sessions, null, 2)], { type: 'text/json;charset=utf-8' })
FileSaver.saveAs(blob, 'conversations.json')
}
const clearConversations = async () => {
const sessions = await resetSessions()
setSessions(sessions)
@@ -98,6 +105,9 @@ function App() {
<button className="normal-button" onClick={createNewChat}>
{t('New Chat')}
</button>
<button className="normal-button" onClick={exportConversations}>
{t('Export')}
</button>
</div>
<hr />
<div className="chat-list">