mirror of
https://github.com/MetaCubeX/metacubexd.git
synced 2024-11-23 21:35:36 +08:00
refactor: a little better update proxies
This commit is contained in:
parent
467d0bcce2
commit
06845963c6
@ -13,23 +13,11 @@ import {
|
||||
IconRuler,
|
||||
IconSettings,
|
||||
} from '@tabler/icons-solidjs'
|
||||
import {
|
||||
For,
|
||||
ParentComponent,
|
||||
Show,
|
||||
createEffect,
|
||||
createMemo,
|
||||
createSignal,
|
||||
} from 'solid-js'
|
||||
import { For, ParentComponent, Show, createMemo, createSignal } from 'solid-js'
|
||||
import { twMerge } from 'tailwind-merge'
|
||||
import { LANG, ROUTE } from '~/config/enum'
|
||||
import { themes } from '~/constants'
|
||||
import {
|
||||
endpoint,
|
||||
selectedEndpoint,
|
||||
setCurTheme,
|
||||
setSelectedEndpoint,
|
||||
} from '~/signals'
|
||||
import { setCurTheme, setSelectedEndpoint } from '~/signals'
|
||||
import { useProxies } from '~/signals/proxies'
|
||||
|
||||
const Nav: ParentComponent<{ href: string; tooltip: string }> = ({
|
||||
@ -80,14 +68,6 @@ const ThemeSwitcher = () => (
|
||||
export const Header = () => {
|
||||
const [t, { locale }] = useI18n()
|
||||
const { proxyProviders } = useProxies()
|
||||
|
||||
createEffect(() => {
|
||||
// Need fix: useRequest is not reactive so we need to useProxies again or request wont have endpoint
|
||||
if (selectedEndpoint() && endpoint()) {
|
||||
useProxies().updateProxy()
|
||||
}
|
||||
})
|
||||
|
||||
const navs = createMemo(() => {
|
||||
const list = [
|
||||
{
|
||||
|
@ -3,6 +3,17 @@ import ky from 'ky'
|
||||
import { createSignal } from 'solid-js'
|
||||
import { themes } from '~/constants'
|
||||
|
||||
export const useRequest = () => {
|
||||
const e = endpoint()
|
||||
|
||||
return ky.create({
|
||||
prefixUrl: e?.url,
|
||||
headers: {
|
||||
Authorization: e?.secret ? `Bearer ${e.secret}` : '',
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
export const [selectedEndpoint, setSelectedEndpoint] = makePersisted(
|
||||
createSignal(''),
|
||||
{
|
||||
@ -33,14 +44,3 @@ export const endpoint = () =>
|
||||
export const secret = () => endpoint()?.secret
|
||||
|
||||
export const wsEndpointURL = () => endpoint()?.url.replace('http', 'ws')
|
||||
|
||||
export const useRequest = () => {
|
||||
const e = endpoint()
|
||||
|
||||
return ky.create({
|
||||
prefixUrl: e?.url,
|
||||
headers: {
|
||||
Authorization: e?.secret ? `Bearer ${e.secret}` : '',
|
||||
},
|
||||
})
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
import { createSignal } from 'solid-js'
|
||||
import { useRequest } from '~/signals'
|
||||
import { createEffect, createSignal } from 'solid-js'
|
||||
import { endpoint, selectedEndpoint, useRequest } from '~/signals'
|
||||
import { autoCloseConns, urlForDelayTest } from '~/signals/config'
|
||||
import type { Proxy, ProxyNode, ProxyProvider } from '~/types'
|
||||
|
||||
@ -140,3 +140,9 @@ export function useProxies() {
|
||||
healthCheckByProviderName,
|
||||
}
|
||||
}
|
||||
|
||||
createEffect(() => {
|
||||
if (selectedEndpoint() && endpoint()) {
|
||||
useProxies().updateProxy()
|
||||
}
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user