From 2f832a0f5b80857c381aa2283e5a11826da99a50 Mon Sep 17 00:00:00 2001 From: josc146 Date: Fri, 21 Apr 2023 21:21:21 +0800 Subject: [PATCH] feat: export conversations (#228) --- src/_locales/en/main.json | 3 ++- src/_locales/zh-hans/main.json | 3 ++- src/_locales/zh-hant/main.json | 3 ++- src/pages/IndependentPanel/App.jsx | 10 ++++++++++ 4 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/_locales/en/main.json b/src/_locales/en/main.json index baa0dcc..1c15b63 100644 --- a/src/_locales/en/main.json +++ b/src/_locales/en/main.json @@ -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" } diff --git a/src/_locales/zh-hans/main.json b/src/_locales/zh-hans/main.json index 172851e..5783f73 100644 --- a/src/_locales/zh-hans/main.json +++ b/src/_locales/zh-hans/main.json @@ -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": "导出" } diff --git a/src/_locales/zh-hant/main.json b/src/_locales/zh-hant/main.json index 96585f0..ef9421a 100644 --- a/src/_locales/zh-hant/main.json +++ b/src/_locales/zh-hant/main.json @@ -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": "導出" } diff --git a/src/pages/IndependentPanel/App.jsx b/src/pages/IndependentPanel/App.jsx index b1db66b..2a3f541 100644 --- a/src/pages/IndependentPanel/App.jsx +++ b/src/pages/IndependentPanel/App.jsx @@ -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() { +