mirror of
https://github.com/sub-store-org/Sub-Store.git
synced 2026-11-27 06:43:08 +00:00
修正了几个订阅解析错误
- 修复了Quantmult格式VMess的obfs-path和obfs-header解析错误的问题。 - 修复了SSR URI格式protoparams和obfsparams解析错误的问题
This commit is contained in:
1 parent
8195fb8235
commit
f54b87dff3
2 files changed
+17
-12
No files matched your search
+15
-10
@@ -833,21 +833,21 @@ var ProxyUtils = (function () {
|
||||
supported,
|
||||
};
|
||||
// get other params
|
||||
params = {};
|
||||
const other_params = {};
|
||||
line = line.split("/?")[1].split("&");
|
||||
if (line.length > 1) {
|
||||
for (const item of line) {
|
||||
const [key, val] = item.split("=");
|
||||
params[key] = val;
|
||||
other_params[key] = val.trim();
|
||||
}
|
||||
}
|
||||
proxy = {
|
||||
...proxy,
|
||||
name: Base64.safeDecode(params.remarks),
|
||||
name: other_params.remarks ? Base64.safeDecode(other_params.remarks) : proxy.server,
|
||||
"protocol-param":
|
||||
Base64.safeDecode(params.protoparam).replace(/\s/g, "") || "",
|
||||
Base64.safeDecode(other_params.protoparam || "").replace(/\s/g, ""),
|
||||
"obfs-param":
|
||||
Base64.safeDecode(params.obfsparam).replace(/\s/g, "") || "",
|
||||
Base64.safeDecode(other_params.obfsparam || "").replace(/\s/g, ""),
|
||||
};
|
||||
return proxy;
|
||||
};
|
||||
@@ -869,8 +869,8 @@ var ProxyUtils = (function () {
|
||||
line = line.split("vmess://")[1];
|
||||
const content = Base64.safeDecode(line);
|
||||
if (/=\s*vmess/.test(content)) {
|
||||
const partitions = content.split(",").map((p) => p.trim());
|
||||
// Quantumult VMess URI format
|
||||
const partitions = content.split(",").map((p) => p.trim());
|
||||
// get keyword params
|
||||
const params = {};
|
||||
for (const part of partitions) {
|
||||
@@ -888,16 +888,21 @@ var ProxyUtils = (function () {
|
||||
cipher: partitions[3],
|
||||
uuid: partitions[4].match(/^"(.*)"$/)[1],
|
||||
tls: params.obfs === "over-tls" || params.obfs === "wss",
|
||||
udp: JSON.parse(params["udp-relay"] || "false"),
|
||||
tfo: JSON.parse(params["fast-open"] || "false"),
|
||||
};
|
||||
|
||||
if (typeof params['udp-relay'] !== "undefined") proxy.udp = JSON.parse(params["udp-relay"]);
|
||||
if (typeof params['fast-open'] !== "undefined") proxy.udp = JSON.parse(params["fast-open"]);
|
||||
|
||||
// handle ws headers
|
||||
if (params.obfs === "ws" || params.obfs === "wss") {
|
||||
proxy.network = "ws";
|
||||
proxy["ws-path"] = params["obfs-uri"];
|
||||
proxy["ws-path"] = (params["obfs-path"] || '"/"').match(/^"(.*)"$/)[1];
|
||||
let obfs_host = params["obfs-header"];
|
||||
if (obfs_host && obfs_host.indexOf("Host") !== -1) {
|
||||
obfs_host = obfs_host.match(/Host:\s*([a-zA-Z0-9-.]*)/)[1];
|
||||
}
|
||||
proxy["ws-headers"] = {
|
||||
Host: params["obfs-host"] || proxy.server, // if no host provided, use the same as server
|
||||
Host: obfs_host || proxy.server, // if no host provided, use the same as server
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Vendored
+2
-2
@@ -1,2 +1,2 @@
|
||||
// UPDATED AT: 2020年11月27日 星期五 20时37分07秒 CST
|
||||
const $=API("sub-store"),Base64=new Base64Code;function service(){console.log("========== Sub-Store ===========");const e=express(),t="settings",s="subs",r="collections",n="builtin";function o(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 a(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)>864e5;if(t&&n&&!a)return $.log(`Use cached for url: ${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}$.read(s)||$.write({},s),$.read(r)||$.write({},r),$.read(t)||$.write({},t),$.read("rules")||$.write({},"rules"),$.write({rules:getBuiltInRules()},n),e.get("/download/collection/:name",async function(e,t){const{name:n}=e.params,{cache:i}=e.query||"false",p=e.query.target||o(e.headers)||"JSON",l=$.read(r),c=$.read(s),u=l[n];if($.info(`正在下载组合订阅:${n}`),u){const e=u.subscriptions;let s=[];for(let t=0;t<e.length;t++){const r=c[e[t]];$.info(`正在处理子订阅:${r.name},进度--${100*((t+1)/e.length).toFixed(1)}% `);try{const e=void 0===i?"JSON"===p||"URI"===p:i,t=await a(r.url,e);let n=ProxyUtils.parse(t);n=await ProxyUtils.process(n,r.process||[]),s=s.concat(n)}catch(e){$.error(`处理组合订阅中的子订阅: ${r.name}时出现错误:${e}! 该订阅已被跳过。`)}}0===(s=await ProxyUtils.process(s,u.process||[])).length&&($.notify("🌍 [Sub-Store] 下载组合订阅失败",`❌ 组合订阅:${n}中不含有效节点!`),t.status(500).json({status:"failed",message:`❌ 组合订阅${n}中不含有${p}可用的节点!`}));try{const e=ProxyUtils.produce(s,p);"JSON"===p?t.set("Content-Type","application/json;charset=utf-8").send(e):t.send(e)}catch(e){$.notify("🌍 [Sub-Store] 下载组合订阅失败",`❌ 无法下载组合订阅:${n}!`,`🤔 原因:${e}`),t.status(500).json({status:"failed",message:e})}}else $.notify("🌍 [Sub-Store] 下载组合订阅失败",`❌ 未找到组合订阅:${n}!`),t.status(404).json({status:"failed"})}),e.get("/download/:name",async function(e,t){const{name:r}=e.params,{cache:n}=e.query,i=e.query.target||o(e.headers)||"JSON";$.info(`正在下载订阅:${r}`);const p=$.read(s)[r];if(p)try{const e=void 0===n?"JSON"===i||"URI"===i:n,s=await a(p.url,e);let o=ProxyUtils.parse(s);o=await ProxyUtils.process(o,p.process||[]);const l=ProxyUtils.produce(o,i);"JSON"===i?t.set("Content-Type","application/json;charset=utf-8").send(l):t.send(l)}catch(e){$.notify("🌍 [Sub-Store] 下载订阅失败",`❌ 无法下载订阅:${r}!`,`🤔 原因:${e}`),t.status(500).json({status:"failed",message:e})}else $.notify("🌍 [Sub-Store] 下载订阅失败",`❌ 未找到订阅:${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:`订阅${n}不存在,无法更新!`})}).delete(function(e,t){const{name:n}=e.params;$.info(`删除订阅:${n}...`);let o=$.read(s);delete o[n],$.write(o,s);let a=$.read(r);for(const e of Object.keys(a))a[e].subscriptions=a[e].subscriptions.filter(e=>e!==n);$.write(a,r),t.json({status:"success"})}),e.route("/api/subs").get(function(e,t){const r=$.read(s);t.json({status:"success",data:r})}).post(function(e,t){const r=e.body,n=$.read(s);$.info(`正在创建订阅: ${r.name}`),n[r.name]&&t.status(500).json({status:"failed",message:`订阅${r.name}已存在!`});/^[\w-_]*$/.test(r.name)?(n[r.name]=r,$.write(n,s),t.status(201).json({status:"success",data:r})):t.status(500).json({status:"failed",message:`订阅名称 ${r.name} 中含有非法字符!名称中只能包含英文字母、数字、下划线、横杠。`})}),e.route("/api/collection/:name").get(function(e,t){const{name:s}=e.params,n=$.read(r)[s];n?t.json({status:"success",data:n}):t.status(404).json({status:"failed",message:`未找到订阅集:${s}!`})}).patch(function(e,t){const{name:s}=e.params;let n=e.body;const o=$.read(r);if(o[s]){const e={...o[s],...n};$.info(`正在更新组合订阅:${s}...`),delete o[s],o[n.name||s]=e,$.write(o,r),t.json({status:"success",data:e})}else t.status(500).json({status:"faLine truncated
|
||||
// UPDATED AT: 2020年12月 1日 星期二 14时53分43秒 CST
|
||||
const $=API("sub-store"),Base64=new Base64Code;function service(){console.log("========== Sub-Store ===========");const e=express(),t="settings",s="subs",r="collections",n="builtin";function o(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 a(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)>864e5;if(t&&n&&!a)return $.log(`Use cached for url: ${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}$.read(s)||$.write({},s),$.read(r)||$.write({},r),$.read(t)||$.write({},t),$.read("rules")||$.write({},"rules"),$.write({rules:getBuiltInRules()},n),e.get("/download/collection/:name",async function(e,t){const{name:n}=e.params,{cache:i}=e.query||"false",p=e.query.target||o(e.headers)||"JSON",l=$.read(r),c=$.read(s),u=l[n];if($.info(`正在下载组合订阅:${n}`),u){const e=u.subscriptions;let s=[];for(let t=0;t<e.length;t++){const r=c[e[t]];$.info(`正在处理子订阅:${r.name},进度--${100*((t+1)/e.length).toFixed(1)}% `);try{const e=void 0===i?"JSON"===p||"URI"===p:i,t=await a(r.url,e);let n=ProxyUtils.parse(t);n=await ProxyUtils.process(n,r.process||[]),s=s.concat(n)}catch(e){$.error(`处理组合订阅中的子订阅: ${r.name}时出现错误:${e}! 该订阅已被跳过。`)}}0===(s=await ProxyUtils.process(s,u.process||[])).length&&($.notify("🌍 [Sub-Store] 下载组合订阅失败",`❌ 组合订阅:${n}中不含有效节点!`),t.status(500).json({status:"failed",message:`❌ 组合订阅${n}中不含有${p}可用的节点!`}));try{const e=ProxyUtils.produce(s,p);"JSON"===p?t.set("Content-Type","application/json;charset=utf-8").send(e):t.send(e)}catch(e){$.notify("🌍 [Sub-Store] 下载组合订阅失败",`❌ 无法下载组合订阅:${n}!`,`🤔 原因:${e}`),t.status(500).json({status:"failed",message:e})}}else $.notify("🌍 [Sub-Store] 下载组合订阅失败",`❌ 未找到组合订阅:${n}!`),t.status(404).json({status:"failed"})}),e.get("/download/:name",async function(e,t){const{name:r}=e.params,{cache:n}=e.query,i=e.query.target||o(e.headers)||"JSON";$.info(`正在下载订阅:${r}`);const p=$.read(s)[r];if(p)try{const e=void 0===n?"JSON"===i||"URI"===i:n,s=await a(p.url,e);let o=ProxyUtils.parse(s);o=await ProxyUtils.process(o,p.process||[]);const l=ProxyUtils.produce(o,i);"JSON"===i?t.set("Content-Type","application/json;charset=utf-8").send(l):t.send(l)}catch(e){$.notify("🌍 [Sub-Store] 下载订阅失败",`❌ 无法下载订阅:${r}!`,`🤔 原因:${e}`),t.status(500).json({status:"failed",message:e})}else $.notify("🌍 [Sub-Store] 下载订阅失败",`❌ 未找到订阅:${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:`订阅${n}不存在,无法更新!`})}).delete(function(e,t){const{name:n}=e.params;$.info(`删除订阅:${n}...`);let o=$.read(s);delete o[n],$.write(o,s);let a=$.read(r);for(const e of Object.keys(a))a[e].subscriptions=a[e].subscriptions.filter(e=>e!==n);$.write(a,r),t.json({status:"success"})}),e.route("/api/subs").get(function(e,t){const r=$.read(s);t.json({status:"success",data:r})}).post(function(e,t){const r=e.body,n=$.read(s);$.info(`正在创建订阅: ${r.name}`),n[r.name]&&t.status(500).json({status:"failed",message:`订阅${r.name}已存在!`});/^[\w-_]*$/.test(r.name)?(n[r.name]=r,$.write(n,s),t.status(201).json({status:"success",data:r})):t.status(500).json({status:"failed",message:`订阅名称 ${r.name} 中含有非法字符!名称中只能包含英文字母、数字、下划线、横杠。`})}),e.route("/api/collection/:name").get(function(e,t){const{name:s}=e.params,n=$.read(r)[s];n?t.json({status:"success",data:n}):t.status(404).json({status:"failed",message:`未找到订阅集:${s}!`})}).patch(function(e,t){const{name:s}=e.params;let n=e.body;const o=$.read(r);if(o[s]){const e={...o[s],...n};$.info(`正在更新组合订阅:${s}...`),delete o[s],o[n.name||s]=e,$.write(o,r),t.json({status:"success",data:e})}else t.status(500).json({status:"faLine truncated
|
||||
Reference in new issue
Block a user