@@ -14,7 +14,7 @@ export function formatSingboxJson(config: ClashConfig): string {
1414 }
1515 }
1616
17- // 2. 转换策略组
17+ // 2. 转换策略组为 selector
1818 for ( const group of clashGroups ) {
1919 outbounds . push ( {
2020 type : 'selector' ,
@@ -23,32 +23,40 @@ export function formatSingboxJson(config: ClashConfig): string {
2323 } ) ;
2424 }
2525
26- // 3. 默认补全 direct 与 block
26+ // 3. 补全内置出站
2727 outbounds . push (
2828 { type : 'direct' , tag : 'DIRECT' } ,
2929 { type : 'block' , tag : 'REJECT' } ,
3030 { type : 'dns' , tag : 'dns-out' }
3131 ) ;
3232
33+ // Sing-box 1.8+ 规范:dns.servers 不放 detour,通过 dns.rules 路由
3334 const singboxConfig = {
3435 log : {
3536 level : 'info' ,
3637 timestamp : true ,
3738 } ,
3839 dns : {
3940 servers : [
40- { tag : 'google' , address : 'tls://8.8.8.8' } ,
41- { tag : 'local' , address : '223.5.5.5' , detour : 'DIRECT' } ,
41+ { tag : 'remote' , address : 'tls://8.8.8.8' , detour : '⚡ 最终出口' } ,
42+ { tag : 'local' , address : '223.5.5.5' } ,
43+ { tag : 'block' , address : 'rcode://success' } ,
4244 ] ,
45+ rules : [
46+ { geosite : [ 'cn' ] , server : 'local' } ,
47+ { geosite : [ 'category-ads-all' ] , server : 'block' , disable_cache : true } ,
48+ ] ,
49+ final : 'remote' ,
50+ strategy : 'prefer_ipv4' ,
4351 } ,
4452 inbounds : [
4553 {
4654 type : 'tun' ,
4755 tag : 'tun-in' ,
48- interface_name : 'tun0' ,
49- inet4_address : '172.19.0.1/30' ,
56+ address : [ '172.19.0.1/30' , 'fdfe:dcba:9876::1/126' ] ,
5057 auto_route : true ,
5158 strict_route : true ,
59+ sniff : true ,
5260 } ,
5361 ] ,
5462 outbounds,
@@ -61,6 +69,7 @@ export function formatSingboxJson(config: ClashConfig): string {
6169 return JSON . stringify ( singboxConfig , null , 2 ) ;
6270}
6371
72+
6473function transformProxyToSingbox ( proxy : ClashProxy ) : Record < string , unknown > | null {
6574 if ( ! proxy || ! proxy . name ) return null ;
6675
@@ -83,18 +92,22 @@ function transformProxyToSingbox(proxy: ClashProxy): Record<string, unknown> | n
8392
8493 if ( type === 'socks5' || type === 'socks' ) {
8594 outbound . type = 'socks' ;
95+ outbound . version = '5' ;
8696 if ( proxy . username ) outbound . username = proxy . username ;
8797 if ( proxy . password ) outbound . password = proxy . password ;
88- } else if ( type === 'http' || type === 'https' ) {
98+ } else if ( type === 'http' ) {
8999 outbound . type = 'http' ;
90100 if ( proxy . username ) outbound . username = proxy . username ;
91101 if ( proxy . password ) outbound . password = proxy . password ;
92- if ( type === 'https' || proxy . tls ) {
93- outbound . tls = { enabled : true , server_name : proxy . sni || server } ;
94- }
102+ } else if ( type === 'https' ) {
103+ // Sing-box 中 https 代理用 http + tls 实现
104+ outbound . type = 'http' ;
105+ if ( proxy . username ) outbound . username = proxy . username ;
106+ if ( proxy . password ) outbound . password = proxy . password ;
107+ outbound . tls = { enabled : true , server_name : proxy . sni || server } ;
95108 } else if ( type === 'ss' ) {
96109 outbound . type = 'shadowsocks' ;
97- outbound . method = proxy . cipher ;
110+ outbound . method = proxy . cipher || 'chacha20-ietf-poly1305' ;
98111 outbound . password = proxy . password ;
99112 } else if ( type === 'vmess' ) {
100113 outbound . type = 'vmess' ;
@@ -108,6 +121,8 @@ function transformProxyToSingbox(proxy: ClashProxy): Record<string, unknown> | n
108121 outbound . type = 'vless' ;
109122 outbound . uuid = proxy . uuid ;
110123 if ( proxy . flow ) outbound . flow = proxy . flow ;
124+ // VLESS 通常需要 TLS(Reality 或 TLS)
125+ outbound . tls = { enabled : true , server_name : proxy . sni || proxy . servername || server } ;
111126 } else if ( type === 'trojan' ) {
112127 outbound . type = 'trojan' ;
113128 outbound . password = proxy . password ;
@@ -117,7 +132,8 @@ function transformProxyToSingbox(proxy: ClashProxy): Record<string, unknown> | n
117132 outbound . password = proxy . auth ;
118133 outbound . tls = { enabled : true , server_name : proxy . sni || server } ;
119134 } else {
120- outbound . type = type ;
135+ // 不支持的类型直接跳过,避免生成无效配置
136+ return null ;
121137 }
122138
123139 return outbound ;
0 commit comments