Skip to content

Commit

Permalink
feat: 处理端口跳跃(感谢亚托莉佬)
Browse files Browse the repository at this point in the history
  • Loading branch information
xream committed Jul 19, 2024
1 parent 317a804 commit c09a945
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
2 changes: 1 addition & 1 deletion backend/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "sub-store",
"version": "2.14.353",
"version": "2.14.355",
"description": "Advanced Subscription Manager for QX, Loon, Surge, Stash and ShadowRocket.",
"main": "src/main.js",
"scripts": {
Expand Down
29 changes: 29 additions & 0 deletions backend/src/core/proxy-utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,23 @@ import { produceArtifact } from '@/restful/sync';
import { getFlag, removeFlag, getISO, MMDB } from '@/utils/geo';
import Gist from '@/utils/gist';

function getRandomInt(min, max) {
min = Math.ceil(min);
max = Math.floor(max);
return Math.floor(Math.random() * (max - min + 1)) + min;
}

function getRandomPort(portString) {
let portParts = portString.split(',');
let randomPart = portParts[Math.floor(Math.random() * portParts.length)];
if (randomPart.includes('-')) {
let [min, max] = randomPart.split('-').map(Number);
return getRandomInt(min, max);
} else {
return Number(randomPart);
}
}

function preprocess(raw) {
for (const processor of PROXY_PREPROCESSORS) {
try {
Expand Down Expand Up @@ -220,6 +237,18 @@ function produce(proxies, targetPlatform, type, opts = {}) {
delete proxy['tls-fingerprint'];
}
}

// 处理 端口跳跃
if (proxy.ports) {
if (!['ClashMeta', 'JSON'].includes(targetPlatform)) {
proxy.ports = proxy.ports.replace(/\//g, ',');
}
if (!['ClashMeta', 'Stash', 'JSON'].includes(targetPlatform)) {
proxy.port = getRandomPort(proxy.ports);
delete proxy.ports;
}
}

return proxy;
});

Expand Down

0 comments on commit c09a945

Please sign in to comment.