mirror of
https://github.com/MetaCubeX/metacubexd.git
synced 2024-11-24 09:45:35 +08:00
refactor: rename delay to latency
This commit is contained in:
parent
635b8ba966
commit
18922eecb3
@ -7,36 +7,37 @@ export const ProxyPreviewBar = (props: {
|
|||||||
now?: string
|
now?: string
|
||||||
}) => {
|
}) => {
|
||||||
const { latencyMap } = useProxies()
|
const { latencyMap } = useProxies()
|
||||||
const delayList = createMemo(() =>
|
const latencyList = createMemo(() =>
|
||||||
props.proxyNameList.map((i) => latencyMap()[i]),
|
props.proxyNameList.map((i) => latencyMap()[i]),
|
||||||
)
|
)
|
||||||
const all = createMemo(() => delayList().length)
|
const all = createMemo(() => latencyList().length)
|
||||||
const good = createMemo(
|
const good = createMemo(
|
||||||
() =>
|
() =>
|
||||||
delayList().filter(
|
latencyList().filter(
|
||||||
(delay) =>
|
(latency) =>
|
||||||
delay > latencyQualityMap().NOT_CONNECTED &&
|
latency > latencyQualityMap().NOT_CONNECTED &&
|
||||||
delay <= latencyQualityMap().MEDIUM,
|
latency <= latencyQualityMap().MEDIUM,
|
||||||
).length,
|
).length,
|
||||||
)
|
)
|
||||||
const middle = createMemo(
|
const middle = createMemo(
|
||||||
() =>
|
() =>
|
||||||
delayList().filter(
|
latencyList().filter(
|
||||||
(delay) =>
|
(latency) =>
|
||||||
delay > latencyQualityMap().NOT_CONNECTED &&
|
latency > latencyQualityMap().NOT_CONNECTED &&
|
||||||
delay <= latencyQualityMap().HIGH,
|
latency <= latencyQualityMap().HIGH,
|
||||||
).length,
|
).length,
|
||||||
)
|
)
|
||||||
const slow = createMemo(
|
const slow = createMemo(
|
||||||
() =>
|
() =>
|
||||||
delayList().filter((delay) => delay > latencyQualityMap().HIGH).length,
|
latencyList().filter((latency) => latency > latencyQualityMap().HIGH)
|
||||||
|
.length,
|
||||||
)
|
)
|
||||||
const notConnected = createMemo(
|
const notConnected = createMemo(
|
||||||
() =>
|
() =>
|
||||||
delayList().filter(
|
latencyList().filter(
|
||||||
(delay) =>
|
(latency) =>
|
||||||
delay === latencyQualityMap().NOT_CONNECTED ||
|
latency === latencyQualityMap().NOT_CONNECTED ||
|
||||||
typeof delay !== 'number',
|
typeof latency !== 'number',
|
||||||
).length,
|
).length,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -2,21 +2,21 @@ import { For } from 'solid-js'
|
|||||||
import { twMerge } from 'tailwind-merge'
|
import { twMerge } from 'tailwind-merge'
|
||||||
import { latencyQualityMap, useProxies } from '~/signals'
|
import { latencyQualityMap, useProxies } from '~/signals'
|
||||||
|
|
||||||
const DelayDots = (p: { delay: number | undefined; selected: boolean }) => {
|
const LatencyDots = (p: { latency: number | undefined; selected: boolean }) => {
|
||||||
let dotClassName = p.selected
|
let dotClassName = p.selected
|
||||||
? 'bg-white border-4 border-success'
|
? 'bg-white border-4 border-success'
|
||||||
: 'bg-success'
|
: 'bg-success'
|
||||||
|
|
||||||
if (
|
if (
|
||||||
typeof p.delay !== 'number' ||
|
typeof p.latency !== 'number' ||
|
||||||
p.delay === latencyQualityMap().NOT_CONNECTED
|
p.latency === latencyQualityMap().NOT_CONNECTED
|
||||||
) {
|
) {
|
||||||
dotClassName = p.selected
|
dotClassName = p.selected
|
||||||
? 'bg-white border-4 border-neutral'
|
? 'bg-white border-4 border-neutral'
|
||||||
: 'bg-neutral'
|
: 'bg-neutral'
|
||||||
} else if (p.delay > latencyQualityMap().HIGH) {
|
} else if (p.latency > latencyQualityMap().HIGH) {
|
||||||
dotClassName = p.selected ? 'bg-white border-4 border-error' : 'bg-error'
|
dotClassName = p.selected ? 'bg-white border-4 border-error' : 'bg-error'
|
||||||
} else if (p.delay > latencyQualityMap().MEDIUM) {
|
} else if (p.latency > latencyQualityMap().MEDIUM) {
|
||||||
dotClassName = p.selected
|
dotClassName = p.selected
|
||||||
? 'bg-white border-4 border-warning'
|
? 'bg-white border-4 border-warning'
|
||||||
: 'bg-warning'
|
: 'bg-warning'
|
||||||
@ -39,10 +39,10 @@ export const ProxyPreviewDots = (props: {
|
|||||||
latencyMap()[name],
|
latencyMap()[name],
|
||||||
])}
|
])}
|
||||||
>
|
>
|
||||||
{([name, delay]) => {
|
{([name, latency]) => {
|
||||||
const isSelected = props.now === name
|
const isSelected = props.now === name
|
||||||
|
|
||||||
return <DelayDots delay={delay} selected={isSelected} />
|
return <LatencyDots latency={latency} selected={isSelected} />
|
||||||
}}
|
}}
|
||||||
</For>
|
</For>
|
||||||
</div>
|
</div>
|
||||||
|
@ -39,7 +39,7 @@ export default {
|
|||||||
auto: 'Auto',
|
auto: 'Auto',
|
||||||
off: 'Off',
|
off: 'Off',
|
||||||
proxiesPreviewType: 'Proxies preview type',
|
proxiesPreviewType: 'Proxies preview type',
|
||||||
urlForDelayTest: 'Url for delay test',
|
urlForLatencyTest: 'Url for latency test',
|
||||||
autoCloseConns: 'Automatically close all connections',
|
autoCloseConns: 'Automatically close all connections',
|
||||||
autoSwitchTheme: 'Automatically switch theme',
|
autoSwitchTheme: 'Automatically switch theme',
|
||||||
favDayTheme: 'Favorite light theme',
|
favDayTheme: 'Favorite light theme',
|
||||||
|
@ -39,7 +39,7 @@ export default {
|
|||||||
auto: '自适应',
|
auto: '自适应',
|
||||||
off: '关闭',
|
off: '关闭',
|
||||||
proxiesPreviewType: '节点组预览样式',
|
proxiesPreviewType: '节点组预览样式',
|
||||||
urlForDelayTest: '测速链接',
|
urlForLatencyTest: '测速链接',
|
||||||
autoCloseConns: '切换代理时自动断开全部连接',
|
autoCloseConns: '切换代理时自动断开全部连接',
|
||||||
autoSwitchTheme: '自动切换主题',
|
autoSwitchTheme: '自动切换主题',
|
||||||
favDayTheme: '浅色主题偏好',
|
favDayTheme: '浅色主题偏好',
|
||||||
|
@ -25,8 +25,8 @@ import {
|
|||||||
setProxiesOrderingType,
|
setProxiesOrderingType,
|
||||||
setProxiesPreviewType,
|
setProxiesPreviewType,
|
||||||
setRenderInTwoColumn,
|
setRenderInTwoColumn,
|
||||||
setUrlForDelayTest,
|
setUrlForLatencyTest,
|
||||||
urlForDelayTest,
|
urlForLatencyTest,
|
||||||
useRequest,
|
useRequest,
|
||||||
} from '~/signals'
|
} from '~/signals'
|
||||||
import type { DNSQuery, Config as IConfig } from '~/types'
|
import type { DNSQuery, Config as IConfig } from '~/types'
|
||||||
@ -323,12 +323,12 @@ const ConfigForXd = () => {
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="flex flex-col">
|
<div class="flex flex-col">
|
||||||
<div class="pb-4">{t('urlForDelayTest')}</div>
|
<div class="pb-4">{t('urlForLatencyTest')}</div>
|
||||||
|
|
||||||
<input
|
<input
|
||||||
class="w-100 input input-bordered max-w-md"
|
class="w-100 input input-bordered max-w-md"
|
||||||
value={urlForDelayTest()}
|
value={urlForLatencyTest()}
|
||||||
onChange={(e) => setUrlForDelayTest(e.target?.value!)}
|
onChange={(e) => setUrlForLatencyTest(e.target?.value!)}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -17,7 +17,7 @@ export default () => {
|
|||||||
const {
|
const {
|
||||||
proxies,
|
proxies,
|
||||||
setProxyGroupByProxyName,
|
setProxyGroupByProxyName,
|
||||||
delayTestByProxyGroupName,
|
latencyTestByProxyGroupName,
|
||||||
latencyMap,
|
latencyMap,
|
||||||
} = useProxies()
|
} = useProxies()
|
||||||
|
|
||||||
@ -34,7 +34,7 @@ export default () => {
|
|||||||
|
|
||||||
el.classList.add('animate-pulse')
|
el.classList.add('animate-pulse')
|
||||||
e.stopPropagation()
|
e.stopPropagation()
|
||||||
await delayTestByProxyGroupName(name)
|
await latencyTestByProxyGroupName(name)
|
||||||
el.classList.remove('animate-pulse')
|
el.classList.remove('animate-pulse')
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -61,7 +61,11 @@ export default () => {
|
|||||||
</div>
|
</div>
|
||||||
<Show when={!collapsedMap()[`group-${proxy.name}`]}>
|
<Show when={!collapsedMap()[`group-${proxy.name}`]}>
|
||||||
<ProxyNodePreview
|
<ProxyNodePreview
|
||||||
proxyNameList={proxy.all ?? []}
|
proxyNameList={sortProxiesByOrderingType(
|
||||||
|
proxy.all ?? [],
|
||||||
|
latencyMap(),
|
||||||
|
proxiesOrderingType(),
|
||||||
|
)}
|
||||||
now={proxy.now}
|
now={proxy.now}
|
||||||
/>
|
/>
|
||||||
</Show>
|
</Show>
|
||||||
|
@ -16,9 +16,9 @@ export const [proxiesOrderingType, setProxiesOrderingType] = makePersisted(
|
|||||||
createSignal(PROXIES_ORDERING_TYPE.NATURAL),
|
createSignal(PROXIES_ORDERING_TYPE.NATURAL),
|
||||||
{ name: 'proxiesOrderingType', storage: localStorage },
|
{ name: 'proxiesOrderingType', storage: localStorage },
|
||||||
)
|
)
|
||||||
export const [urlForDelayTest, setUrlForDelayTest] = makePersisted(
|
export const [urlForLatencyTest, setUrlForLatencyTest] = makePersisted(
|
||||||
createSignal('https://www.gstatic.com/generate_204'),
|
createSignal('https://www.gstatic.com/generate_204'),
|
||||||
{ name: 'urlForDelayTest', storage: localStorage },
|
{ name: 'urlForLatencyTest', storage: localStorage },
|
||||||
)
|
)
|
||||||
export const [autoCloseConns, setAutoCloseConns] = makePersisted(
|
export const [autoCloseConns, setAutoCloseConns] = makePersisted(
|
||||||
createSignal(false),
|
createSignal(false),
|
||||||
@ -41,7 +41,8 @@ export const [renderInTwoColumn, setRenderInTwoColumn] = makePersisted(
|
|||||||
{ name: 'renderInTwoColumn', storage: localStorage },
|
{ name: 'renderInTwoColumn', storage: localStorage },
|
||||||
)
|
)
|
||||||
|
|
||||||
export const isLatencyTestByHttps = () => urlForDelayTest().startsWith('https')
|
export const isLatencyTestByHttps = () =>
|
||||||
|
urlForLatencyTest().startsWith('https')
|
||||||
|
|
||||||
export const latencyQualityMap = () =>
|
export const latencyQualityMap = () =>
|
||||||
isLatencyTestByHttps() ? LATENCY_QUALITY_MAP_HTTPS : LATENCY_QUALITY_MAP_HTTP
|
isLatencyTestByHttps() ? LATENCY_QUALITY_MAP_HTTPS : LATENCY_QUALITY_MAP_HTTP
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { createSignal } from 'solid-js'
|
import { createSignal } from 'solid-js'
|
||||||
import { autoCloseConns, urlForDelayTest, useRequest } from '~/signals'
|
import { autoCloseConns, urlForLatencyTest, useRequest } from '~/signals'
|
||||||
import type { Proxy, ProxyNode, ProxyProvider } from '~/types'
|
import type { Proxy, ProxyNode, ProxyProvider } from '~/types'
|
||||||
|
|
||||||
type ProxyInfo = {
|
type ProxyInfo = {
|
||||||
@ -21,7 +21,7 @@ export const useProxies = () => {
|
|||||||
|
|
||||||
const setProxyInfoByProixes = (proxies: Proxy[] | ProxyNode[]) => {
|
const setProxyInfoByProixes = (proxies: Proxy[] | ProxyNode[]) => {
|
||||||
proxies.forEach((proxy) => {
|
proxies.forEach((proxy) => {
|
||||||
const delay = proxy.history.at(-1)?.delay ?? -1
|
const latency = proxy.history.at(-1)?.delay ?? -1
|
||||||
|
|
||||||
setProxyNodeMap({
|
setProxyNodeMap({
|
||||||
...proxyNodeMap(),
|
...proxyNodeMap(),
|
||||||
@ -33,7 +33,7 @@ export const useProxies = () => {
|
|||||||
})
|
})
|
||||||
setLatencyMap({
|
setLatencyMap({
|
||||||
...latencyMap(),
|
...latencyMap(),
|
||||||
[proxy.name]: delay,
|
[proxy.name]: latency,
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -88,11 +88,11 @@ export const useProxies = () => {
|
|||||||
setProxies(proxyGroupList)
|
setProxies(proxyGroupList)
|
||||||
}
|
}
|
||||||
|
|
||||||
const delayTestByProxyGroupName = async (proxyGroupName: string) => {
|
const latencyTestByProxyGroupName = async (proxyGroupName: string) => {
|
||||||
const data: Record<string, number> = await request
|
const data: Record<string, number> = await request
|
||||||
.get(`group/${proxyGroupName}/delay`, {
|
.get(`group/${proxyGroupName}/delay`, {
|
||||||
searchParams: {
|
searchParams: {
|
||||||
url: urlForDelayTest(),
|
url: urlForLatencyTest(),
|
||||||
timeout: 2000,
|
timeout: 2000,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
@ -130,7 +130,7 @@ export const useProxies = () => {
|
|||||||
return {
|
return {
|
||||||
proxies,
|
proxies,
|
||||||
proxyProviders,
|
proxyProviders,
|
||||||
delayTestByProxyGroupName,
|
latencyTestByProxyGroupName,
|
||||||
latencyMap,
|
latencyMap,
|
||||||
proxyNodeMap,
|
proxyNodeMap,
|
||||||
updateProxies,
|
updateProxies,
|
||||||
|
Loading…
Reference in New Issue
Block a user