From 50438dd612033d1903512f3988b4bf53990cba29 Mon Sep 17 00:00:00 2001 From: kangfenmao Date: Wed, 12 Feb 2025 15:18:53 +0800 Subject: [PATCH] feat: WebDAV data backup and restore secondary confirmation #1326 close #1326 --- src/renderer/src/config/models.ts | 6 +----- src/renderer/src/i18n/locales/en-us.json | 2 ++ src/renderer/src/i18n/locales/ja-jp.json | 2 ++ src/renderer/src/i18n/locales/ru-ru.json | 2 ++ src/renderer/src/i18n/locales/zh-cn.json | 2 ++ src/renderer/src/i18n/locales/zh-tw.json | 2 ++ .../pages/settings/DataSettings/DataSettings.tsx | 16 +++++++--------- .../settings/DataSettings/WebDavSettings.tsx | 11 ++++++++++- src/renderer/src/providers/OpenAIProvider.ts | 3 ++- 9 files changed, 30 insertions(+), 16 deletions(-) diff --git a/src/renderer/src/config/models.ts b/src/renderer/src/config/models.ts index 0192046f..a16ab17a 100644 --- a/src/renderer/src/config/models.ts +++ b/src/renderer/src/config/models.ts @@ -1402,11 +1402,7 @@ export function isWebSearchModel(model: Model): boolean { } if (provider.id === 'aihubmix') { - const models = [ - 'gemini-2.0-flash-search', - 'gemini-2.0-flash-exp-search', - 'gemini-2.0-pro-exp-02-05-search' - ] + const models = ['gemini-2.0-flash-search', 'gemini-2.0-flash-exp-search', 'gemini-2.0-pro-exp-02-05-search'] return models.includes(model?.id) } diff --git a/src/renderer/src/i18n/locales/en-us.json b/src/renderer/src/i18n/locales/en-us.json index 7eef03e7..14a1001f 100644 --- a/src/renderer/src/i18n/locales/en-us.json +++ b/src/renderer/src/i18n/locales/en-us.json @@ -433,6 +433,8 @@ "webdav.noSync": "Waiting for next backup", "webdav.syncError": "Backup Error", "webdav.lastSync": "Last Backup", + "webdav.restore.title": "Restore from WebDAV", + "webdav.restore.content": "Restore from WebDAV will overwrite the current data, continue?", "notion.api_key": "Notion API Key", "notion.database_id": "Notion Database ID", "notion.title": "Notion Configuration" diff --git a/src/renderer/src/i18n/locales/ja-jp.json b/src/renderer/src/i18n/locales/ja-jp.json index 0b0eca04..5eb1f472 100644 --- a/src/renderer/src/i18n/locales/ja-jp.json +++ b/src/renderer/src/i18n/locales/ja-jp.json @@ -424,6 +424,8 @@ "webdav.noSync": "次回のバックアップを待っています", "webdav.syncError": "バックアップエラー", "webdav.lastSync": "最終同期", + "webdav.restore.title": "WebDAVから復元", + "webdav.restore.content": "WebDAVから復元すると、現在のデータが上書きされます。続行しますか?", "notion.api_key": "Notion APIキー", "notion.database_id": "Notion データベースID", "notion.title": "Notion 設定" diff --git a/src/renderer/src/i18n/locales/ru-ru.json b/src/renderer/src/i18n/locales/ru-ru.json index 2efb367c..a21dc76a 100644 --- a/src/renderer/src/i18n/locales/ru-ru.json +++ b/src/renderer/src/i18n/locales/ru-ru.json @@ -425,6 +425,8 @@ "webdav.noSync": "Ожидание следующего резервного копирования", "webdav.syncError": "Ошибка резервного копирования", "webdav.lastSync": "Последняя синхронизация", + "webdav.restore.title": "Восстановление с WebDAV", + "webdav.restore.content": "Восстановление с WebDAV перезапишет текущие данные, продолжить?", "notion.api_key": "Ключ API Notion", "notion.database_id": "ID базы данных Notion", "notion.title": "Настройки Notion" diff --git a/src/renderer/src/i18n/locales/zh-cn.json b/src/renderer/src/i18n/locales/zh-cn.json index 1dc2613b..c742f970 100644 --- a/src/renderer/src/i18n/locales/zh-cn.json +++ b/src/renderer/src/i18n/locales/zh-cn.json @@ -432,6 +432,8 @@ "webdav.noSync": "等待下次备份", "webdav.syncError": "备份错误", "webdav.lastSync": "上次备份时间", + "webdav.restore.title": "从 WebDAV 恢复", + "webdav.restore.content": "从 WebDAV 恢复将覆盖当前数据,是否继续?", "notion.api_key": "Notion 密钥", "notion.database_id": "Notion 数据库ID", "notion.title": "Notion 配置" diff --git a/src/renderer/src/i18n/locales/zh-tw.json b/src/renderer/src/i18n/locales/zh-tw.json index 2094dbc0..45447c96 100644 --- a/src/renderer/src/i18n/locales/zh-tw.json +++ b/src/renderer/src/i18n/locales/zh-tw.json @@ -431,6 +431,8 @@ "webdav.noSync": "等待下次備份", "webdav.syncError": "備份錯誤", "webdav.lastSync": "上次同步時間", + "webdav.restore.title": "從 WebDAV 恢復", + "webdav.restore.content": "從 WebDAV 恢復將覆蓋當前資料,是否繼續?", "notion.api_key": "Notion 金鑰", "notion.database_id": "Notion 資料庫 ID", "notion.title": "Notion 配置" diff --git a/src/renderer/src/pages/settings/DataSettings/DataSettings.tsx b/src/renderer/src/pages/settings/DataSettings/DataSettings.tsx index c1caeaa8..9eab93dd 100644 --- a/src/renderer/src/pages/settings/DataSettings/DataSettings.tsx +++ b/src/renderer/src/pages/settings/DataSettings/DataSettings.tsx @@ -5,7 +5,7 @@ import { backup, reset, restore } from '@renderer/services/BackupService' import { RootState, useAppDispatch } from '@renderer/store' import { setNotionApiKey, setNotionDatabaseID } from '@renderer/store/settings' import { AppInfo } from '@renderer/types' -import { Button,Modal, Typography } from 'antd' +import { Button, Modal, Typography } from 'antd' import Input from 'antd/es/input/Input' import { FC, useEffect, useState } from 'react' import { useTranslation } from 'react-i18next' @@ -23,17 +23,16 @@ const NotionSettings: FC = () => { // 这里可以添加 Notion 相关的状态和逻辑 // 例如: - const notionApiKey = useSelector((state: RootState) => state.settings.notionApiKey); - const notionDatabaseID = useSelector((state: RootState) => state.settings.notionDatabaseID); + const notionApiKey = useSelector((state: RootState) => state.settings.notionApiKey) + const notionDatabaseID = useSelector((state: RootState) => state.settings.notionDatabaseID) const handleNotionTokenChange = (e: React.ChangeEvent) => { dispatch(setNotionApiKey(e.target.value)) - }; + } const handleNotionDatabaseIdChange = (e: React.ChangeEvent) => { dispatch(setNotionDatabaseID(e.target.value)) - }; - + } return ( @@ -42,8 +41,8 @@ const NotionSettings: FC = () => { {t('settings.data.notion.api_key')} - { - ) } diff --git a/src/renderer/src/pages/settings/DataSettings/WebDavSettings.tsx b/src/renderer/src/pages/settings/DataSettings/WebDavSettings.tsx index e2ed1802..d641ee8f 100644 --- a/src/renderer/src/pages/settings/DataSettings/WebDavSettings.tsx +++ b/src/renderer/src/pages/settings/DataSettings/WebDavSettings.tsx @@ -66,6 +66,15 @@ const WebDavSettings: FC = () => { setRestoring(false) } + const onPressRestore = () => { + window.modal.confirm({ + title: t('settings.data.webdav.restore.title'), + content: t('settings.data.webdav.restore.content'), + centered: true, + onOk: onRestore + }) + } + const onSyncIntervalChange = (value: number) => { setSyncInterval(value) dispatch(_setWebdavSyncInterval(value)) @@ -158,7 +167,7 @@ const WebDavSettings: FC = () => { - diff --git a/src/renderer/src/providers/OpenAIProvider.ts b/src/renderer/src/providers/OpenAIProvider.ts index c3c3c75c..3bce28f5 100644 --- a/src/renderer/src/providers/OpenAIProvider.ts +++ b/src/renderer/src/providers/OpenAIProvider.ts @@ -161,6 +161,7 @@ export default class OpenAIProvider extends BaseProvider { const { contextCount, maxTokens, streamOutput } = getAssistantSettings(assistant) let systemMessage = assistant.prompt ? { role: 'system', content: assistant.prompt } : undefined + if (['o1', 'o1-2024-12-17'].includes(model.id) || model.id.startsWith('o3')) { systemMessage = { role: 'developer', @@ -344,7 +345,7 @@ export default class OpenAIProvider extends BaseProvider { // 针对思考类模型的返回,总结仅截取之后的内容 let content = response.choices[0].message?.content || '' content = content.replace(/^(.*?)<\/think>/s, '') - + return removeSpecialCharacters(content.substring(0, 50)) }