Skip to content

Commit

Permalink
feat: add initial support for proxy-providers
Browse files Browse the repository at this point in the history
  • Loading branch information
magicdawn committed Jul 18, 2023
1 parent 2ad2577 commit 2c572d8
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
19 changes: 19 additions & 0 deletions packages/ui/src/common/define/ClashConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -37,6 +38,7 @@ export interface FallbackFilter {

export interface ProxyGroup {
name: string
use?: string[]
proxies: string[]
type: ProxyGroupType
url?: string
Expand All @@ -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
}
11 changes: 11 additions & 0 deletions packages/ui/src/util/gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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

Expand Down

0 comments on commit 2c572d8

Please sign in to comment.