53f46218d3
* wip: silicon oauth * feat: Add custom protocol handler for SiliconFlow OAuth login * feat: Improve SiliconFlow OAuth flow with dynamic key update * feat: Enhance OAuth and Provider Settings UI * feat: Refactor SiliconFlow OAuth and update localization strings * chore: Update provider localization and system provider configuration * feat: Add OAuth support for AIHubMix provider
41 lines
1017 B
TypeScript
41 lines
1017 B
TypeScript
import { useProvider } from '@renderer/hooks/useProvider'
|
|
import { Provider } from '@renderer/types'
|
|
import { oauthWithAihubmix, oauthWithSiliconFlow } from '@renderer/utils/oauth'
|
|
import { Button, ButtonProps } from 'antd'
|
|
import { FC } from 'react'
|
|
import { useTranslation } from 'react-i18next'
|
|
|
|
interface Props extends ButtonProps {
|
|
provider: Provider
|
|
}
|
|
|
|
const OAuthButton: FC<Props> = (props) => {
|
|
const { t } = useTranslation()
|
|
const { provider, updateProvider } = useProvider(props.provider.id)
|
|
|
|
const onAuth = () => {
|
|
const onSuccess = (key: string) => {
|
|
if (key.trim()) {
|
|
updateProvider({ ...provider, apiKey: key })
|
|
window.message.success(t('auth.get_key_success'))
|
|
}
|
|
}
|
|
|
|
if (provider.id === 'silicon') {
|
|
oauthWithSiliconFlow(onSuccess)
|
|
}
|
|
|
|
if (provider.id === 'aihubmix') {
|
|
oauthWithAihubmix(onSuccess)
|
|
}
|
|
}
|
|
|
|
return (
|
|
<Button onClick={onAuth} {...props}>
|
|
{t('auth.get_key')}
|
|
</Button>
|
|
)
|
|
}
|
|
|
|
export default OAuthButton
|