fix bug: #2474
This commit is contained in:
parent
2ab8f325df
commit
acc803aa43
@ -10,6 +10,7 @@ import {
|
||||
} from '@ant-design/icons'
|
||||
import { Navbar, NavbarCenter } from '@renderer/components/app/Navbar'
|
||||
import { isLocalAi } from '@renderer/config/env'
|
||||
import ModelSettings from '@renderer/pages/settings/ModelSettings/ModelSettings'
|
||||
import { FC } from 'react'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { Link, Route, Routes, useLocation } from 'react-router-dom'
|
||||
@ -19,7 +20,6 @@ import AboutSettings from './AboutSettings'
|
||||
import DataSettings from './DataSettings/DataSettings'
|
||||
import DisplaySettings from './DisplaySettings/DisplaySettings'
|
||||
import GeneralSettings from './GeneralSettings'
|
||||
import ModelSettings from '@renderer/pages/settings/ModelSettings/ModelSettings'
|
||||
import ProvidersList from './ProviderSettings'
|
||||
import QuickAssistantSettings from './QuickAssistantSettings'
|
||||
import ShortcutSettings from './ShortcutSettings'
|
||||
|
||||
@ -6,7 +6,7 @@ import { useWebSearchProvider } from '@renderer/hooks/useWebSearchProviders'
|
||||
import { useAppDispatch, useAppSelector } from '@renderer/store'
|
||||
import { setExcludeDomains, setMaxResult, setSearchWithTime } from '@renderer/store/websearch'
|
||||
import { formatDomains } from '@renderer/utils/blacklist'
|
||||
import { Alert, Input, Slider, Switch, Typography } from 'antd'
|
||||
import { Alert, Button, Input, Slider, Switch, Typography } from 'antd'
|
||||
import TextArea from 'antd/es/input/TextArea'
|
||||
import { FC, useEffect, useState } from 'react'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
@ -113,11 +113,11 @@ const WebSearchSettings: FC = () => {
|
||||
<TextArea
|
||||
value={blacklistInput}
|
||||
onChange={(e) => setBlacklistInput(e.target.value)}
|
||||
onBlur={() => updateManualBlacklist(blacklistInput)}
|
||||
placeholder={t('settings.websearch.blacklist_tooltip')}
|
||||
autoSize={{ minRows: 2, maxRows: 6 }}
|
||||
autoSize={{ minRows: 4, maxRows: 8 }}
|
||||
rows={4}
|
||||
/>
|
||||
<Button onClick={() => updateManualBlacklist(blacklistInput)}>{t('common.save')}</Button>
|
||||
{errFormat && <Alert message={t('settings.websearch.blacklist_tooltip')} type="error" />}
|
||||
</SettingGroup>
|
||||
</SettingContainer>
|
||||
|
||||
@ -2,7 +2,6 @@ interface FormatDomainsResult {
|
||||
formattedDomains: string[]
|
||||
hasError: boolean
|
||||
}
|
||||
|
||||
export function formatDomains(urls: string[]): FormatDomainsResult {
|
||||
let hasError = false
|
||||
const formattedDomains: string[] = []
|
||||
@ -16,13 +15,29 @@ export function formatDomains(urls: string[]): FormatDomainsResult {
|
||||
modifiedUrlString = modifiedUrlString.substring(4)
|
||||
}
|
||||
|
||||
// 2. 检查并添加协议前缀
|
||||
if (!modifiedUrlString.match(/^[a-zA-Z]+:\/\//)) {
|
||||
modifiedUrlString = 'https://' + modifiedUrlString
|
||||
// 2. 处理域名通配符 (*.example.com)
|
||||
let domain = modifiedUrlString
|
||||
if (domain.includes('://')) {
|
||||
const parts = domain.split('://')
|
||||
const domainPart = parts[1]
|
||||
if (domainPart.startsWith('*.')) {
|
||||
domain = parts[0] + '://' + domainPart.substring(2)
|
||||
} else {
|
||||
domain = modifiedUrlString
|
||||
}
|
||||
} else if (domain.startsWith('*.')) {
|
||||
domain = domain.substring(2)
|
||||
} else {
|
||||
domain = modifiedUrlString
|
||||
}
|
||||
|
||||
// 3. URL 解析和验证
|
||||
const url = new URL(modifiedUrlString)
|
||||
// 3. 检查并添加协议前缀
|
||||
if (!domain.match(/^[a-zA-Z]+:\/\//)) {
|
||||
domain = 'https://' + domain
|
||||
}
|
||||
|
||||
// 4. URL 解析和验证
|
||||
const url = new URL(domain)
|
||||
if (url.protocol !== 'https:') {
|
||||
if (url.protocol !== 'http:') {
|
||||
hasError = true
|
||||
@ -31,14 +46,8 @@ export function formatDomains(urls: string[]): FormatDomainsResult {
|
||||
}
|
||||
}
|
||||
|
||||
// 4. 通配符处理
|
||||
let domain = url.hostname
|
||||
if (domain.startsWith('*.')) {
|
||||
domain = domain.substring(2)
|
||||
}
|
||||
|
||||
// 5. 格式化
|
||||
const formattedDomain = `https://${domain}`
|
||||
const formattedDomain = `https://${url.hostname}`
|
||||
formattedDomains.push(formattedDomain)
|
||||
} catch (error) {
|
||||
hasError = true
|
||||
@ -48,3 +57,4 @@ export function formatDomains(urls: string[]): FormatDomainsResult {
|
||||
|
||||
return { formattedDomains, hasError }
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user