diff --git a/src/renderer/src/i18n/locales/zh-cn.json b/src/renderer/src/i18n/locales/zh-cn.json index c425621899..9973630d3c 100644 --- a/src/renderer/src/i18n/locales/zh-cn.json +++ b/src/renderer/src/i18n/locales/zh-cn.json @@ -828,7 +828,12 @@ "api_key": "Tavily API 密钥", "api_key.placeholder": "请输入 Tavily API 密钥" }, - "search_with_time": "搜索包含日期" + "search_with_time": "搜索包含日期", + "search_max_result": "搜索结果个数", + "search_result_default": "默认", + "blacklist": "黑名单", + "blacklist_description": "在搜索结果中不会出现以下网站的结果", + "blacklist_tooltip": "请使用以下格式(换行分隔)\nexample.com\nhttps://www.example.com\nhttps://example.com\n*://*.example.com" } }, "translate": { diff --git a/src/renderer/src/pages/settings/WebSearchSettings.tsx b/src/renderer/src/pages/settings/WebSearchSettings.tsx index c95044b77b..307be41101 100644 --- a/src/renderer/src/pages/settings/WebSearchSettings.tsx +++ b/src/renderer/src/pages/settings/WebSearchSettings.tsx @@ -4,8 +4,10 @@ import { HStack } from '@renderer/components/Layout' import { useTheme } from '@renderer/context/ThemeProvider' import { useWebSearchProvider } from '@renderer/hooks/useWebSearchProviders' import { useAppDispatch, useAppSelector } from '@renderer/store' -import { setSearchWithTime } from '@renderer/store/websearch' -import { Input, Switch, Typography } from 'antd' +import { setExcludeDomains, setMaxResult, setSearchWithTime } from '@renderer/store/websearch' +import { formatDomains } from '@renderer/utils/blacklist' +import { Alert, Input, Slider, Switch, Typography } from 'antd' +import TextArea from 'antd/es/input/TextArea' import { FC, useEffect, useState } from 'react' import { useTranslation } from 'react-i18next' import styled from 'styled-components' @@ -29,6 +31,11 @@ const WebSearchSettings: FC = () => { const [apiKey, setApiKey] = useState(provider.apiKey) const logo = theme === 'dark' ? tavilyLogoDark : tavilyLogo const searchWithTime = useAppSelector((state) => state.websearch.searchWithTime) + const maxResults = useAppSelector((state) => state.websearch.maxResults) + const excludeDomains = useAppSelector((state) => state.websearch.excludeDomains) + const [errFormat, setErrFormat] = useState(false) + const [blacklistInput, setBlacklistInput] = useState('') + const dispatch = useAppDispatch() useEffect(() => { @@ -39,6 +46,20 @@ const WebSearchSettings: FC = () => { } }, [apiKey, provider, updateProvider]) + useEffect(() => { + if (excludeDomains) { + setBlacklistInput(excludeDomains.join('\n')) + } + }, [excludeDomains]) + + function updateManualBlacklist(blacklist: string) { + const blacklistDomains = blacklist.split('\n').filter((url) => url.trim() !== '') + const { formattedDomains, hasError } = formatDomains(blacklistDomains) + setErrFormat(hasError) + if (hasError) return + dispatch(setExcludeDomains(formattedDomains)) + } + return ( @@ -70,6 +91,34 @@ const WebSearchSettings: FC = () => { {t('settings.websearch.search_with_time')} dispatch(setSearchWithTime(checked))} /> + + {t('settings.websearch.search_max_result')} + dispatch(setMaxResult(value))} + /> + + + + {t('settings.websearch.blacklist')} + + + {t('settings.websearch.blacklist_description')} + +