modify ProxyParser interface

This commit is contained in:
2025-06-12 02:48:59 +10:00
parent 1b662de245
commit 4f3c2bb280
11 changed files with 87 additions and 22 deletions

View File

@ -1,5 +1,7 @@
package model package model
import "github.com/bestnite/sub2clash/parser"
type ClashType int type ClashType int
const ( const (
@ -8,29 +10,19 @@ const (
) )
func GetSupportProxyTypes(clashType ClashType) map[string]bool { func GetSupportProxyTypes(clashType ClashType) map[string]bool {
if clashType == Clash { supportProxyTypes := make(map[string]bool)
return map[string]bool{
"ss": true, for _, parser := range parser.GetAllParsers() {
"ssr": true, if clashType == Clash {
"vmess": true, if parser.SupportClash() {
"trojan": true, supportProxyTypes[parser.GetType()] = true
"socks5": true, }
} else if clashType == ClashMeta {
if parser.SupportMeta() {
supportProxyTypes[parser.GetType()] = true
}
} }
} }
if clashType == ClashMeta { return supportProxyTypes
return map[string]bool{
"ss": true,
"ssr": true,
"vmess": true,
"trojan": true,
"vless": true,
"hysteria": true,
"hysteria2": true,
"socks5": true,
"anytls": true,
}
}
return nil
} }

View File

@ -11,6 +11,14 @@ import (
type AnytlsParser struct{} type AnytlsParser struct{}
func (p *AnytlsParser) SupportClash() bool {
return false
}
func (p *AnytlsParser) SupportMeta() bool {
return true
}
func (p *AnytlsParser) GetPrefixes() []string { func (p *AnytlsParser) GetPrefixes() []string {
return []string{"anytls://"} return []string{"anytls://"}
} }

View File

@ -12,6 +12,14 @@ import (
type HysteriaParser struct{} type HysteriaParser struct{}
func (p *HysteriaParser) SupportClash() bool {
return false
}
func (p *HysteriaParser) SupportMeta() bool {
return true
}
func (p *HysteriaParser) GetPrefixes() []string { func (p *HysteriaParser) GetPrefixes() []string {
return []string{"hysteria://"} return []string{"hysteria://"}
} }

View File

@ -11,6 +11,14 @@ import (
type Hysteria2Parser struct{} type Hysteria2Parser struct{}
func (p *Hysteria2Parser) SupportClash() bool {
return false
}
func (p *Hysteria2Parser) SupportMeta() bool {
return true
}
func (p *Hysteria2Parser) GetPrefixes() []string { func (p *Hysteria2Parser) GetPrefixes() []string {
return []string{"hysteria2://", "hy2://"} return []string{"hysteria2://", "hy2://"}
} }

View File

@ -16,6 +16,8 @@ type ProxyParser interface {
GetPrefixes() []string GetPrefixes() []string
// GetType 返回协议类型名称 // GetType 返回协议类型名称
GetType() string GetType() string
SupportClash() bool
SupportMeta() bool
} }
// parserRegistry 解析器注册中心 // parserRegistry 解析器注册中心

View File

@ -12,6 +12,14 @@ import (
// ShadowsocksParser Shadowsocks协议解析器 // ShadowsocksParser Shadowsocks协议解析器
type ShadowsocksParser struct{} type ShadowsocksParser struct{}
func (p *ShadowsocksParser) SupportClash() bool {
return true
}
func (p *ShadowsocksParser) SupportMeta() bool {
return true
}
// GetPrefixes 返回支持的协议前缀 // GetPrefixes 返回支持的协议前缀
func (p *ShadowsocksParser) GetPrefixes() []string { func (p *ShadowsocksParser) GetPrefixes() []string {
return []string{"ss://"} return []string{"ss://"}

View File

@ -11,6 +11,14 @@ import (
type ShadowsocksRParser struct{} type ShadowsocksRParser struct{}
func (p *ShadowsocksRParser) SupportClash() bool {
return true
}
func (p *ShadowsocksRParser) SupportMeta() bool {
return true
}
func (p *ShadowsocksRParser) GetPrefixes() []string { func (p *ShadowsocksRParser) GetPrefixes() []string {
return []string{"ssr://"} return []string{"ssr://"}
} }

View File

@ -11,6 +11,13 @@ import (
type SocksParser struct{} type SocksParser struct{}
func (p *SocksParser) SupportClash() bool {
return true
}
func (p *SocksParser) SupportMeta() bool {
return true
}
func (p *SocksParser) GetPrefixes() []string { func (p *SocksParser) GetPrefixes() []string {
return []string{"socks://"} return []string{"socks://"}
} }

View File

@ -11,6 +11,14 @@ import (
type TrojanParser struct{} type TrojanParser struct{}
func (p *TrojanParser) SupportClash() bool {
return true
}
func (p *TrojanParser) SupportMeta() bool {
return true
}
func (p *TrojanParser) GetPrefixes() []string { func (p *TrojanParser) GetPrefixes() []string {
return []string{"trojan://"} return []string{"trojan://"}
} }

View File

@ -11,6 +11,14 @@ import (
type VlessParser struct{} type VlessParser struct{}
func (p *VlessParser) SupportClash() bool {
return false
}
func (p *VlessParser) SupportMeta() bool {
return true
}
func (p *VlessParser) GetPrefixes() []string { func (p *VlessParser) GetPrefixes() []string {
return []string{"vless://"} return []string{"vless://"}
} }

View File

@ -12,6 +12,14 @@ import (
type VmessParser struct{} type VmessParser struct{}
func (p *VmessParser) SupportClash() bool {
return true
}
func (p *VmessParser) SupportMeta() bool {
return true
}
func (p *VmessParser) GetPrefixes() []string { func (p *VmessParser) GetPrefixes() []string {
return []string{"vmess://"} return []string{"vmess://"}
} }