原项目自定义ipv6优选IP无法订阅出的解决方案:
原代码里有两套逻辑:
第一套(正确)
动态优选 IP 使用:
const safeIP = item.ip.includes(':') ? `[${item.ip}]` : item.ip;
links.push(
`${proto}://${user}@${safeIP}:${port}?...`
);这里 IPv6 会变成:
vless://uuid@[2606:4700:xxxx]:443
正确。
第二套(有 Bug)
GitHub 优选 piu 走的是:
function generateLinksFromNewIPs(list, user, workerDomain, customPath='/', echConfig=null)里面直接写:
${proto}://${user}@${item.ip}:${port}IPv6 会变成:
vless://uuid@2606:4700:440c:78b1:a24:2ae6:e8f4:5c0a:443
这是非法 URI。
直接修改
找到:
function generateLinksFromNewIPs(...)在
const nodeName = item.name.replace(/\s/g, '_');
const port = item.port;后面增加:
const safeIP = item.ip.includes(':')
? `[${item.ip}]`
: item.ip;然后把函数里所有:
${item.ip}:${port}改成:
${safeIP}:${port}即:
const link =
`${proto}://${user}@${safeIP}:${port}?encryption=none&security=tls&sni=${workerDomain}&fp=chrome&type=ws&host=${workerDomain}&path=${wsPath}${echSuffix}#${encodeURIComponent(wsNodeName)}`;以及
const link =
`${proto}://${user}@${safeIP}:${port}?encryption=none&security=none&type=ws&host=${workerDomain}&path=${wsPath}#${encodeURIComponent(wsNodeName)}`;全部替换。
第二个 Bug(文件格式触发)
你的 GitHub 文件内容是:
[2606:4700:440c:78b1:a24:2ae6:e8f4:5c0a]:443
[2a06:98c1:3105:c06b:ca21:d92c:601f:e810]:443
[2606:4700:54:64ff:fb34:b723:2d64:586c]:443但 fetchAndParseNewIPs() 的正则是:
const regex = /^([^:]+):(\d+)#(.*)$/;它要求:
IP:PORT#备注
而且 [^:]+ 根本不支持 IPv6。
所以如果你的 piu 是单个
GitHub URL:https://raw.githubusercontent.com/.../yxip20260613-1.txt
实际上会解析失败,返回空数组。
一步到位替换
把:
const regex = /^([^:]+):(\d+)#(.*)$/;替换成:
const regex =
/^(\[[0-9a-fA-F:]+\]|[\d.]+)(?::(\d+))?(?:#(.*))?$/;然后:
results.push({
ip: match[1].replace(/[\[\]]/g, ''),
port: parseInt(match[2] || 443),
name: (match[3] || match[1]).trim()
});这样支持:
104.18.45.30:443
104.18.45.30:443#HK
[2606:4700:440c:78b1:a24:2ae6:e8f4:5c0a]:443
[2606:4700:440c:78b1:a24:2ae6:e8f4:5c0a]:443#HK全部能识别。
所以你的问题实际上是 两个 Bug 同时存在:
fetchAndParseNewIPs()不识别 IPv6 文件。generateLinksFromNewIPs()生成 IPv6 VLESS 链接时没加[]。
把这两处改完,你现在这个:
https://raw.githubusercontent.com/a287926405/picgo/main/yxip20260613-1.txt
就能直接作为 piu= 使用了。
评论区