feat(notion): 添加 Notion连接检查功能 (#1620)
- 在 Notion 配置页面添加"检查"按钮 - 实现 Notion 连接检查逻辑 - 添加相关国际化文本
This commit is contained in:
parent
fd4334f331
commit
710180997f
@ -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",
|
||||
|
||||
@ -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": "オフ",
|
||||
|
||||
@ -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": "Выключено",
|
||||
|
||||
@ -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": "关闭",
|
||||
|
||||
@ -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": "關閉",
|
||||
|
||||
@ -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<HTMLInputElement>) => {
|
||||
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 (
|
||||
<SettingGroup theme={theme}>
|
||||
<SettingTitle>{t('settings.data.notion.title')}</SettingTitle>
|
||||
<SettingRow>
|
||||
<SettingRowTitle>{t('settings.data.notion.database_id')}</SettingRowTitle>
|
||||
<HStack alignItems="center" gap="5px">
|
||||
<Input
|
||||
type="text"
|
||||
value={notionDatabaseID || ''}
|
||||
onChange={handleNotionDatabaseIdChange}
|
||||
onBlur={handleNotionDatabaseIdChange}
|
||||
style={{ width: 315 }}
|
||||
/>
|
||||
</HStack>
|
||||
</SettingRow>
|
||||
<SettingDivider />
|
||||
<SettingRow>
|
||||
<SettingRowTitle>{t('settings.data.notion.api_key')}</SettingRowTitle>
|
||||
@ -48,21 +86,12 @@ const NotionSettings: FC = () => {
|
||||
onBlur={handleNotionTokenChange}
|
||||
style={{ width: 250 }}
|
||||
/>
|
||||
<Button onClick={handleNotionConnectionCheck} style={{ width: 60 }}>
|
||||
{t('settings.data.notion.check.button')}
|
||||
</Button>
|
||||
</HStack>
|
||||
</SettingRow>
|
||||
<SettingDivider /> {/* 添加分割线 */}
|
||||
<SettingRow>
|
||||
<SettingRowTitle>{t('settings.data.notion.database_id')}</SettingRowTitle>
|
||||
<HStack alignItems="center" gap="5px">
|
||||
<Input
|
||||
type="text"
|
||||
value={notionDatabaseID || ''}
|
||||
onChange={handleNotionDatabaseIdChange}
|
||||
onBlur={handleNotionDatabaseIdChange}
|
||||
style={{ width: 250 }}
|
||||
/>
|
||||
</HStack>
|
||||
</SettingRow>
|
||||
</SettingGroup>
|
||||
)
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user