* feat: migrate legacy local storage data to new app * chore: refactor localstorage db read * chore: clean up * chore: migrate api key setting * chore: apply proxy configs * chore: fix key
60 lines
2.1 KiB
TypeScript
60 lines
2.1 KiB
TypeScript
import { create } from 'zustand'
|
|
import { persist, createJSONStorage } from 'zustand/middleware'
|
|
import { localStorageKey } from '@/constants/localStorage'
|
|
|
|
type ProxyConfigState = {
|
|
proxyEnabled: boolean
|
|
proxyUrl: string
|
|
proxyUsername: string
|
|
proxyPassword: string
|
|
proxyIgnoreSSL: boolean
|
|
verifyProxySSL: boolean
|
|
verifyProxyHostSSL: boolean
|
|
verifyPeerSSL: boolean
|
|
verifyHostSSL: boolean
|
|
noProxy: string
|
|
// Function to set the proxy configuration
|
|
setProxyEnabled: (proxyEnabled: boolean) => void
|
|
setProxyUrl: (proxyUrl: string) => void
|
|
setProxyUsername: (proxyUsername: string) => void
|
|
setProxyPassword: (proxyPassword: string) => void
|
|
setProxyIgnoreSSL: (proxyIgnoreSSL: boolean) => void
|
|
setVerifyProxySSL: (verifyProxySSL: boolean) => void
|
|
setVerifyProxyHostSSL: (verifyProxyHostSSL: boolean) => void
|
|
setVerifyPeerSSL: (verifyPeerSSL: boolean) => void
|
|
setVerifyHostSSL: (verifyHostSSL: boolean) => void
|
|
setNoProxy: (noProxy: string) => void
|
|
}
|
|
|
|
export const useProxyConfig = create<ProxyConfigState>()(
|
|
persist(
|
|
(set) => ({
|
|
proxyEnabled: false,
|
|
proxyUrl: '',
|
|
proxyUsername: '',
|
|
proxyPassword: '',
|
|
proxyIgnoreSSL: false,
|
|
verifyProxySSL: true,
|
|
verifyProxyHostSSL: true,
|
|
verifyPeerSSL: true,
|
|
verifyHostSSL: true,
|
|
noProxy: '',
|
|
setProxyEnabled: (proxyEnabled) => set({ proxyEnabled }),
|
|
setProxyUrl: (proxyUrl) => set({ proxyUrl }),
|
|
setProxyUsername: (proxyUsername) => set({ proxyUsername }),
|
|
setProxyPassword: (proxyPassword) => set({ proxyPassword }),
|
|
setProxyIgnoreSSL: (proxyIgnoreSSL) => set({ proxyIgnoreSSL }),
|
|
setVerifyProxySSL: (verifyProxySSL) => set({ verifyProxySSL }),
|
|
setVerifyProxyHostSSL: (verifyProxyHostSSL) =>
|
|
set({ verifyProxyHostSSL }),
|
|
setVerifyPeerSSL: (verifyPeerSSL) => set({ verifyPeerSSL }),
|
|
setVerifyHostSSL: (verifyHostSSL) => set({ verifyHostSSL }),
|
|
setNoProxy: (noProxy) => set({ noProxy }),
|
|
}),
|
|
{
|
|
name: localStorageKey.settingProxyConfig,
|
|
storage: createJSONStorage(() => localStorage),
|
|
}
|
|
)
|
|
)
|