feat: 支持 Shadowsocks 2022 的 URI 输入/输出

This commit is contained in:
xream 2024-12-15 23:03:41 +08:00
parent bd87e9231e
commit 06f3e97af2
No known key found for this signature in database
GPG Key ID: 1D2C5225471789F9
3 changed files with 26 additions and 10 deletions

View File

@ -1,6 +1,6 @@
{
"name": "sub-store",
"version": "2.14.442",
"version": "2.14.443",
"description": "Advanced Subscription Manager for QX, Loon, Surge, Stash and ShadowRocket.",
"main": "src/main.js",
"scripts": {

View File

@ -46,9 +46,15 @@ function URI_SS() {
content = content.split('#')[0]; // strip proxy name
// handle IPV4 and IPV6
let serverAndPortArray = content.match(/@([^/]*)(\/|$)/);
let userInfoStr = Base64.decode(
decodeURIComponent(content.split('@')[0]),
);
let rawUserInfoStr = decodeURIComponent(content.split('@')[0]); // 其实应该分隔之后, 用户名和密码再 decodeURIComponent. 但是问题不大
let userInfoStr;
if (rawUserInfoStr?.startsWith('2022-blake3-')) {
userInfoStr = rawUserInfoStr;
} else {
userInfoStr = Base64.decode(rawUserInfoStr);
}
let query = '';
if (!serverAndPortArray) {
if (content.includes('?')) {
@ -73,15 +79,21 @@ function URI_SS() {
userInfoStr = content.split('@')[0];
serverAndPortArray = content.match(/@([^/]*)(\/|$)/);
}
const serverAndPort = serverAndPortArray[1];
const portIdx = serverAndPort.lastIndexOf(':');
proxy.server = serverAndPort.substring(0, portIdx);
proxy.port = `${serverAndPort.substring(portIdx + 1)}`.match(
/\d+/,
)?.[0];
const userInfo = userInfoStr.match(/(^.*?):(.*$)/);
proxy.cipher = userInfo[1];
proxy.password = userInfo[2];
let userInfo = userInfoStr.match(/(^.*?):(.*$)/);
proxy.cipher = userInfo?.[1];
proxy.password = userInfo?.[2];
// if (!proxy.cipher || !proxy.password) {
// userInfo = rawUserInfoStr.match(/(^.*?):(.*$)/);
// proxy.cipher = userInfo?.[1];
// proxy.password = userInfo?.[2];
// }
// handle obfs
const idx = content.indexOf('?plugin=');

View File

@ -29,9 +29,13 @@ export default function URI_Producer() {
switch (proxy.type) {
case 'ss':
const userinfo = `${proxy.cipher}:${proxy.password}`;
result = `ss://${Base64.encode(userinfo)}@${proxy.server}:${
proxy.port
}${proxy.plugin ? '/' : ''}`;
result = `ss://${
proxy.cipher?.startsWith('2022-blake3-')
? `${encodeURIComponent(
proxy.cipher,
)}:${encodeURIComponent(proxy.password)}`
: Base64.encode(userinfo)
}@${proxy.server}:${proxy.port}${proxy.plugin ? '/' : ''}`;
if (proxy.plugin) {
result += '?plugin=';
const opts = proxy['plugin-opts'];