import { useCallback, useState } from 'react' import { Input, ScrollArea, Switch } from '@janhq/joi' import { useAtom, useAtomValue } from 'jotai' import { EyeIcon, EyeOffIcon, XIcon, ArrowLeftIcon } from 'lucide-react' import { useDebouncedCallback } from 'use-debounce' import { useConfigurations } from '@/hooks/useConfigurations' import { ignoreSslAtom, proxyAtom, verifyProxySslAtom, verifyProxyHostSslAtom, verifyPeerSslAtom, verifyHostSslAtom, noProxyAtom, proxyUsernameAtom, proxyPasswordAtom, } from '@/helpers/atoms/AppConfig.atom' import { showScrollBarAtom } from '@/helpers/atoms/Setting.atom' const ProxySettings = ({ onBack }: { onBack: () => void }) => { const [proxy, setProxy] = useAtom(proxyAtom) const [noProxy, setNoProxy] = useAtom(noProxyAtom) const [partialProxy, setPartialProxy] = useState(proxy) const [proxyUsername, setProxyUsername] = useAtom(proxyUsernameAtom) const [proxyPassword, setProxyPassword] = useAtom(proxyPasswordAtom) const [proxyPartialPassword, setProxyPartialPassword] = useState(proxyPassword) const [proxyPartialUsername, setProxyPartialUsername] = useState(proxyUsername) const { configurePullOptions } = useConfigurations() const [ignoreSSL, setIgnoreSSL] = useAtom(ignoreSslAtom) const [verifyProxySSL, setVerifyProxySSL] = useAtom(verifyProxySslAtom) const [verifyProxyHostSSL, setVerifyProxyHostSSL] = useAtom( verifyProxyHostSslAtom ) const [verifyPeerSSL, setVerifyPeerSSL] = useAtom(verifyPeerSslAtom) const [verifyHostSSL, setVerifyHostSSL] = useAtom(verifyHostSslAtom) const [showPassword, setShowPassword] = useState(false) const showScrollBar = useAtomValue(showScrollBarAtom) const updatePullOptions = useDebouncedCallback( () => configurePullOptions(), 1000 ) const onProxyChange = useDebouncedCallback((value: string) => { if (value.trim().startsWith('http')) { setProxy(value.trim()) updatePullOptions() } else { setProxy('') updatePullOptions() } }, 1000) const onProxyUsernameChange = useDebouncedCallback((value: string) => { setProxyUsername(value) updatePullOptions() }, 1000) const onProxyPasswordChange = useDebouncedCallback((value: string) => { setProxyPassword(value) updatePullOptions() }, 1000) const handleProxyInputChange = useCallback( (e: React.ChangeEvent) => { const value = e.target.value || '' setPartialProxy(value) onProxyChange(value) }, [setPartialProxy, onProxyChange] ) const handleProxyUsernameInputChange = useCallback( (e: React.ChangeEvent) => { const value = e.target.value || '' setProxyPartialUsername(value) onProxyUsernameChange(value) }, [setProxyPartialUsername, onProxyUsernameChange] ) const handleProxyPasswordInputChange = useCallback( (e: React.ChangeEvent) => { const value = e.target.value || '' setProxyPartialPassword(value) onProxyPasswordChange(value) }, [setProxyPartialPassword, onProxyPasswordChange] ) const onNoProxyChange = useCallback( (e: React.ChangeEvent) => { const listNoProxy = e.target.value || '' const listNoProxyTrim = listNoProxy.split(',').map((item) => item.trim()) setNoProxy(listNoProxyTrim.join(',')) updatePullOptions() }, [setNoProxy, updatePullOptions] ) return ( {/* Header */}
/ HTTPS Proxy
{/* Content */}

Proxy Configuration

URL and port of your proxy server.

{partialProxy && ( )}
} />

Credentials for your proxy server (if required).

{proxyUsername && ( )}
} /> {proxyPassword && ( )}
} />
{/* No Proxy */}

List of hosts that should bypass the proxy.

{noProxy && ( )}
} />

SSL Verification

{/* Ignore SSL certificates */}
Ignore SSL certificates

Allow self-signed or unverified certificates (may be required for certain proxies). Enable this reduces security. Only use this if you trust your proxy server.

{ setIgnoreSSL(e.target.checked) updatePullOptions() }} />
{/* Verify Proxy SSL */}
Verify Proxy SSL

Validate SSL certificate when connecting to the proxy server.

{ setVerifyProxySSL(e.target.checked) updatePullOptions() }} />
{/* Verify Proxy Host SSL */}
Verify Proxy Host SSL

Validate SSL certificate of the proxy server host.

{ setVerifyProxyHostSSL(e.target.checked) updatePullOptions() }} />
{/* Verify Peer SSL */}
Verify Peer SSL

Validate SSL certificate of the peer connections.

{ setVerifyPeerSSL(e.target.checked) updatePullOptions() }} />
{/* Verify Host SSL */}
Verify Host SSL

Validate SSL certificate of destination hosts.

{ setVerifyHostSSL(e.target.checked) updatePullOptions() }} />
) } export default ProxySettings