添加 Surge Hybrid 参数支持,添加一键上传所有节点配置到 Gist

This commit is contained in:
Peng-YM 2021-09-03 18:05:22 +08:00
parent 204e5b73a2
commit 87deb369fb
7 changed files with 81 additions and 19 deletions

View File

@ -2573,6 +2573,7 @@ var ProxyUtils = (function () {
function Surge_Producer() {
const targetPlatform = "Surge";
const produce = (proxy) => {
let result = "";
let obfs_opts, tls_opts;
switch (proxy.type) {
case "ss":
@ -2587,13 +2588,14 @@ var ProxyUtils = (function () {
);
}
}
return `${proxy.name}=ss,${proxy.server}, ${proxy.port
result = `${proxy.name}=ss,${proxy.server}, ${proxy.port
},encrypt-method=${proxy.cipher},password=${proxy.password
}${obfs_opts},tfo=${proxy.tfo || "false"},udp-relay=${proxy.udp || "false"
}`;
break;
case "vmess":
tls_opts = "";
let config = `${proxy.name}=vmess,${proxy.server},${proxy.port
result = `${proxy.name}=vmess,${proxy.server},${proxy.port
},username=${proxy.uuid},tls=${proxy.tls || "false"},tfo=${proxy.tfo || "false"
}`;
if (proxy.network === "ws") {
@ -2601,35 +2603,42 @@ var ProxyUtils = (function () {
const wsHeaders = Object.entries(proxy["ws-headers"]).map(
([key, value]) => (`${key}:"${value}"`))
.join('|');
config += `,ws=true${path ? ",ws-path=" + path : ""}${wsHeaders ? ",ws-headers=" + wsHeaders : ""}`;
result += `,ws=true${path ? ",ws-path=" + path : ""}${wsHeaders ? ",ws-headers=" + wsHeaders : ""}`;
}
if (proxy.tls) {
config += `${typeof proxy["skip-cert-verify"] !== "undefined"
result += `${typeof proxy["skip-cert-verify"] !== "undefined"
? ",skip-cert-verify=" + proxy["skip-cert-verify"]
: ""
}`;
config += proxy.sni ? `,sni=${proxy.sni}` : "";
result += proxy.sni ? `,sni=${proxy.sni}` : "";
}
return config;
break;
case "trojan":
return `${proxy.name}=trojan,${proxy.server},${proxy.port
result = `${proxy.name}=trojan,${proxy.server},${proxy.port
},password=${proxy.password}${typeof proxy["skip-cert-verify"] !== "undefined"
? ",skip-cert-verify=" + proxy["skip-cert-verify"]
: ""
}${proxy.sni ? ",sni=" + proxy.sni : ""},tfo=${proxy.tfo || "false"
}`;
break;
case "http":
tls_opts = ", tls=false";
if (proxy.tls) {
tls_opts = `,tls=true,skip-cert-verify=${proxy["skip-cert-verify"]},sni=${proxy.sni}`;
}
return `${proxy.name}=http, ${proxy.server}, ${proxy.port}${proxy.username ? ",username=" + proxy.username : ""
result = `${proxy.name}=http, ${proxy.server}, ${proxy.port}${proxy.username ? ",username=" + proxy.username : ""
}${proxy.password ? ",password=" + proxy.password : ""
}${tls_opts},tfo=${proxy.tfo || "false"}`;
break;
default:
throw new Error(
`Platform ${targetPlatform} does not support proxy type: ${proxy.type}`
);
}
throw new Error(
`Platform ${targetPlatform} does not support proxy type: ${proxy.type}`
);
// handle surge hybrid param
result += proxy["surge-hybrid"] !== undefined ? `,hybrid=${proxy["surge-hybrid"]}` : "";
return result;
};
return {produce};
}

File diff suppressed because one or more lines are too long

View File

@ -66,5 +66,7 @@ function operator(proxies) {
// flag operator
procedure = $get("Flag Operator", true);
proxies = $process(procedure, proxies);
procedure = $get("Flag Operator", true);
return proxies;
}

View File

@ -105,6 +105,14 @@ export default {
this.save();
},
},
created() {
if (typeof this.args !== 'undefined') {
this.action = this.args.action || this.action;
this.position = this.args.position || this.position;
this.template = this.args.template || this.template;
this.link = typeof this.args.link !== 'undefined' ? this.args.link : this.link;
}
}
};
</script>

View File

@ -1,2 +1,3 @@
const DEBUG = process.env.NODE_ENV === "development";
export const BACKEND_BASE = DEBUG ? `http://localhost:3000` : `https://sub.store`;
// export const BACKEND_BASE = DEBUG ? `http://localhost:3000` : `https://sub.store`;
export const BACKEND_BASE = DEBUG ? `https://sub.store:9999` : `https://sub.store`;

View File

@ -5,6 +5,9 @@
<v-icon left>mdi-cloud</v-icon>
同步配置
<v-spacer></v-spacer>
<v-btn icon @click="syncAllArtifacts()">
<v-icon>backup</v-icon>
</v-btn>
<v-btn icon @click="openGist()">
<v-icon>visibility</v-icon>
</v-btn>
@ -318,6 +321,20 @@ export default {
}
},
async syncAllArtifacts() {
try {
const {data} = await axios.get(`/cron/sync-artifacts`);
const {failed} = data;
if (failed.length > 0) {
this.$store.commit("SET_ERROR_MESSAGE", `部分配置(${failed.map(artifact => artifact.name).join(", ")})同步失败,请查看日志!`);
} else {
this.$store.commit("SET_SUCCESS_MESSAGE", `Gist 同步生成节点成功!`);
}
} catch (err) {
this.$store.commit("SET_ERROR_MESSAGE", `Gist 同步生成节点失败!${err}`);
}
},
setArtifactType(type) {
this.currentArtifact.type = type;
this.currentArtifact.source = "";

View File

@ -178,6 +178,30 @@
</v-item-group>
</v-form>
</v-card>
<v-card class="mb-4">
<v-subheader>Surge 选项</v-subheader>
<v-form class="pl-4 pr-4">
<v-radio-group
v-model="options['surge-hybrid']"
class="mt-0 mb-0"
dense
>
Hybrid 策略
<v-row>
<v-col>
<v-radio label="默认" value="DEFAULT"/>
</v-col>
<v-col>
<v-radio label="强制开启" value="FORCE_OPEN"/>
</v-col>
<v-col>
<v-radio label="强制关闭" value="FORCE_CLOSE"/>
</v-col>
</v-row>
</v-radio-group>
</v-form>
</v-card>
<v-card id="processors" class="mb-4">
<v-subheader>
节点操作
@ -270,7 +294,7 @@ const AVAILABLE_PROCESSORS = {
},
"Handle Duplicate Operator": {
component: "HandleDuplicateOperator",
name: "重复节点处理"
name: "节点去重"
},
"Script Filter": {
component: "ScriptFilter",
@ -334,6 +358,7 @@ export default {
udp: "DEFAULT",
"skip-cert-verify": "DEFAULT",
tfo: "DEFAULT",
"surge-hybrid": "DEFAULT"
},
process: [],
selected: []
@ -345,12 +370,12 @@ export default {
let source;
if (this.isCollection) {
source = (typeof name === 'undefined' || name === 'UNTITLED') ? {} : this.$store.state.collections[name];
this.$store.commit("SET_NAV_TITLE", source.name ? `组合订阅编辑 -- ${source.name}` : "新建组合订阅");
this.$store.commit("SET_NAV_TITLE", source.name ? `组合订阅编辑 ${source.name}` : "新建组合订阅");
this.selected = source.subscriptions || [];
} else {
source = (typeof name === 'undefined' || name === 'UNTITLED') ? {} : this.$store.state.subscriptions[name];
this.$store.commit("SET_NAV_TITLE", source.name ? `订阅编辑 -- ${source.name}` : "新建订阅");
this.$store.commit("SET_NAV_TITLE", source.name ? `订阅编辑 ${source.name}` : "新建订阅");
}
this.name = source.name;
const {options, process} = loadProcess(this.options, source);
@ -395,7 +420,7 @@ export default {
});
}
// udp, tfo, scert
for (const opt of ['udp', 'tfo', 'skip-cert-verify']) {
for (const opt of ['udp', 'tfo', 'skip-cert-verify', 'surge-hybrid']) {
if (this.options[opt] !== 'DEFAULT') {
output.process.push({
type: "Set Property Operator",
@ -575,7 +600,7 @@ function loadProcess(options, source, isCollection = false) {
function uuidv4() {
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
var r = Math.random() * 16 | 0, v = c == 'x' ? r : (r & 0x3 | 0x8);
var r = Math.random() * 16 | 0, v = c === 'x' ? r : (r & 0x3 | 0x8);
return v.toString(16);
});
}