From 2c572d8acc5a4b3722bf20566cc09c13c2a417fe Mon Sep 17 00:00:00 2001 From: Tao Date: Tue, 18 Jul 2023 19:23:59 +0800 Subject: [PATCH] feat: add initial support for proxy-providers --- packages/ui/src/common/define/ClashConfig.ts | 19 +++++++++++++++++++ packages/ui/src/util/gen.ts | 11 +++++++++++ 2 files changed, 30 insertions(+) diff --git a/packages/ui/src/common/define/ClashConfig.ts b/packages/ui/src/common/define/ClashConfig.ts index c356173..a9bcd81 100644 --- a/packages/ui/src/common/define/ClashConfig.ts +++ b/packages/ui/src/common/define/ClashConfig.ts @@ -5,6 +5,7 @@ import { ClashProxyItem } from '$clash-utils' export default interface ClashConfig { 'proxies': ClashProxyItem[] 'proxy-groups': ProxyGroup[] + 'proxy-providers': ProxyProviders | undefined 'port': number 'socks-port': number 'mixed-port': number @@ -37,6 +38,7 @@ export interface FallbackFilter { export interface ProxyGroup { name: string + use?: string[] proxies: string[] type: ProxyGroupType url?: string @@ -49,3 +51,20 @@ export enum ProxyGroupType { Select = 'select', URLTest = 'url-test', } + +export interface ProxyProviders { + [name: string]: ProxyProvider +} + +export interface ProxyProvider { + 'type': 'file' | 'http' + 'path': string + 'url'?: string + 'interval'?: number + 'health-check': ProxyProviderHealthCheck +} + +export interface ProxyProviderHealthCheck { + enable: boolean + url: string +} diff --git a/packages/ui/src/util/gen.ts b/packages/ui/src/util/gen.ts index e0787f9..6789a30 100644 --- a/packages/ui/src/util/gen.ts +++ b/packages/ui/src/util/gen.ts @@ -165,6 +165,7 @@ export default async function genConfig({ forceUpdate = false }: { forceUpdate?: /* #endregion */ /* #region proxy-groups */ + // subscribe 自动生成 proxy groups const subscribeTragets = subscribeItems.map((sub) => sub.name) @@ -291,6 +292,16 @@ export default async function genConfig({ forceUpdate = false }: { forceUpdate?: proxyGroups.push(newgroup) } + // proxy-providers + const proxyProviderNames = Object.keys(config['proxy-providers'] || {}) + if (proxyProviderNames.length) { + proxyGroups.forEach((pg) => { + if (!pg.proxies.length && !pg.use?.length) { + pg.use ||= proxyProviderNames + } + }) + } + // done for proxy-groups config['proxy-groups'] = proxyGroups