mirror of
https://github.com/woodchen-ink/clash-and-dashboard.git
synced 2025-07-18 14:01:56 +08:00
feat(rules): add proxygroups
This commit is contained in:
parent
0c93e77bf6
commit
cc70575a86
@ -29,13 +29,13 @@ class Rules extends React.Component<RulesProps, RulesState> {
|
||||
async componentDidMount () {
|
||||
const { config } = this.props
|
||||
await config.fetchAndParseConfig()
|
||||
const rules = config.config.rules
|
||||
const proxies = {
|
||||
'REJECT': { type: 'Reject' }
|
||||
'REJECT': { type: 'Reject' },
|
||||
'DIRECT': { type: 'Direct' }
|
||||
}
|
||||
config.config.proxy.map(p => {
|
||||
proxies[p.name] = { type: p.type }
|
||||
})
|
||||
config.config.proxy.map(p => proxies[p.name] = { type: p.type })
|
||||
config.config.proxyGroup.map(p => proxies[p.name] = { type: p.type })
|
||||
const rules = config.config.rules.filter(r => proxies[r.proxy])
|
||||
this.setState({
|
||||
rules,
|
||||
proxies
|
||||
@ -47,7 +47,6 @@ class Rules extends React.Component<RulesProps, RulesState> {
|
||||
const { config } = this.props
|
||||
const { rules } = this.state
|
||||
config.config.rules = rules
|
||||
console.log(config)
|
||||
await config.updateConfig()
|
||||
}
|
||||
|
||||
@ -69,8 +68,6 @@ class Rules extends React.Component<RulesProps, RulesState> {
|
||||
rules: produce(rules, draftState => {
|
||||
draftState[index].payload = payload
|
||||
})
|
||||
}, () => {
|
||||
this.saveConfig()
|
||||
})
|
||||
}
|
||||
|
||||
@ -172,7 +169,7 @@ class Rules extends React.Component<RulesProps, RulesState> {
|
||||
inside={true}
|
||||
autoFocus={true}
|
||||
onChange={ value => this.handleModifyPayload(index, value) }
|
||||
onBlur={() => this.setState({ modifiedIndex: -1 })}
|
||||
onBlur={() => { this.setState({ modifiedIndex: -1 });this.saveConfig() }}
|
||||
style={{ maxWidth: 230 }}
|
||||
/>
|
||||
)
|
||||
|
@ -59,22 +59,10 @@ export interface Socks5Proxy {
|
||||
|
||||
}
|
||||
|
||||
export interface ProxyGroup {
|
||||
|
||||
/**
|
||||
* proxy group name
|
||||
*/
|
||||
name?: string
|
||||
|
||||
/**
|
||||
* configs of proxy server
|
||||
* now support select and url-test
|
||||
*/
|
||||
config?: SelectProxyGroup | UrlTestProxyGroup | FallbackProxyGroup
|
||||
|
||||
}
|
||||
export type ProxyGroup = SelectProxyGroup | UrlTestProxyGroup | FallbackProxyGroup
|
||||
|
||||
export interface SelectProxyGroup {
|
||||
name?: string
|
||||
|
||||
type?: 'select'
|
||||
|
||||
@ -83,6 +71,7 @@ export interface SelectProxyGroup {
|
||||
}
|
||||
|
||||
export interface FallbackProxyGroup {
|
||||
name?: string
|
||||
|
||||
type?: 'fallback'
|
||||
|
||||
@ -95,6 +84,7 @@ export interface FallbackProxyGroup {
|
||||
}
|
||||
|
||||
export interface UrlTestProxyGroup {
|
||||
name?: string
|
||||
|
||||
type?: 'url-test'
|
||||
|
||||
|
@ -9,10 +9,11 @@ export interface Rule {
|
||||
}
|
||||
|
||||
export enum RuleType {
|
||||
DOMAIN = 'DOMAIN',
|
||||
'DOMAIN' = 'DOMAIN',
|
||||
'DOMAIN-SUFFIX' = 'DOMAIN-SUFFIX',
|
||||
'DOMAIN-KEYWORD' = 'DOMAIN-KEYWORD',
|
||||
'GEOIP' = 'GEOIP',
|
||||
'FINAL' = 'FINAL',
|
||||
'IP-CIDR' = 'IP-CIDR'
|
||||
'IP-CIDR' = 'IP-CIDR',
|
||||
'USER-AGENT' = 'USER-AGENT'
|
||||
}
|
||||
|
@ -29,7 +29,7 @@ export class ConfigStore {
|
||||
|
||||
// otherwise parse ini
|
||||
const config = yaml.parse(rawConfig)
|
||||
|
||||
console.log(config)
|
||||
const externalController = config['external-controller'] as string || ''
|
||||
const host = externalController.split(':')
|
||||
|
||||
@ -40,13 +40,13 @@ export class ConfigStore {
|
||||
const proxyGroups = config['Proxy Group'] as any[] || []
|
||||
const proxyGroup: Models.ProxyGroup[] = proxyGroups
|
||||
.filter(p => ['url-test', 'select', 'fallback'].includes(p.type))
|
||||
.map(p => ({ name: p.name, config: p }))
|
||||
const rules = config['Rule'] as any[] || []
|
||||
const rule: Models.Rule[] = rules.map(r => r.split(',')).filter(r => r.length !== 3).map(r => ({
|
||||
const rule: Models.Rule[] = rules.map(r => r.split(',')).filter(r => r.length >= 3).map(r => ({
|
||||
type: Models.RuleType[r[0] as string],
|
||||
payload: r[1],
|
||||
proxy: r[2]
|
||||
}))
|
||||
console.log(rule)
|
||||
this.config = {
|
||||
general: {
|
||||
port: config.port || 0,
|
||||
@ -88,10 +88,6 @@ export class ConfigStore {
|
||||
const { general, proxy, proxyGroup, rules } = this.config
|
||||
const externalController = `${general.externalControllerAddr}:${general.externalControllerPort}`
|
||||
const Rule = rules.map(r => [r.type, r.payload, r.proxy].join(','))
|
||||
const proxyGroups = proxyGroup.map(p => ({
|
||||
name: p.name,
|
||||
...p.config
|
||||
}))
|
||||
const config = {
|
||||
'external-controller': externalController,
|
||||
port: general.port,
|
||||
@ -102,11 +98,11 @@ export class ConfigStore {
|
||||
'log-level': general.logLevel,
|
||||
mode: general.mode,
|
||||
Proxy: proxy,
|
||||
'Proxy Group': proxyGroups,
|
||||
'Proxy Group': proxyGroup,
|
||||
Rule
|
||||
}
|
||||
const data = yaml.stringify(config)
|
||||
console.log(data)
|
||||
// jsBridge.writeConfigWithString(data)
|
||||
// console.log(data)
|
||||
jsBridge.writeConfigWithString(data)
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user