Skip to content

Commit

Permalink
feat: apply changes in #226
Browse files Browse the repository at this point in the history
  • Loading branch information
geekdada committed Apr 21, 2023
1 parent 5d10af1 commit 3dd0135
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
12 changes: 12 additions & 0 deletions src/utils/clash.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export const getClashNodes = function (

switch (nodeConfig.type) {
case NodeTypeEnum.Shadowsocks:
// Istanbul ignore next
if (
nodeConfig.shadowTls &&
!nodeConfig.clashConfig?.enableShadowTls
Expand All @@ -52,6 +53,7 @@ export const getClashNodes = function (
return null;
}

// Istanbul ignore next
if (nodeConfig.shadowTls && nodeConfig.obfs) {
logger.warn(
`Clash 不支持同时开启 shadow-tls 和 obfs,节点 ${nodeConfig.nodeName} 将被忽略。`,
Expand Down Expand Up @@ -166,6 +168,14 @@ export const getClashNodes = function (
}

case NodeTypeEnum.Snell:
// Istanbul ignore next
if (Number(nodeConfig.version) >= 4) {
logger.warn(
`Clash 尚不支持 Snell v${nodeConfig.version},节点 ${nodeConfig.nodeName} 会被省略。`,
);
return null;
}

return {
type: 'snell',
name: nodeConfig.nodeName,
Expand Down Expand Up @@ -251,12 +261,14 @@ export const getClashNodes = function (
};

case NodeTypeEnum.Tuic:
// Istanbul ignore next
if (!nodeConfig.clashConfig?.enableTuic) {
logger.warn(
`尚未开启 Clash 的 TUIC 支持,节点 ${nodeConfig.nodeName} 会被省略。如需开启,请在配置文件中设置 clashConfig.enableTuic 为 true。`,
);
return null;
}
// Istanbul ignore next
if (nodeConfig.alpn && !nodeConfig.alpn.length) {
logger.warn(
`节点 ${nodeConfig.nodeName} 的 alpn 为空。Stash 客户端不支持 ALPN 为空,默认的 ALPN 为 h3。`,
Expand Down
3 changes: 2 additions & 1 deletion src/validators/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ export const SimpleNodeConfigValidator = z.object({
shadowTls: z
.object({
version: z
.union([z.literal('1'), z.literal('2'), z.literal('3')])
.union([z.string(), z.number()])
.refine((v) => Number(v))
.optional(),
password: z.string(),
sni: z.string(),
Expand Down
5 changes: 4 additions & 1 deletion src/validators/snell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,8 @@ export const SnellNodeConfigValidator = SimpleNodeConfigValidator.extend({
obfs: z.union([z.literal('http'), z.literal('tls')]).optional(),
obfsHost: z.ostring(),
reuse: z.oboolean(),
version: z.ostring(),
version: z
.union([z.string(), z.number()])
.refine((v) => Number(v))
.optional(),
});

0 comments on commit 3dd0135

Please sign in to comment.