fix: proxy check
This commit is contained in:
parent
dedabe320e
commit
4a32976483
@ -102,7 +102,7 @@ app.whenReady().then(() => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
ipcMain.handle('set-proxy', (_, proxy: string) => {
|
ipcMain.handle('set-proxy', (_, proxy: string) => {
|
||||||
session.defaultSession.setProxy({ proxyRules: proxy })
|
session.defaultSession.setProxy(proxy ? { proxyRules: proxy } : {})
|
||||||
})
|
})
|
||||||
|
|
||||||
// 触发检查更新(此方法用于被渲染线程调用,例如页面点击检查更新按钮来调用此方法)
|
// 触发检查更新(此方法用于被渲染线程调用,例如页面点击检查更新按钮来调用此方法)
|
||||||
|
|||||||
2
src/preload/index.d.ts
vendored
2
src/preload/index.d.ts
vendored
@ -10,7 +10,7 @@ declare global {
|
|||||||
}>
|
}>
|
||||||
checkForUpdate: () => void
|
checkForUpdate: () => void
|
||||||
openWebsite: (url: string) => void
|
openWebsite: (url: string) => void
|
||||||
setProxy: (proxy: string) => void
|
setProxy: (proxy: string | undefined) => void
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -27,7 +27,7 @@ const GeneralSettings: FC = () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const onSetProxyUrl = () => {
|
const onSetProxyUrl = () => {
|
||||||
if (!proxyUrl || !isValidProxyUrl(proxyUrl)) {
|
if (proxyUrl && !isValidProxyUrl(proxyUrl)) {
|
||||||
window.message.error({ content: t('message.error.invalid.proxy.url'), key: 'proxy-error' })
|
window.message.error({ content: t('message.error.invalid.proxy.url'), key: 'proxy-error' })
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,7 +2,7 @@ import i18n from '@renderer/i18n'
|
|||||||
import store from '@renderer/store'
|
import store from '@renderer/store'
|
||||||
import { setGenerating } from '@renderer/store/runtime'
|
import { setGenerating } from '@renderer/store/runtime'
|
||||||
import { Assistant, Message, Provider, Topic } from '@renderer/types'
|
import { Assistant, Message, Provider, Topic } from '@renderer/types'
|
||||||
import { getErrorMessage, uuid } from '@renderer/utils'
|
import { uuid } from '@renderer/utils'
|
||||||
import dayjs from 'dayjs'
|
import dayjs from 'dayjs'
|
||||||
import { getAssistantProvider, getDefaultModel, getProviderByModel, getTopNamingModel } from './assistant'
|
import { getAssistantProvider, getDefaultModel, getProviderByModel, getTopNamingModel } from './assistant'
|
||||||
import { EVENT_NAMES, EventEmitter } from './event'
|
import { EVENT_NAMES, EventEmitter } from './event'
|
||||||
@ -92,15 +92,13 @@ export async function checkApi(provider: Provider) {
|
|||||||
|
|
||||||
const providerSdk = new ProviderSDK(provider)
|
const providerSdk = new ProviderSDK(provider)
|
||||||
|
|
||||||
const { valid, error } = await providerSdk.check()
|
const { valid } = await providerSdk.check()
|
||||||
|
|
||||||
window.message[valid ? 'success' : 'error']({
|
window.message[valid ? 'success' : 'error']({
|
||||||
key: 'api-check',
|
key: 'api-check',
|
||||||
style: { marginTop: '3vh' },
|
style: { marginTop: '3vh' },
|
||||||
duration: valid ? 2 : 8,
|
duration: valid ? 2 : 8,
|
||||||
content: valid
|
content: valid ? i18n.t('message.api.connection.success') : i18n.t('message.api.connection.failed')
|
||||||
? i18n.t('message.api.connection.success')
|
|
||||||
: i18n.t('message.api.connection.failed') + ' : ' + getErrorMessage(error)
|
|
||||||
})
|
})
|
||||||
|
|
||||||
return valid
|
return valid
|
||||||
|
|||||||
@ -206,10 +206,5 @@ export const capitalizeFirstLetter = (str: string) => {
|
|||||||
|
|
||||||
// is valid proxy url
|
// is valid proxy url
|
||||||
export const isValidProxyUrl = (url: string) => {
|
export const isValidProxyUrl = (url: string) => {
|
||||||
try {
|
return url.includes('://')
|
||||||
new URL(url)
|
|
||||||
return true
|
|
||||||
} catch (error) {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user