mirror of
https://github.com/sub-store-org/Sub-Store.git
synced 2026-11-27 06:43:08 +00:00
Merge ; commit '5b1e24a4afdc1ca8d06293c172f7130a1c91a1fc'
Conflicts: backend/sub-store.min.js
This commit is contained in:
commit
e5cfa2c821
3 files changed
+35
-11
No files matched your search
+14
-9
@@ -773,10 +773,10 @@ function service() {
|
||||
}
|
||||
|
||||
async function refreshCache(req, res) {
|
||||
const {url} = req.body;
|
||||
const { url, ua } = req.body;
|
||||
$.info(`Refreshing cache for URL: ${url}`);
|
||||
try {
|
||||
const raw = await getResource(url, false);
|
||||
const raw = await getResource(url, false, ua);
|
||||
$.write(raw, `#${Base64.safeEncode(url)}`);
|
||||
res.json({
|
||||
status: "success",
|
||||
@@ -871,11 +871,16 @@ function service() {
|
||||
}
|
||||
|
||||
// get resource, with cache ability to speedup response time
|
||||
async function getResource(url, useCache = true) {
|
||||
// use QX agent to get flow headers
|
||||
async function getResource(url, useCache = true, userAgent) {
|
||||
// use QX agent to get flow headers ,if not assign user-agent
|
||||
let ua = userAgent
|
||||
if (typeof userAgent == "undefined" || userAgent == null || userAgent.trim().length == 0) {
|
||||
ua = "Quantumult%20X"
|
||||
}
|
||||
|
||||
const $http = HTTP({
|
||||
headers: {
|
||||
"User-Agent": "Quantumult%20X",
|
||||
"User-Agent": ua,
|
||||
},
|
||||
});
|
||||
const key = "#" + Base64.safeEncode(url);
|
||||
@@ -915,7 +920,7 @@ function service() {
|
||||
) {
|
||||
if (type === "subscription") {
|
||||
const sub = item;
|
||||
const raw = await getResource(sub.url, useCache);
|
||||
const raw = await getResource(sub.url, useCache, sub.ua);
|
||||
// parse proxies
|
||||
let proxies = ProxyUtils.parse(raw);
|
||||
if (!noProcessor) {
|
||||
@@ -945,7 +950,7 @@ function service() {
|
||||
}% `
|
||||
);
|
||||
try {
|
||||
const raw = await getResource(sub.url, useCache);
|
||||
const raw = await getResource(sub.url, useCache, sub.ua);
|
||||
// parse proxies
|
||||
let currentProxies = ProxyUtils.parse(raw);
|
||||
if (!noProcessor) {
|
||||
@@ -1379,13 +1384,13 @@ var ProxyUtils = (function () {
|
||||
let paramArr = line.split("?")
|
||||
let sni=null
|
||||
if (paramArr.length > 1) {
|
||||
paramArr=paramArr[1].split("#")[0].split("&")
|
||||
paramArr = paramArr[1].split("#")[0].split("&")
|
||||
const params = new Map(paramArr.map((item) => {
|
||||
return item.split("=")
|
||||
}))
|
||||
sni = params.get("sni")
|
||||
}
|
||||
|
||||
|
||||
return {
|
||||
name: name || `[Trojan] ${server}`, // trojan uri may have no server tag!
|
||||
type: "trojan",
|
||||
|
||||
Vendored
+2
-2
@@ -1,2 +1,2 @@
|
||||
// UPDATED AT: 2021年 9月 9日 星期四 18时35分32秒 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 l({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 u(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,noProcessor:o}={platform:"JSON",useCache:!1,noProcessor:!1}){if("subscription"===e){const e=t,s=await f(e.url,n);let a=ProxyUtils.parse(s);o||(a=await ProxyUtils.process(a,e.process||[]));const i={};return a.forEach(e=>{i[e.name]&&$.notify("🌍 『 𝑺𝒖𝒃-𝑺𝒕𝒐𝒓𝒆 』","⚠️ 订阅包含重复节点!","请仔细检测配置!",{"media-url":"https://cdn3.iconfinder.com/data/icons/seo-outline-1/512/25_code_program_programming_develop_bug_search_developer-512.png"})}),ProxyUtils.produce(a,r)}if("collection"===e){const e=$.read(s),a=t,i=a.subscriptions;let p=[];for(let t=0;t<i.length;t++){const s=e[i[t]];$.info(`正在处理子订阅:${s.name},进度--${100*((t+1)/i.length).toFixed(1)}% `);try{const e=await f(s.url,n);let t=ProxyUtils.parse(e);o||(t=await ProxyUtils.process(t,s.process||[])),p=p.concat(t)}catch(e){$.error(`处理组合订阅中的子订阅: ${s.name}时出现错误:${e}! 该订阅已被跳过。`)}}if(o||(p=await ProxyUtils.process(p,a.process||[])),0===p.length)throw new Error("组合订阅中不含有效节点!");return ProxyUtils.produce(p,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",{raw:o}=e.query||"false",a=e.query.target||u(e.headers)||"JSON",i=void 0===n?"JSON"===a||"URI"===a:n,p=$.read(r)[s];if($.info(`正在下载组合订阅:${s}`),p)try{const e=await d({type:"collection",item:p,platform:a,useCache:i,noProcessor:o});"JSON"===a?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,{raw:o}=e.query||"false",a=e.query.target||u(e.headers)||"JSON",i=void 0===n?"JSON"===a||"URI"===a:n;$.info(`正在下载订阅:${r}`);const p=$.read(s)[r];if(p)try{const s=await d({type:"subscription",item:p,platform:a,useCache:i,noProcessor:o});if(-1!==["QX","Surge","Loon"].indexOf(u(e.headers))){const{headers:e}=await $.http.get({url:p.url,headers:{"User-Agent":"Quantumult/1.0.13 (iPhone10,3; iOS 14.0)"}}),s=Object.keys(e).filter(e=>/SUBSCRIPTION-USERINFO/i.test(e))[0],r=e[s];t.set("subscription-userinfo",r)}"JSON"===a?t.set("Content-Type","application/json;charset=utf-8").send(s):t.send(s)}catch(e){$.notify("🌍 『 𝑺𝒖𝒃-𝑺𝒕𝒐𝒓𝒆 』 下载订阅失败",`❌ 无法下载订阅:${r}!`,`🤔 原因:${e}`),t.status(500).json({status:"failed",message:e})}else $.notify("🌍 『 𝑺𝒖𝒃-𝑺𝒕𝒐𝒓𝒆 』 下载订阅失Line truncated
|
||||
// UPDATED AT: 2021年 9月15日 星期三 22时37分25秒 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 l({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 u(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,s){let r=s;void 0!==s&&null!=s&&0!=s.trim().length||(r="Quantumult%20X");const n=HTTP({headers:{"User-Agent":r}}),o="#"+Base64.safeEncode(e),a=$.read(o),i=`#TIME-${Base64.safeEncode(e)}`,p=(new Date).getTime()-$.read(i)>36e5;if(t&&a&&!p)return $.log(`Use cached for resource: ${e}`),a;let c="";try{c=(await n.get(e)).body}catch(e){throw new Error(e)}finally{$.write(c,o),$.write((new Date).getTime(),i)}if(0===c.replace(/\s/g,"").length)throw new Error("订阅内容为空!");return c}async function d({type:e,item:t,platform:r,useCache:n,noProcessor:o}={platform:"JSON",useCache:!1,noProcessor:!1}){if("subscription"===e){const e=t,s=await f(e.url,n,e.ua);let a=ProxyUtils.parse(s);o||(a=await ProxyUtils.process(a,e.process||[]));const i={};return a.forEach(e=>{i[e.name]&&$.notify("🌍 『 𝑺𝒖𝒃-𝑺𝒕𝒐𝒓𝒆 』","⚠️ 订阅包含重复节点!","请仔细检测配置!",{"media-url":"https://cdn3.iconfinder.com/data/icons/seo-outline-1/512/25_code_program_programming_develop_bug_search_developer-512.png"})}),ProxyUtils.produce(a,r)}if("collection"===e){const e=$.read(s),a=t,i=a.subscriptions;let p=[];for(let t=0;t<i.length;t++){const s=e[i[t]];$.info(`正在处理子订阅:${s.name},进度--${100*((t+1)/i.length).toFixed(1)}% `);try{const e=await f(s.url,n,s.ua);let t=ProxyUtils.parse(e);o||(t=await ProxyUtils.process(t,s.process||[])),p=p.concat(t)}catch(e){$.error(`处理组合订阅中的子订阅: ${s.name}时出现错误:${e}! 该订阅已被跳过。`)}}if(o||(p=await ProxyUtils.process(p,a.process||[])),0===p.length)throw new Error("组合订阅中不含有效节点!");return ProxyUtils.produce(p,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",{raw:o}=e.query||"false",a=e.query.target||u(e.headers)||"JSON",i=void 0===n?"JSON"===a||"URI"===a:n,p=$.read(r)[s];if($.info(`正在下载组合订阅:${s}`),p)try{const e=await d({type:"collection",item:p,platform:a,useCache:i,noProcessor:o});"JSON"===a?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,{raw:o}=e.query||"false",a=e.query.target||u(e.headers)||"JSON",i=void 0===n?"JSON"===a||"URI"===a:n;$.info(`正在下载订阅:${r}`);const p=$.read(s)[r];if(p)try{const s=await d({type:"subscription",item:p,platform:a,useCache:i,noProcessor:o});if(-1!==["QX","Surge","Loon"].indexOf(u(e.headers))){const{headers:e}=await $.http.get({url:p.url,headers:{"User-Agent":"Quantumult/1.0.13 (iPhone10,3; iOS 14.0)"}}),s=Object.keys(e).filter(e=>/SUBSCRIPTION-USERINFO/i.test(e))[0],r=e[s];t.set("subscription-userinfo",r)}"JSON"===a?t.set("Content-Type","application/json;charset=utf-8").send(s):t.send(s)}catch(e){$.notify("🌍 『 𝑺𝒖𝒃-𝑺𝒕𝒐𝒓𝒆 』 下载订阅失败",`❌ 无法下载订阅:${r}!`,`🤔 原因:${e}`),t.status(500).json({status:"failed",message:e})}else $.notiLine truncated
|
||||
@@ -49,6 +49,16 @@
|
||||
/>
|
||||
</v-list-item>
|
||||
</v-list>
|
||||
<v-textarea
|
||||
v-model="options.ua"
|
||||
auto-grow
|
||||
class="mt-2"
|
||||
clear-icon="clear"
|
||||
clearable
|
||||
label="User-Agent"
|
||||
placeholder="自定义下载订阅使用的User-Agent,可选。"
|
||||
rows="2"
|
||||
/>
|
||||
<v-textarea
|
||||
v-model="options.icon"
|
||||
auto-grow
|
||||
@@ -354,6 +364,7 @@ export default {
|
||||
name: "",
|
||||
url: "",
|
||||
icon: "",
|
||||
ua: "",
|
||||
useless: "KEEP",
|
||||
udp: "DEFAULT",
|
||||
"skip-cert-verify": "DEFAULT",
|
||||
@@ -413,6 +424,13 @@ export default {
|
||||
} else {
|
||||
output.url = this.options.url;
|
||||
}
|
||||
// assign user-agent, if ua is set
|
||||
let ua = this.options.ua;
|
||||
if (typeof ua != "undefined" && ua != null && ua.trim().length > 0) {
|
||||
output.ua = ua;
|
||||
}else{
|
||||
output.ua=""
|
||||
}
|
||||
// useless filter
|
||||
if (this.options.useless === 'REMOVE') {
|
||||
output.process.push({
|
||||
@@ -573,6 +591,7 @@ function loadProcess(options, source, isCollection = false) {
|
||||
...options,
|
||||
name: source.name,
|
||||
icon: source.icon,
|
||||
ua: source.ua
|
||||
};
|
||||
if (isCollection) {
|
||||
options.subscriptions = source.subscriptions;
|
||||
|
||||
Reference in new issue
Block a user