2023-09-15 23:43:55 +08:00
|
|
|
import {
|
|
|
|
IconBrandSpeedtest,
|
|
|
|
IconReload,
|
|
|
|
IconSettings,
|
|
|
|
} from '@tabler/icons-solidjs'
|
2023-09-24 15:29:26 +08:00
|
|
|
import { For, Show, createMemo, createSignal, onMount } from 'solid-js'
|
2023-09-05 15:38:42 +08:00
|
|
|
import { twMerge } from 'tailwind-merge'
|
2023-09-03 03:26:29 +08:00
|
|
|
import {
|
|
|
|
Button,
|
|
|
|
Collapse,
|
2023-09-15 23:43:55 +08:00
|
|
|
ProxiesSettingsModal,
|
2023-09-24 17:56:24 +08:00
|
|
|
ProxyNodeCard,
|
2023-09-03 03:26:29 +08:00
|
|
|
ProxyNodePreview,
|
2023-09-21 23:58:06 +08:00
|
|
|
RenderInTwoColumns,
|
2023-09-06 20:06:26 +08:00
|
|
|
SubscriptionInfo,
|
2023-09-03 03:26:29 +08:00
|
|
|
} from '~/components'
|
2023-09-04 19:12:27 +08:00
|
|
|
import {
|
2023-09-15 23:56:14 +08:00
|
|
|
filterProxiesByAvailability,
|
2023-09-06 20:06:26 +08:00
|
|
|
sortProxiesByOrderingType,
|
|
|
|
} from '~/helpers'
|
2023-09-22 17:14:35 +08:00
|
|
|
import { useI18n } from '~/i18n'
|
2023-09-15 23:56:14 +08:00
|
|
|
import {
|
2023-09-23 00:33:48 +08:00
|
|
|
formatTimeFromNow,
|
2023-09-15 23:56:14 +08:00
|
|
|
hideUnAvailableProxies,
|
|
|
|
proxiesOrderingType,
|
|
|
|
useProxies,
|
|
|
|
} from '~/signals'
|
2023-09-06 20:06:26 +08:00
|
|
|
|
|
|
|
enum ActiveTab {
|
|
|
|
proxyProviders = 'proxyProviders',
|
|
|
|
proxies = 'proxies',
|
|
|
|
}
|
2023-08-24 04:20:53 +08:00
|
|
|
|
2023-08-29 14:44:49 +08:00
|
|
|
export default () => {
|
2023-09-23 20:24:43 +08:00
|
|
|
let proxiesSettingsModalRef: HTMLDialogElement | undefined
|
|
|
|
|
2023-09-23 01:38:36 +08:00
|
|
|
const [t] = useI18n()
|
2023-09-23 20:24:43 +08:00
|
|
|
|
2023-09-03 05:35:08 +08:00
|
|
|
const {
|
2023-09-24 15:29:26 +08:00
|
|
|
fetchProxies,
|
2023-09-03 05:35:08 +08:00
|
|
|
proxies,
|
2023-09-17 14:55:03 +08:00
|
|
|
selectProxyInGroup,
|
2023-09-03 05:35:08 +08:00
|
|
|
latencyMap,
|
2023-09-06 20:06:26 +08:00
|
|
|
proxyProviders,
|
|
|
|
updateProviderByProviderName,
|
|
|
|
updateAllProvider,
|
2023-09-24 17:56:24 +08:00
|
|
|
proxyGroupLatencyTest,
|
|
|
|
proxyProviderLatencyTest,
|
2023-09-24 17:10:01 +08:00
|
|
|
collapsedMap,
|
|
|
|
setCollapsedMap,
|
2023-09-24 18:05:52 +08:00
|
|
|
proxyGroupLatencyTestingMap,
|
|
|
|
proxyProviderLatencyTestingMap,
|
2023-09-24 17:56:24 +08:00
|
|
|
isAllProviderUpdating,
|
|
|
|
updatingMap,
|
2023-09-03 05:35:08 +08:00
|
|
|
} = useProxies()
|
2023-08-30 23:02:55 +08:00
|
|
|
|
2023-09-24 15:29:26 +08:00
|
|
|
onMount(fetchProxies)
|
|
|
|
|
2023-09-24 17:56:24 +08:00
|
|
|
const onProxyGroupLatencyTestClick = async (
|
|
|
|
e: MouseEvent,
|
|
|
|
groupName: string,
|
|
|
|
) => {
|
2023-09-06 20:06:26 +08:00
|
|
|
e.stopPropagation()
|
2023-09-24 17:56:24 +08:00
|
|
|
void proxyGroupLatencyTest(groupName)
|
2023-09-06 20:06:26 +08:00
|
|
|
}
|
|
|
|
|
2023-09-24 17:56:24 +08:00
|
|
|
const onProxyProviderLatencyTestClick = (
|
|
|
|
e: MouseEvent,
|
|
|
|
providerName: string,
|
|
|
|
) => {
|
2023-09-06 20:06:26 +08:00
|
|
|
e.stopPropagation()
|
2023-09-24 17:56:24 +08:00
|
|
|
void proxyProviderLatencyTest(providerName)
|
2023-09-06 20:06:26 +08:00
|
|
|
}
|
|
|
|
|
2023-09-24 17:56:24 +08:00
|
|
|
const onUpdateProxyProviderClick = (e: MouseEvent, providerName: string) => {
|
2023-09-06 20:06:26 +08:00
|
|
|
e.stopPropagation()
|
2023-09-24 17:56:24 +08:00
|
|
|
void updateProviderByProviderName(providerName)
|
2023-09-06 20:06:26 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
const onUpdateAllProviderClick = async (e: MouseEvent) => {
|
2023-09-05 15:38:42 +08:00
|
|
|
e.stopPropagation()
|
2023-09-24 17:56:24 +08:00
|
|
|
void updateAllProvider()
|
2023-08-30 11:01:19 +08:00
|
|
|
}
|
|
|
|
|
2023-09-07 13:09:27 +08:00
|
|
|
const [activeTab, setActiveTab] = createSignal(ActiveTab.proxies)
|
2023-09-06 20:06:26 +08:00
|
|
|
|
|
|
|
const tabs = () => [
|
|
|
|
{
|
2023-09-07 13:09:27 +08:00
|
|
|
type: ActiveTab.proxies,
|
|
|
|
name: t('proxies'),
|
|
|
|
count: proxies().length,
|
2023-09-06 20:06:26 +08:00
|
|
|
},
|
|
|
|
{
|
|
|
|
type: ActiveTab.proxyProviders,
|
|
|
|
name: t('proxyProviders'),
|
|
|
|
count: proxyProviders().length,
|
|
|
|
},
|
|
|
|
]
|
|
|
|
|
2023-08-24 04:20:53 +08:00
|
|
|
return (
|
2023-09-06 22:47:02 +08:00
|
|
|
<div class="flex h-full flex-col gap-2">
|
2023-09-16 00:30:44 +08:00
|
|
|
<div class="flex items-center gap-2">
|
2023-09-24 15:29:26 +08:00
|
|
|
<div class="tabs-boxed tabs gap-2">
|
2023-09-16 00:30:44 +08:00
|
|
|
<For each={tabs()}>
|
|
|
|
{(tab) => (
|
|
|
|
<button
|
2023-09-06 20:06:26 +08:00
|
|
|
class={twMerge(
|
2023-09-16 00:30:44 +08:00
|
|
|
activeTab() === tab.type && 'tab-active',
|
|
|
|
'tab tab-sm gap-2 px-2 sm:tab-md',
|
2023-09-06 20:06:26 +08:00
|
|
|
)}
|
2023-09-16 00:30:44 +08:00
|
|
|
onClick={() => setActiveTab(tab.type)}
|
|
|
|
>
|
|
|
|
<span>{tab.name}</span>
|
|
|
|
<div class="badge badge-sm">{tab.count}</div>
|
|
|
|
</button>
|
|
|
|
)}
|
|
|
|
</For>
|
|
|
|
</div>
|
2023-09-15 23:43:55 +08:00
|
|
|
|
2023-09-16 00:30:44 +08:00
|
|
|
<Show when={activeTab() === ActiveTab.proxyProviders}>
|
|
|
|
<Button
|
|
|
|
class="btn btn-circle btn-sm"
|
|
|
|
disabled={isAllProviderUpdating()}
|
|
|
|
onClick={(e) => onUpdateAllProviderClick(e)}
|
2023-09-22 16:05:36 +08:00
|
|
|
icon={
|
|
|
|
<IconReload
|
|
|
|
class={twMerge(
|
|
|
|
isAllProviderUpdating() && 'animate-spin text-success',
|
|
|
|
)}
|
|
|
|
/>
|
|
|
|
}
|
|
|
|
/>
|
2023-09-16 00:30:44 +08:00
|
|
|
</Show>
|
|
|
|
|
|
|
|
<div class="ml-auto">
|
|
|
|
<Button
|
|
|
|
class="btn-circle btn-sm sm:btn-md"
|
2023-09-23 20:24:43 +08:00
|
|
|
onClick={() => proxiesSettingsModalRef?.showModal()}
|
2023-09-22 16:05:36 +08:00
|
|
|
icon={<IconSettings />}
|
|
|
|
/>
|
2023-09-06 20:06:26 +08:00
|
|
|
</div>
|
2023-09-16 00:30:44 +08:00
|
|
|
</div>
|
2023-09-06 20:06:26 +08:00
|
|
|
|
2023-09-06 22:47:02 +08:00
|
|
|
<div class="flex-1 overflow-y-auto">
|
2023-09-16 00:30:44 +08:00
|
|
|
<Show when={activeTab() === ActiveTab.proxies}>
|
2023-09-21 23:58:06 +08:00
|
|
|
<RenderInTwoColumns>
|
2023-09-16 01:00:30 +08:00
|
|
|
<For each={proxies()}>
|
2023-09-17 14:55:03 +08:00
|
|
|
{(proxyGroup) => {
|
2023-09-16 14:28:21 +08:00
|
|
|
const sortedProxyNames = createMemo(() =>
|
|
|
|
filterProxiesByAvailability(
|
|
|
|
sortProxiesByOrderingType(
|
2023-09-17 14:55:03 +08:00
|
|
|
proxyGroup.all ?? [],
|
2023-09-16 14:28:21 +08:00
|
|
|
latencyMap(),
|
|
|
|
proxiesOrderingType(),
|
|
|
|
),
|
2023-09-16 01:00:30 +08:00
|
|
|
latencyMap(),
|
2023-09-16 14:28:21 +08:00
|
|
|
hideUnAvailableProxies(),
|
2023-09-16 01:00:30 +08:00
|
|
|
),
|
|
|
|
)
|
2023-09-16 00:30:44 +08:00
|
|
|
|
2023-09-16 01:00:30 +08:00
|
|
|
const title = (
|
|
|
|
<>
|
2023-09-24 17:56:24 +08:00
|
|
|
<div class="flex items-center justify-between pr-8">
|
2023-09-16 01:00:30 +08:00
|
|
|
<div class="flex items-center gap-2">
|
2023-09-17 14:55:03 +08:00
|
|
|
<span>{proxyGroup.name}</span>
|
|
|
|
<div class="badge badge-sm">
|
|
|
|
{proxyGroup.all?.length}
|
|
|
|
</div>
|
2023-09-16 01:00:30 +08:00
|
|
|
</div>
|
2023-09-16 00:30:44 +08:00
|
|
|
|
2023-09-16 01:00:30 +08:00
|
|
|
<Button
|
|
|
|
class="btn-circle btn-sm"
|
2023-09-24 18:05:52 +08:00
|
|
|
disabled={
|
|
|
|
proxyGroupLatencyTestingMap()[proxyGroup.name]
|
|
|
|
}
|
2023-09-24 17:56:24 +08:00
|
|
|
onClick={(e) =>
|
|
|
|
onProxyGroupLatencyTestClick(e, proxyGroup.name)
|
|
|
|
}
|
2023-09-22 16:05:36 +08:00
|
|
|
icon={
|
|
|
|
<IconBrandSpeedtest
|
|
|
|
class={twMerge(
|
2023-09-24 18:05:52 +08:00
|
|
|
proxyGroupLatencyTestingMap()[proxyGroup.name] &&
|
2023-09-22 16:05:36 +08:00
|
|
|
'animate-pulse text-success',
|
|
|
|
)}
|
|
|
|
/>
|
|
|
|
}
|
|
|
|
/>
|
2023-09-16 01:00:30 +08:00
|
|
|
</div>
|
2023-09-16 00:30:44 +08:00
|
|
|
|
2023-09-16 01:00:30 +08:00
|
|
|
<div class="text-sm text-slate-500">
|
2023-09-17 14:55:03 +08:00
|
|
|
{proxyGroup.type}{' '}
|
|
|
|
{proxyGroup.now?.length > 0 && ` :: ${proxyGroup.now}`}
|
2023-09-16 01:00:30 +08:00
|
|
|
</div>
|
2023-09-16 00:30:44 +08:00
|
|
|
|
2023-09-17 14:55:03 +08:00
|
|
|
<Show when={!collapsedMap()[proxyGroup.name]}>
|
2023-09-16 01:00:30 +08:00
|
|
|
<ProxyNodePreview
|
2023-09-16 14:28:21 +08:00
|
|
|
proxyNameList={sortedProxyNames()}
|
2023-09-17 14:55:03 +08:00
|
|
|
now={proxyGroup.now}
|
2023-09-16 01:00:30 +08:00
|
|
|
/>
|
|
|
|
</Show>
|
|
|
|
</>
|
|
|
|
)
|
2023-09-16 00:30:44 +08:00
|
|
|
|
2023-09-16 01:00:30 +08:00
|
|
|
return (
|
|
|
|
<Collapse
|
2023-09-17 14:55:03 +08:00
|
|
|
isOpen={collapsedMap()[proxyGroup.name]}
|
2023-09-16 01:00:30 +08:00
|
|
|
title={title}
|
2023-09-17 14:55:03 +08:00
|
|
|
onCollapse={(val) => setCollapsedMap(proxyGroup.name, val)}
|
2023-09-16 01:28:58 +08:00
|
|
|
>
|
2023-09-24 17:56:24 +08:00
|
|
|
<For each={sortedProxyNames()}>
|
|
|
|
{(proxyName) => (
|
|
|
|
<ProxyNodeCard
|
|
|
|
proxyName={proxyName}
|
|
|
|
isSelected={proxyGroup.now === proxyName}
|
|
|
|
onClick={() =>
|
|
|
|
void selectProxyInGroup(proxyGroup, proxyName)
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
</For>
|
2023-09-16 01:28:58 +08:00
|
|
|
</Collapse>
|
2023-09-16 01:00:30 +08:00
|
|
|
)
|
|
|
|
}}
|
|
|
|
</For>
|
2023-09-21 23:58:06 +08:00
|
|
|
</RenderInTwoColumns>
|
2023-09-16 00:30:44 +08:00
|
|
|
</Show>
|
|
|
|
|
2023-09-07 13:09:27 +08:00
|
|
|
<Show when={activeTab() === ActiveTab.proxyProviders}>
|
2023-09-21 23:58:06 +08:00
|
|
|
<RenderInTwoColumns>
|
2023-09-16 01:00:30 +08:00
|
|
|
<For each={proxyProviders()}>
|
|
|
|
{(proxyProvider) => {
|
2023-09-16 14:28:21 +08:00
|
|
|
const sortedProxyNames = createMemo(() =>
|
2023-09-16 01:00:30 +08:00
|
|
|
sortProxiesByOrderingType(
|
|
|
|
proxyProvider.proxies.map((i) => i.name) ?? [],
|
|
|
|
latencyMap(),
|
|
|
|
proxiesOrderingType(),
|
|
|
|
),
|
|
|
|
)
|
2023-09-06 20:06:26 +08:00
|
|
|
|
2023-09-16 01:00:30 +08:00
|
|
|
const title = (
|
|
|
|
<>
|
2023-09-24 17:56:24 +08:00
|
|
|
<div class="flex items-center justify-between pr-8">
|
2023-09-16 01:00:30 +08:00
|
|
|
<div class="flex items-center gap-2">
|
|
|
|
<span>{proxyProvider.name}</span>
|
|
|
|
<div class="badge badge-sm">
|
|
|
|
{proxyProvider.proxies.length}
|
|
|
|
</div>
|
2023-09-06 22:47:02 +08:00
|
|
|
</div>
|
|
|
|
|
2023-09-22 16:05:36 +08:00
|
|
|
<div class="flex items-center gap-2">
|
2023-09-16 01:00:30 +08:00
|
|
|
<Button
|
2023-09-22 16:05:36 +08:00
|
|
|
class="btn btn-circle btn-sm"
|
2023-09-16 01:00:30 +08:00
|
|
|
disabled={updatingMap()[proxyProvider.name]}
|
|
|
|
onClick={(e) =>
|
2023-09-24 17:56:24 +08:00
|
|
|
onUpdateProxyProviderClick(e, proxyProvider.name)
|
2023-09-16 01:00:30 +08:00
|
|
|
}
|
2023-09-22 16:05:36 +08:00
|
|
|
icon={
|
|
|
|
<IconReload
|
|
|
|
class={twMerge(
|
|
|
|
updatingMap()[proxyProvider.name] &&
|
|
|
|
'animate-spin text-success',
|
|
|
|
)}
|
|
|
|
/>
|
|
|
|
}
|
|
|
|
/>
|
2023-09-06 22:47:02 +08:00
|
|
|
|
2023-09-16 01:00:30 +08:00
|
|
|
<Button
|
|
|
|
class="btn btn-circle btn-sm"
|
2023-09-24 18:05:52 +08:00
|
|
|
disabled={
|
|
|
|
proxyProviderLatencyTestingMap()[proxyProvider.name]
|
|
|
|
}
|
2023-09-16 01:00:30 +08:00
|
|
|
onClick={(e) =>
|
2023-09-24 17:56:24 +08:00
|
|
|
onProxyProviderLatencyTestClick(
|
|
|
|
e,
|
|
|
|
proxyProvider.name,
|
|
|
|
)
|
2023-09-16 01:00:30 +08:00
|
|
|
}
|
2023-09-22 16:05:36 +08:00
|
|
|
icon={
|
|
|
|
<IconBrandSpeedtest
|
|
|
|
class={twMerge(
|
2023-09-24 18:05:52 +08:00
|
|
|
proxyProviderLatencyTestingMap()[
|
|
|
|
proxyProvider.name
|
|
|
|
] && 'animate-pulse text-success',
|
2023-09-22 16:05:36 +08:00
|
|
|
)}
|
|
|
|
/>
|
|
|
|
}
|
|
|
|
/>
|
2023-09-16 01:00:30 +08:00
|
|
|
</div>
|
2023-09-06 22:40:52 +08:00
|
|
|
</div>
|
|
|
|
|
2023-09-16 01:00:30 +08:00
|
|
|
<SubscriptionInfo
|
|
|
|
subscriptionInfo={proxyProvider.subscriptionInfo}
|
|
|
|
/>
|
2023-09-06 22:47:02 +08:00
|
|
|
|
2023-09-16 01:00:30 +08:00
|
|
|
<div class="text-sm text-slate-500">
|
|
|
|
{proxyProvider.vehicleType} :: {t('updated')}{' '}
|
|
|
|
{formatTimeFromNow(proxyProvider.updatedAt)}
|
|
|
|
</div>
|
2023-09-06 22:47:02 +08:00
|
|
|
|
2023-09-16 01:00:30 +08:00
|
|
|
<Show when={!collapsedMap()[proxyProvider.name]}>
|
2023-09-16 14:28:21 +08:00
|
|
|
<ProxyNodePreview proxyNameList={sortedProxyNames()} />
|
2023-09-16 01:00:30 +08:00
|
|
|
</Show>
|
|
|
|
</>
|
|
|
|
)
|
2023-09-06 22:47:02 +08:00
|
|
|
|
2023-09-16 01:00:30 +08:00
|
|
|
return (
|
|
|
|
<Collapse
|
|
|
|
isOpen={collapsedMap()[proxyProvider.name]}
|
|
|
|
title={title}
|
|
|
|
onCollapse={(val) =>
|
|
|
|
setCollapsedMap(proxyProvider.name, val)
|
|
|
|
}
|
2023-09-16 01:28:58 +08:00
|
|
|
>
|
2023-09-24 17:56:24 +08:00
|
|
|
<For each={sortedProxyNames()}>
|
|
|
|
{(proxyName) => <ProxyNodeCard proxyName={proxyName} />}
|
|
|
|
</For>
|
2023-09-16 01:28:58 +08:00
|
|
|
</Collapse>
|
2023-09-16 01:00:30 +08:00
|
|
|
)
|
|
|
|
}}
|
|
|
|
</For>
|
2023-09-21 23:58:06 +08:00
|
|
|
</RenderInTwoColumns>
|
2023-09-06 22:47:02 +08:00
|
|
|
</Show>
|
|
|
|
</div>
|
2023-09-15 23:43:55 +08:00
|
|
|
|
2023-09-23 20:24:43 +08:00
|
|
|
<ProxiesSettingsModal ref={(el) => (proxiesSettingsModalRef = el)} />
|
2023-09-06 20:06:26 +08:00
|
|
|
</div>
|
2023-08-24 04:20:53 +08:00
|
|
|
)
|
|
|
|
}
|