引入显式 IR 契约 + Builders 迁移到 IR maps(Clash/Surge/Singbox/Xray)+ 输入模式前端升级(链接/文本/标准化节点)+ Xray JSON 输出 + AnyTLS/规范化输入/订阅解码修复#316
Open
w31r4 wants to merge 7 commits into7Sageer:mainfrom
Conversation
Introduce XrayConfigBuilder and a new /xray-config route (plus /g short
links) to output Xray JSON configs with routing rules. Add UI/i18n support
for the new link, extend proxy parsing with anytls://, and accept a
normalized {version,nodes} input format. Also guard Base64 decoding in
subscription fetching to avoid corrupting plain-text configs.
|
@w31r4 is attempting to deploy a commit to the 7sageer's projects Team on Vercel. A member of the Team first needs to authorize it. |
Owner
|
感谢这个 PR!架构方向是对的——IR 中间层解耦解析和输出,以后扩展协议会轻松很多。 改动量比较大(28files, +1.6k lines),我会仔细 review 一下细节,可能会有一些修改建议或者讨论点。几个初步印象:
稍后会给出具体的 review comments,有些地方可能需要讨论一下再决定怎么处理。 |
Contributor
Author
|
https://github.com/w31r4/sublink-worker/tree/refactor/parsers 在这个分支中我完全重构了解析流程, 但是由于改动太大一直没有推到主线上来, 先自己试用, 目前没有发现太大问题, 但是后来发现主线更新的频率有点高所以又在最新主线基础上引入了 IR 层解耦, 顺便补充了一下 Anytls 的解析和自定义节点功能, 并为拆分输入框做了一些准备, 接下来的目标是:
也就是把 links 和 Structured config 以及规划中的 Guided input 拆分开来 |
Owner
|
看了demo,三模式输入的设计看起来很有意思! 简单和AI Review了一下发现几个需要注意的点:
改动量确实比较大😂,我需要再花点时间评估一下和现有架构的兼容性。 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


背景 / 动机
当前解析与各类 Builder(Clash/Surge/Sing-box/Xray)之间耦合较强,协议扩展会重复写“转换逻辑”。本 PR 以 显式 IR(Intermediate Representation) 作为统一契约,逐步把各 Builder 迁移为 直接消费 IR →
src/ir/maps/*,从而使转化更规范、更易扩展与测试。同时,为了匹配新的输入能力(尤其是
{version,nodes}的标准化输入),前端输入区域升级为三种输入模式:链接 / 文本 / 标准化节点,减少用户误用与解析歧义。主要变更
1) 引入显式 IR 契约层
src/ir/contract.js:IR 版本与基础工具src/ir/normalize.js:legacy proxy → IR(容错为主),并补齐关键字段(如tls.alpn、tcp_fast_open)src/ir/legacy.js:IR → legacy proxy(用于平滑过渡/兼容未迁移组件)src/ir/caps.js:按目标客户端能力降级(reality/utls 等)src/ir/index.js:统一导出src/builders/BaseConfigBuilder.js支持 builder “直通 IR”:usesIR = true直接获取 IR 节点2) Builders 迁移为 IR → maps/*
新增并使用 map 模块,减少 builder 内部协议分支与重复逻辑:
src/ir/maps/xray.jssrc/builders/XrayConfigBuilder.jssrc/ir/maps/surge.jssrc/builders/SurgeConfigBuilder.jssrc/ir/maps/clash.jssrc/builders/ClashConfigBuilder.jssrc/ir/maps/singbox.jssrc/builders/SingboxConfigBuilder.js统一流程:
normalizeLegacyProxyToIR()(若输入不是 IR)downgradeByCaps(ir, target)mapIRTo<target>(ir)3) 前端输入框升级:三模式(链接 / 文本 / 标准化节点)
src/components/Form.jsxsrc/components/formLogic.jsinputMode + inputLinks/inputText/inputNormalizedinputTextarea自动迁移到新结构(并猜测模式)configsrc/i18n/index.js4) 新增 Xray Config JSON 输出(API + UI 链接)
/xray-config端点输出 Xray JSON/g/:code)与 resolve/redirect 兼容xrayConfig字段5) 解析增强:AnyTLS + 标准化输入 + 订阅 Base64 误解码修复
src/parsers/protocols/anytlsParser.jssrc/parsers/ProxyParser.js注册{ version, nodes }(严格校验):src/parsers/subscription/subscriptionContentParser.jssrc/parsers/subscription/httpSubscriptionFetcher.js:仅对“看起来像 Base64”内容才解码行为变化与兼容性说明
udpalpn只放tls.alpnpacket_encoding仍不输出(版本差异较大)config=<string>,只是由前端选择不同来源填入。测试
pnpm exec vitest run(全套测试绿色)test/ir-normalize.test.jstest/normalized-input.test.jstest/anytls-link-parsing.test.jstest/worker.test.js(覆盖/xray-config)test/proxy-providers.test.js(fetch stub 调整)变更范围概览(便于 Review)
src/ir/*、src/ir/maps/*src/builders/{Base,Clash,Surge,Singbox,Xray}ConfigBuilder.jssrc/components/Form.jsx、src/components/formLogic.jssrc/app/createApp.jsxsrc/parsers/*、src/parsers/subscription/*src/i18n/index.jstest/*Reviewer 建议阅读顺序
src/ir/contract.js/src/ir/normalize.js(IR 字段与容错策略)src/ir/maps/*(目标格式映射)BaseConfigBuilder的 IR 直通机制(是否影响旧链路)httpSubscriptionFetcher的 Base64 gating(避免误解码)设计说明:IR / CAPS(能力降级)
IR(Intermediate Representation)
IR 是一个统一的“节点契约层”,把不同来源(分享链接、Clash YAML、Sing-box JSON、Surge 等)解析出来的节点,规范到同一套字段结构中(如
kind/host/port/tags/auth/tls/transport/...)。这样做的收益:
src/ir/maps/*),更易写单测、减少回归风险。{version,nodes}JSON。CAPS(能力降级)
不同目标客户端能力不同(例如 Reality/uTLS 支持差异)。
CAPS用来描述“目标支持哪些能力”,downgradeByCaps(ir, target)会对 IR 做不修改原对象的裁剪/降级,以避免输出到不支持的平台时出现无效字段。扩展方式:
src/ir/caps.js增加CAPS.<target>,并在 builder 中调用downgradeByCaps(ir, '<target>')CAPS.<target>增加字段(如将来packetEncoding,http2),并在downgradeByCaps里实现相应裁剪策略normalizeLegacyProxyToIR()与mapIRTo<target>(),caps 只负责“同协议下的能力差异处理”新增接口:
/xray-config与短链/g/:code/xray-config:输出 Xray JSON 格式配置(便于直接导入/对接),与现有/xray(Base64/链接型输出)互补。/g/:code:为/xray-config?...提供对应的短链入口(g= xray-config),与已有短链体系一致,方便分享/二维码/避免 URL 过长。输入模式说明(前端)
本 PR 将输入分为三种模式,仅把“当前选中模式的内容”作为
config参数提交给后端:/b/xxx){ "version": "...", "nodes": [...] }的规范化 JSONCI / Tests
pnpm exec vitest run(18 files / 106 tests)。