修复Trojan一处解析错误

This commit is contained in:
Peng-YM committed 2020-12-31 14:30:01 +08:00
1 parent 76cd097a23
commit b092d3fd6a
6 files changed
+28 -6

No files matched your search

+1 -1
View File
@@ -1192,7 +1192,7 @@ var ProxyUtils = (function () {
const parse = (line) => {
const supported = {};
line = line.split("trojan://")[1];
const [server, port] = line.split("@")[1].split("?")[0].split(".");
const [server, port] = line.split("@")[1].split("?")[0].split(":");
const name = decodeURIComponent(line.split("#")[1].trim());
return {
+2 -2
View File
@@ -1,2 +1,2 @@
// UPDATED AT: 2020年12月25日 星期五 14时46分03秒 CST
const $=API("sub-store"),Base64=new Base64Code;function service(){console.log("\n┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅\n 𝑺𝒖𝒃-𝑺𝒕𝒐𝒓𝒆 © 𝑷𝒆𝒏𝒈-𝒀𝑴\n┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅\n");const e=express(),t="settings",s="subs",r="collections",n="rules",o="builtin",a="artifacts",i="Auto Generated Sub-Store Backup",p="Sub-Store",c="Sub-Store Artifacts Repository";async function u({filename:e,content:s}){const{gistToken:r}=$.read(t);return r?new Gist({token:r,key:c}).upload({filename:e,content:s}):Promise.reject("未设置Gist Token!")}function l(e){const t=Object.keys(e);let s="";for(let r of t)if(/USER-AGENT/i.test(r)){s=e[r];break}return-1!==s.indexOf("Quantumult%20X")?"QX":-1!==s.indexOf("Surge")?"Surge":-1!==s.indexOf("Decar")||-1!==s.indexOf("Loon")?"Loon":null}async function f(e,t=!0){const s=HTTP({headers:{"User-Agent":"Quantumult%20X"}}),r="#"+Base64.safeEncode(e),n=$.read(r),o=`#TIME-${Base64.safeEncode(e)}`,a=(new Date).getTime()-$.read(o)>36e5;if(t&&n&&!a)return $.log(`Use cached for resource: ${e}`),n;let i="";try{i=(await s.get(e)).body}catch(e){throw new Error(e)}finally{$.write(i,r),$.write((new Date).getTime(),o)}if(0===i.replace(/\s/g,"").length)throw new Error("订阅内容为空!");return i}async function d({type:e,item:t,platform:r,useCache:n}={platform:"JSON",useCache:!1}){if("subscription"===e){const e=t,s=await f(e.url,n);let o=ProxyUtils.parse(s);return o=await ProxyUtils.process(o,e.process||[]),ProxyUtils.produce(o,r)}if("collection"===e){const e=$.read(s),o=t,a=o.subscriptions;let i=[];for(let t=0;t<a.length;t++){const s=e[a[t]];$.info(`正在处理子订阅:${s.name},进度--${100*((t+1)/a.length).toFixed(1)}% `);try{const e=await f(s.url,n);let t=ProxyUtils.parse(e);t=await ProxyUtils.process(t,s.process||[]),i=i.concat(t)}catch(e){$.error(`处理组合订阅中的子订阅: ${s.name}时出现错误:${e}! 该订阅已被跳过。`)}}if(0===(i=await ProxyUtils.process(i,o.process||[])).length)throw new Error("组合订阅中不含有效节点!");return ProxyUtils.produce(i,r)}if("rule"===e){const e=t;let s=[];for(let t=0;t<e.urls.length;t++){const r=e.urls[t];$.info(`正在处理URL:${r},进度--${100*((t+1)/e.urls.length).toFixed(1)}% `);try{const{body:e}=await $.http.get(r),t=RuleUtils.parse(e);s=s.concat(t)}catch(e){$.error(`处理分流订阅中的URL: ${r}时出现错误:${e}! 该订阅已被跳过。`)}}return s=await RuleUtils.process(s,[{type:"Remove Duplicate Filter"}]),RuleUtils.produce(s,r)}}$.read(s)||$.write({},s),$.read(r)||$.write({},r),$.read(t)||$.write({},t),$.read(n)||$.write({},n),$.read(a)||$.write({},a),$.write({rules:getBuiltInRules()},o),e.get("/download/collection/:name",async function(e,t){const{name:s}=e.params,{cache:n}=e.query||"false",o=e.query.target||l(e.headers)||"JSON",a=void 0===n?"JSON"===o||"URI"===o:n,i=$.read(r)[s];if($.info(`正在下载组合订阅:${s}`),i)try{const e=await d({type:"collection",item:i,platform:o,useCache:a});"JSON"===o?t.set("Content-Type","application/json;charset=utf-8").send(e):t.send(e)}catch(e){$.notify("🌍 『 𝑺𝒖𝒃-𝑺𝒕𝒐𝒓𝒆 』 下载组合订阅失败",`❌ 下载组合订阅错误:${s}!`,`🤔 原因:${e}`),t.status(500).json({status:"failed",message:e})}else $.notify("🌍 『 𝑺𝒖𝒃-𝑺𝒕𝒐𝒓𝒆 』 下载组合订阅失败",`❌ 未找到组合订阅:${s}!`),t.status(404).json({status:"failed"})}),e.get("/download/:name",async function(e,t){const{name:r}=e.params,{cache:n}=e.query,o=e.query.target||l(e.headers)||"JSON",a=void 0===n?"JSON"===o||"URI"===o:n;$.info(`正在下载订阅:${r}`);const i=$.read(s)[r];if(i)try{const e=await d({type:"subscription",item:i,platform:o,useCache:a});"JSON"===o?t.set("Content-Type","application/json;charset=utf-8").send(e):t.send(e)}catch(e){$.notify("🌍 『 𝑺𝒖𝒃-𝑺𝒕𝒐𝒓𝒆 』 下载订阅失败",`❌ 无法下载订阅:${r}!`,`🤔 原因:${e}`),t.status(500).json({status:"failed",message:e})}else $.notify("🌍 『 𝑺𝒖𝒃-𝑺𝒕𝒐𝒓𝒆 』 下载订阅失败",`❌ 未找到订阅:${r}!`),t.status(404).json({status:"failed"})}),e.route("/api/sub/:name").get(function(e,t){const{name:r}=e.params,n=$.read(s)[r];n?t.json({status:"success",data:n}):t.status(404).json({status:"failed",message:`未找到订阅:${r}!`})}).patch(function(e,t){const{name:n}=e.params;let o=e.body;const a=$.read(s);if(a[n]){const e={...a[n],...o};if($.info(`正在更新订阅: ${n}`),n!==o.name){const t=$.read(r);for(const e of Object.keys(t)){const s=t[e].subscriptions.indexOf(n);-1!==s&&(t[e].subscriptions[s]=o.name)}delete a[n],a[o.name]=e}else a[n]=e;$.write(a,s),t.json({status:"success",data:e})}else t.status(500).json({status:"failed",message:`订 Line truncated
// UPDATED AT: 2020年12月31日 星期四 14时29分41秒 CST
const $=API("sub-store"),Base64=new Base64Code;function service(){console.log("\n┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅\n 𝑺𝒖𝒃-𝑺𝒕𝒐𝒓𝒆 © 𝑷𝒆𝒏𝒈-𝒀𝑴\n┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅\n");const e=express(),t="settings",s="subs",r="collections",n="rules",o="builtin",a="artifacts",i="Auto Generated Sub-Store Backup",p="Sub-Store",c="Sub-Store Artifacts Repository";async function u({filename:e,content:s}){const{gistToken:r}=$.read(t);return r?new Gist({token:r,key:c}).upload({filename:e,content:s}):Promise.reject("未设置Gist Token!")}function l(e){const t=Object.keys(e);let s="";for(let r of t)if(/USER-AGENT/i.test(r)){s=e[r];break}return-1!==s.indexOf("Quantumult%20X")?"QX":-1!==s.indexOf("Surge")?"Surge":-1!==s.indexOf("Decar")||-1!==s.indexOf("Loon")?"Loon":null}async function f(e,t=!0){const s=HTTP({headers:{"User-Agent":"Quantumult%20X"}}),r="#"+Base64.safeEncode(e),n=$.read(r),o=`#TIME-${Base64.safeEncode(e)}`,a=(new Date).getTime()-$.read(o)>36e5;if(t&&n&&!a)return $.log(`Use cached for resource: ${e}`),n;let i="";try{i=(await s.get(e)).body}catch(e){throw new Error(e)}finally{$.write(i,r),$.write((new Date).getTime(),o)}if(0===i.replace(/\s/g,"").length)throw new Error("订阅内容为空!");return i}async function d({type:e,item:t,platform:r,useCache:n}={platform:"JSON",useCache:!1}){if("subscription"===e){const e=t,s=await f(e.url,n);let o=ProxyUtils.parse(s);return o=await ProxyUtils.process(o,e.process||[]),ProxyUtils.produce(o,r)}if("collection"===e){const e=$.read(s),o=t,a=o.subscriptions;let i=[];for(let t=0;t<a.length;t++){const s=e[a[t]];$.info(`正在处理子订阅:${s.name},进度--${100*((t+1)/a.length).toFixed(1)}% `);try{const e=await f(s.url,n);let t=ProxyUtils.parse(e);t=await ProxyUtils.process(t,s.process||[]),i=i.concat(t)}catch(e){$.error(`处理组合订阅中的子订阅: ${s.name}时出现错误:${e}! 该订阅已被跳过。`)}}if(0===(i=await ProxyUtils.process(i,o.process||[])).length)throw new Error("组合订阅中不含有效节点!");return ProxyUtils.produce(i,r)}if("rule"===e){const e=t;let s=[];for(let t=0;t<e.urls.length;t++){const r=e.urls[t];$.info(`正在处理URL:${r},进度--${100*((t+1)/e.urls.length).toFixed(1)}% `);try{const{body:e}=await $.http.get(r),t=RuleUtils.parse(e);s=s.concat(t)}catch(e){$.error(`处理分流订阅中的URL: ${r}时出现错误:${e}! 该订阅已被跳过。`)}}return s=await RuleUtils.process(s,[{type:"Remove Duplicate Filter"}]),RuleUtils.produce(s,r)}}$.read(s)||$.write({},s),$.read(r)||$.write({},r),$.read(t)||$.write({},t),$.read(n)||$.write({},n),$.read(a)||$.write({},a),$.write({rules:getBuiltInRules()},o),e.get("/download/collection/:name",async function(e,t){const{name:s}=e.params,{cache:n}=e.query||"false",o=e.query.target||l(e.headers)||"JSON",a=void 0===n?"JSON"===o||"URI"===o:n,i=$.read(r)[s];if($.info(`正在下载组合订阅:${s}`),i)try{const e=await d({type:"collection",item:i,platform:o,useCache:a});"JSON"===o?t.set("Content-Type","application/json;charset=utf-8").send(e):t.send(e)}catch(e){$.notify("🌍 『 𝑺𝒖𝒃-𝑺𝒕𝒐𝒓𝒆 』 下载组合订阅失败",`❌ 下载组合订阅错误:${s}!`,`🤔 原因:${e}`),t.status(500).json({status:"failed",message:e})}else $.notify("🌍 『 𝑺𝒖𝒃-𝑺𝒕𝒐𝒓𝒆 』 下载组合订阅失败",`❌ 未找到组合订阅:${s}!`),t.status(404).json({status:"failed"})}),e.get("/download/:name",async function(e,t){const{name:r}=e.params,{cache:n}=e.query,o=e.query.target||l(e.headers)||"JSON",a=void 0===n?"JSON"===o||"URI"===o:n;$.info(`正在下载订阅:${r}`);const i=$.read(s)[r];if(i)try{const e=await d({type:"subscription",item:i,platform:o,useCache:a});"JSON"===o?t.set("Content-Type","application/json;charset=utf-8").send(e):t.send(e)}catch(e){$.notify("🌍 『 𝑺𝒖𝒃-𝑺𝒕𝒐𝒓𝒆 』 下载订阅失败",`❌ 无法下载订阅:${r}!`,`🤔 原因:${e}`),t.status(500).json({status:"failed",message:e})}else $.notify("🌍 『 𝑺𝒖𝒃-𝑺𝒕𝒐𝒓𝒆 』 下载订阅失败",`❌ 未找到订阅:${r}!`),t.status(404).json({status:"failed"})}),e.route("/api/sub/:name").get(function(e,t){const{name:r}=e.params,n=$.read(s)[r];n?t.json({status:"success",data:n}):t.status(404).json({status:"failed",message:`未找到订阅:${r}!`})}).patch(function(e,t){const{name:n}=e.params;let o=e.body;const a=$.read(s);if(a[n]){const e={...a[n],...o};if($.info(`正在更新订阅: ${n}`),n!==o.name){const t=$.read(r);for(const e of Object.keys(t)){const s=t[e].subscriptions.indexOf(n);-1!==s&&(t[e].subscriptions[s]=o.name)}delete a[n],a[o.name]=e}else a[n]=e;$.write(a,s),t.json({status:"success",data:e})}else t.status(500).json({status:"failed",message:`订 Line truncated
+13 -1
View File
@@ -24,6 +24,14 @@
>
{{ errorMessage }}
</v-snackbar>
<v-overlay :value="isLoading">
<v-progress-circular
indeterminate
size="64"
color="primary"
></v-progress-circular>
</v-overlay>
</v-app>
</template>
@@ -63,7 +71,8 @@ export default {
this.$store.watch(
(state => state.settings.theme.darkMode),
(value => {
this.$vuetify.theme.dark = value
this.$vuetify.theme.dark = value;
window.localStorage.setItem("darkMode", value);
})
)
},
@@ -75,6 +84,9 @@ export default {
errorMessage() {
return this.$store.state.errorMessage;
},
isLoading() {
return this.$store.state.isLoading;
}
},
watch: {
+6 -1
View File
@@ -8,6 +8,7 @@ const store = new Vuex.Store({
state: {
title: "Sub-Store",
clipboard: "",
isLoading: false,
successMessage: "",
errorMessage: "",
@@ -19,7 +20,7 @@ const store = new Vuex.Store({
env: {},
settings: {
theme: {
darkMode: false
darkMode: window.localStorage.getItem("darkMode") || false
}
}
},
@@ -33,6 +34,10 @@ const store = new Vuex.Store({
state.title = title;
},
SET_LOADING(state, loading) {
state.isLoading = loading;
},
SET_SNACK_BAR_TIMER(state, timer) {
state.snackbarTimer = timer;
},
+3
View File
@@ -269,12 +269,15 @@ export default {
},
async sync(name) {
this.$store.commit("SET_LOADING", true);
try {
await axios.get(`/artifact/${name}?action=sync`);
await this.$store.dispatch("FETCH_ARTIFACTS");
this.$store.commit("SET_SUCCESS_MESSAGE", `同步配置成功!`);
} catch (err) {
this.$store.commit("SET_ERROR_MESSAGE", `同步配置失败!${err}`);
} finally {
this.$store.commit("SET_LOADING", false);
}
},
+3 -1
View File
@@ -412,7 +412,8 @@ export default {
if (this.options.name && this.selected) {
if (this.$route.params.name === 'UNTITLED') {
this.$store.dispatch("NEW_COLLECTION", this.config).then(() => {
showInfo(`成功创建组合订阅:${this.name}!`)
showInfo(`成功创建组合订阅:${this.name}!`);
this.$router.back();
}).catch(() => {
showError(`发生错误,无法创建组合订阅!`)
});
@@ -442,6 +443,7 @@ export default {
} else {
this.$store.dispatch("NEW_SUBSCRIPTION", this.config).then(() => {
showInfo(`成功创建订阅:${this.options.name}!`);
this.$router.back();
}).catch(() => {
showError(`发生错误,无法创建订阅!`);
});