From f44e7e6a14cc62e2b0982dcaa45017dab9982cd5 Mon Sep 17 00:00:00 2001 From: Trey Dong <1346650911@qq.com> Date: Fri, 14 Feb 2025 10:52:16 +0800 Subject: [PATCH] =?UTF-8?q?feat(notion):=20=E6=B7=BB=E5=8A=A0=20Notion?= =?UTF-8?q?=E8=BF=9E=E6=8E=A5=E6=A3=80=E6=9F=A5=E5=8A=9F=E8=83=BD=20(#1620?= =?UTF-8?q?)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在 Notion 配置页面添加"检查"按钮 - 实现 Notion 连接检查逻辑 - 添加相关国际化文本 --- src/renderer/src/i18n/locales/en-us.json | 8 +++ src/renderer/src/i18n/locales/ja-jp.json | 8 +++ src/renderer/src/i18n/locales/ru-ru.json | 8 +++ src/renderer/src/i18n/locales/zh-cn.json | 8 +++ src/renderer/src/i18n/locales/zh-tw.json | 8 +++ .../settings/DataSettings/DataSettings.tsx | 53 ++++++++++++++----- 6 files changed, 81 insertions(+), 12 deletions(-) diff --git a/src/renderer/src/i18n/locales/en-us.json b/src/renderer/src/i18n/locales/en-us.json index 30d3a06a63..bd07c9e437 100644 --- a/src/renderer/src/i18n/locales/en-us.json +++ b/src/renderer/src/i18n/locales/en-us.json @@ -552,6 +552,14 @@ "notion.api_key": "Notion API Key", "notion.database_id": "Notion Database ID", "notion.title": "Notion Configuration", + "notion.check": { + "button": "Check", + "fail": "Connection failed, please check the configuration", + "success": "Connection successful", + "error": "Connection error, please check the network", + "empty_api_key": "Api_key is not configured", + "empty_database_id": "Database_id is not configured" + }, "title": "Data Settings", "webdav.autoSync": "Auto Backup", "webdav.autoSync.off": "Off", diff --git a/src/renderer/src/i18n/locales/ja-jp.json b/src/renderer/src/i18n/locales/ja-jp.json index 243cbe77a0..355982878e 100644 --- a/src/renderer/src/i18n/locales/ja-jp.json +++ b/src/renderer/src/i18n/locales/ja-jp.json @@ -552,6 +552,14 @@ "notion.api_key": "Notion APIキー", "notion.database_id": "Notion データベースID", "notion.title": "Notion 設定", + "notion.check": { + "button": "確認", + "fail": "接続に失敗しました。設定を確認してください。", + "success": "接続に成功しました。", + "error": "接続エラーが発生しました。ネットワークを確認してください。", + "empty_api_key": "Api_keyが設定されていません", + "empty_database_id": "Database_idが設定されていません" + }, "title": "データ設定", "webdav.autoSync": "自動バックアップ", "webdav.autoSync.off": "オフ", diff --git a/src/renderer/src/i18n/locales/ru-ru.json b/src/renderer/src/i18n/locales/ru-ru.json index f83a359966..4d5f7e213e 100644 --- a/src/renderer/src/i18n/locales/ru-ru.json +++ b/src/renderer/src/i18n/locales/ru-ru.json @@ -552,6 +552,14 @@ "notion.api_key": "Ключ API Notion", "notion.database_id": "ID базы данных Notion", "notion.title": "Настройки Notion", + "notion.check": { + "button": "Проверить", + "fail": "Ошибка подключения, проверьте настройки", + "success": "Подключение успешно", + "error": "Ошибка подключения, проверьте сеть", + "empty_api_key": "Не настроен Api_key", + "empty_database_id": "Не настроен Database_id" + }, "title": "Настройки данных", "webdav.autoSync": "Автоматическое резервное копирование", "webdav.autoSync.off": "Выключено", diff --git a/src/renderer/src/i18n/locales/zh-cn.json b/src/renderer/src/i18n/locales/zh-cn.json index e5f7b564f9..eb93bbaae5 100644 --- a/src/renderer/src/i18n/locales/zh-cn.json +++ b/src/renderer/src/i18n/locales/zh-cn.json @@ -552,6 +552,14 @@ "notion.api_key": "Notion 密钥", "notion.database_id": "Notion 数据库ID", "notion.title": "Notion 配置", + "notion.check": { + "button": "检查", + "fail": "连接失败,请检查配置", + "success": "连接成功", + "error": "连接异常,请检查网络", + "empty_api_key": "未配置Api_key", + "empty_database_id": "未配置Database_id" + }, "title": "数据设置", "webdav.autoSync": "自动备份", "webdav.autoSync.off": "关闭", diff --git a/src/renderer/src/i18n/locales/zh-tw.json b/src/renderer/src/i18n/locales/zh-tw.json index 5577bd0f67..7001096abf 100644 --- a/src/renderer/src/i18n/locales/zh-tw.json +++ b/src/renderer/src/i18n/locales/zh-tw.json @@ -550,6 +550,14 @@ "notion.api_key": "Notion 金鑰", "notion.database_id": "Notion 資料庫 ID", "notion.title": "Notion 配置", + "notion.check": { + "button": "檢查", + "fail": "連線失敗,請檢查配置", + "success": "連線成功", + "error": "連線異常,請檢查網路", + "empty_api_key": "未配置Api_key", + "empty_database_id": "未配置Database_id" + }, "title": "數據設定", "webdav.autoSync": "自動備份", "webdav.autoSync.off": "關閉", diff --git a/src/renderer/src/pages/settings/DataSettings/DataSettings.tsx b/src/renderer/src/pages/settings/DataSettings/DataSettings.tsx index 9eab93dd3d..174a94c782 100644 --- a/src/renderer/src/pages/settings/DataSettings/DataSettings.tsx +++ b/src/renderer/src/pages/settings/DataSettings/DataSettings.tsx @@ -1,4 +1,5 @@ import { FileSearchOutlined, FolderOpenOutlined, SaveOutlined } from '@ant-design/icons' +import { Client } from '@notionhq/client' import { HStack } from '@renderer/components/Layout' import { useTheme } from '@renderer/context/ThemeProvider' import { backup, reset, restore } from '@renderer/services/BackupService' @@ -33,10 +34,47 @@ const NotionSettings: FC = () => { const handleNotionDatabaseIdChange = (e: React.ChangeEvent) => { dispatch(setNotionDatabaseID(e.target.value)) } + const handleNotionConnectionCheck = () => { + if (notionApiKey === null) { + window.message.error(t('settings.data.notion.check.empty_api_key')) + return + } + if (notionDatabaseID === null) { + window.message.error(t('settings.data.notion.check.empty_database_id')) + return + } + const notion = new Client({ auth: notionApiKey }) + notion.databases + .retrieve({ + database_id: notionDatabaseID + }) + .then((result) => { + if (result) { + window.message.success(t('settings.data.notion.check.success')) + } else { + window.message.error(t('settings.data.notion.check.fail')) + } + }) + .catch(() => { + window.message.error(t('settings.data.notion.check.error')) + }) + } return ( {t('settings.data.notion.title')} + + {t('settings.data.notion.database_id')} + + + + {t('settings.data.notion.api_key')} @@ -48,21 +86,12 @@ const NotionSettings: FC = () => { onBlur={handleNotionTokenChange} style={{ width: 250 }} /> + {/* 添加分割线 */} - - {t('settings.data.notion.database_id')} - - - - ) }