mirror of
https://github.com/sub-store-org/Sub-Store.git
synced 2026-11-27 23:13:43 +00:00
紧急修复BUG
This commit is contained in:
1 parent
2f7023e9e6
commit
f334f430d1
3 files changed
+23
-42
No files matched your search
+17
-36
@@ -13,11 +13,11 @@
|
||||
const $ = API("sub-store");
|
||||
const Base64 = new Base64Code();
|
||||
|
||||
startService();
|
||||
service();
|
||||
|
||||
/****************************************** Service **********************************************************/
|
||||
|
||||
function startService() {
|
||||
function service() {
|
||||
const welcome = heredoc(function () {/*
|
||||
_____ __ _____ __
|
||||
/ ___/ __ __ / /_ / ___/ / /_ ____ _____ ___
|
||||
@@ -27,7 +27,7 @@ function startService() {
|
||||
*/
|
||||
});
|
||||
console.log(welcome);
|
||||
const $app = express();
|
||||
const $app = express({debug: true});
|
||||
// Constants
|
||||
const SETTINGS_KEY = "settings";
|
||||
const SUBS_KEY = "subs";
|
||||
@@ -38,8 +38,8 @@ function startService() {
|
||||
if (!$.read(SETTINGS_KEY)) $.write({}, SETTINGS_KEY);
|
||||
|
||||
// download
|
||||
$app.get("/download/:name", downloadSubscription);
|
||||
$app.get("/download/collection/:name", downloadCollection);
|
||||
$app.get("/download/:name", downloadSubscription);
|
||||
|
||||
// subscription API
|
||||
$app.route("/api/sub/:name")
|
||||
@@ -62,7 +62,7 @@ function startService() {
|
||||
.post(createCollection);
|
||||
|
||||
// gist backup
|
||||
$app.get("/api/backup")
|
||||
$app.get("/api/backup");
|
||||
|
||||
$app.all("/", (req, res) => {
|
||||
res.status(405).end();
|
||||
@@ -103,6 +103,10 @@ function startService() {
|
||||
});
|
||||
}
|
||||
|
||||
$app.all("/", (req, res) => {
|
||||
res.send("Hello from sub-store, made with ❤️ by Peng-YM");
|
||||
});
|
||||
|
||||
$app.start();
|
||||
|
||||
// subscriptions API
|
||||
@@ -2947,8 +2951,8 @@ function Gist(backupKey, token) {
|
||||
* Mini Express Framework
|
||||
* https://github.com/Peng-YM/QuanX/blob/master/Tools/OpenAPI/Express.js
|
||||
*/
|
||||
function express({port, debug} = {port: 3000, debug: false}) {
|
||||
const {isNode} = debug ? false : ENV();
|
||||
function express(port = 3000) {
|
||||
const {isNode} = ENV();
|
||||
const DEFAULT_HEADERS = {
|
||||
"Content-Type": "text/plain;charset=UTF-8",
|
||||
"Access-Control-Allow-Origin": "*",
|
||||
@@ -2997,36 +3001,25 @@ function express({port, debug} = {port: 3000, debug: false}) {
|
||||
// dispatch url to route
|
||||
const dispatch = (request, start = 0) => {
|
||||
let {method, url, headers, body} = request;
|
||||
if (debug) {
|
||||
console.log("=================== Dispatching Request ===============================");
|
||||
console.log(JSON.stringify(request, null, 2));
|
||||
}
|
||||
if (/json/i.test(headers["Content-Type"])) {
|
||||
body = JSON.parse(body);
|
||||
}
|
||||
|
||||
method = method.toUpperCase();
|
||||
const {path, query} = extractURL(url);
|
||||
let handler = null;
|
||||
let i;
|
||||
|
||||
// path matching
|
||||
let handler = null;
|
||||
let longestMatchedPattern = 0;
|
||||
for (i = start; i < handlers.length; i++) {
|
||||
if (handlers[i].method === "ALL" || method === handlers[i].method) {
|
||||
const {pattern} = handlers[i];
|
||||
if (patternMatched(pattern, path)) {
|
||||
if (pattern.split("/").length > longestMatchedPattern) {
|
||||
handler = handlers[i];
|
||||
longestMatchedPattern = pattern.split("/").length;
|
||||
}
|
||||
handler = handlers[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (handler) {
|
||||
if (debug) {
|
||||
console.log(`Pattern: ${handler.pattern} matched`);
|
||||
}
|
||||
// dispatch to next handler
|
||||
const next = () => {
|
||||
dispatch(method, url, i);
|
||||
@@ -3041,22 +3034,12 @@ function express({port, debug} = {port: 3000, debug: false}) {
|
||||
body,
|
||||
};
|
||||
const res = Response();
|
||||
const cb = handler.callback;
|
||||
const onError = (err) => {
|
||||
handler.callback(req, res, next).catch((err) => {
|
||||
res.status(500).json({
|
||||
status: "failed",
|
||||
message: `Internal Server Error: ${err}`,
|
||||
});
|
||||
};
|
||||
if (cb.constructor.name === "AsyncFunction") {
|
||||
handler.callback(req, res, next).catch(onError);
|
||||
} else {
|
||||
try {
|
||||
handler.callback(req, res, next);
|
||||
} catch (err) {
|
||||
onError(err);
|
||||
}
|
||||
}
|
||||
});
|
||||
} else {
|
||||
// no route, return 404
|
||||
const res = Response();
|
||||
@@ -3117,7 +3100,6 @@ function express({port, debug} = {port: 3000, debug: false}) {
|
||||
307: "HTTP/1.1 307 Temporary Redirect",
|
||||
308: "HTTP/1.1 308 Permanent Redirect",
|
||||
404: "HTTP/1.1 404 Not Found",
|
||||
405: "HTTP/1.1 405 Method Not Allowed",
|
||||
500: "HTTP/1.1 500 Internal Server Error",
|
||||
};
|
||||
return new (class {
|
||||
@@ -3152,7 +3134,7 @@ function express({port, debug} = {port: 3000, debug: false}) {
|
||||
|
||||
json(data) {
|
||||
this.set("Content-Type", "application/json;charset=UTF-8");
|
||||
this.send(JSON.stringify(data, null, 2));
|
||||
this.send(JSON.stringify(data));
|
||||
}
|
||||
|
||||
set(key, val) {
|
||||
@@ -3234,7 +3216,6 @@ function express({port, debug} = {port: 3000, debug: false}) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/****************************************** Third Party Libraries **********************************************************/
|
||||
function heredoc(fn) {
|
||||
return fn.toString().split('\n').slice(1, -2).join('\n') + '\n';
|
||||
|
||||
Vendored
+2
-2
@@ -1,2 +1,2 @@
|
||||
// UPDATED AT: 2020年11月24日 星期二 21时20分42秒 CST
|
||||
const $=API("sub-store"),Base64=new Base64Code;function startService(){const e=heredoc(function(){});console.log(e);const t=express(),s="settings",r="subs",n="collections";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":"JSON"}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;const{body:i}=await s.get(e);if(0===i.replace(/\s/g,"").length)throw new Error("订阅内容为空!");return $.write(i,r),$.write((new Date).getTime(),o),i}$.read(r)||$.write({},r),$.read(n)||$.write({},n),$.read(s)||$.write({},s),t.get("/download/:name",async function(e,t){const{name:s}=e.params,{cache:n}=e.query,i=e.query.target||o(e.headers),p=$.read(r)[s];if(p)try{const e=void 0===n?"JSON"===i||"URI"===i:n,r=await a(p.url,e);let o=ProxyUtils.parse(r);o=await ProxyUtils.process(o,p.process||[]);const l=ProxyUtils.produce(o,i);"JSON"===i?t.set("Content-Type","application/json").send(l):t.send(l)}catch(e){$.notify("🌍 [Sub-Store] 下载订阅失败",`❌ 无法下载订阅:${s}!`,`🤔 原因:${e}`),t.status(500).json({status:"failed",message:e})}else $.notify("🌍 [Sub-Store] 下载订阅失败",`❌ 未找到订阅:${s}!`),t.status(404).json({status:"failed"})}),t.get("/download/collection/:name",async function(e,t){const{name:s}=e.params,{cache:i}=e.query||"false",p=e.query.target||o(e.headers),l=$.read(n),c=$.read(r),u=l[s];if($.info(`正在下载组合订阅:${s}`),u){const e=u.subscriptions;let r=[];for(let t=0;t<e.length;t++){const s=c[e[t]];$.info(`正在处理子订阅:${s.name},进度--${100*(t+1/e.length).toFixed(1)}% `);try{const e=void 0===i?"JSON"===p||"URI"===p:i,t=await a(s.url,e);r=r.concat(ProxyUtils.parse(t)),r=await ProxyUtils.process(r,s.process||[])}catch(e){$.error(`处理组合订阅中的子订阅: ${s.name}时出现错误:${e}! 该订阅已被跳过。`)}}0===(r=await ProxyUtils.process(r,u.process||[])).length&&($.notify("🌍 [Sub-Store] 下载组合订阅失败",`❌ 未找到组合订阅:${s}!`),t.status(500).json({status:"failed",message:`❌ 组合订阅${s}中不含有${p}可用的节点!`}));try{const e=ProxyUtils.produce(r,p);"JSON"===p?t.set("Content-Type","application/json").send(e):t.send(e)}catch(e){$.notify("🌍 [Sub-Store] 下载组合订阅失败",`❌ 无法下载组合订阅:${s}!`,`🤔 原因:${e}`),t.status(500).json({status:"failed",message:e})}}else $.notify("🌍 [Sub-Store] 下载组合订阅失败",`❌ 未找到组合订阅:${s}!`),t.status(404).json({status:"failed"})}),t.route("/api/sub/: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 o=e.body;const a=$.read(r);if(a[s]){const e={...a[s],...o};if($.info(`正在更新订阅: ${s}`),s!==o.name){const t=$.read(n);for(const e of Object.keys(t)){const r=t[e].subscriptions.indexOf(s);-1!==r&&(t[e].subscriptions[r]=o.name)}delete a[s],a[o.name]=e}else a[s]=e;$.write(a,r),t.json({status:"success",data:e})}else t.status(500).json({status:"failed",message:`订阅${s}不存在,无法更新!`})}).delete(function(e,t){const{name:s}=e.params;$.info(`删除订阅:${s}...`);let o=$.read(r);delete o[s],$.write(o,r);let a=$.read(n);for(const e of Object.keys(a))a[e].subscriptions=a[e].subscriptions.filter(e=>e!==s);$.write(a,n),t.json({status:"success"})}),t.route("/api/subs").get(function(e,t){const s=$.read(r);t.json({status:"success",data:s})}).post(function(e,t){const s=e.body,n=$.read(r);$.info(`正在创建订阅: ${s.name}`),n[s.name]&&t.status(500).json({status:"failed",message:`订阅${s.name}已存在!`});/^[\w-_]*$/.test(s.name)?(n[s.name]=s,$.write(n,r),t.status(201).json({status:"success",data:s})):t.status(500).json({status:"failed",message:`订阅名称 ${s.name} 中含有非法字符!名称中只能包含英文字母、数字、下划线、横杠。`})}),t.route("/api/collection/:name").get(function(e,t){const{name:s}=e.params,r=$.read(n)[s];r?t.json({status:"success",data:r}):t.status(404).json({status:"failed",message:`未找到订阅集:${s}!`})}).patch(function(e,t){const{name:s}=e.params;let r=e.body;const o=$.read(n);if(o[s]){const e={...o[s],...r};$.info(`正在更新组合订阅:${s}...`),delete o[s],o[r.name||s]=e,$.write(o,n),t.json({status:"success",data:e})}else t.status(500).json({status:"failed",message:`订阅集${s}不存在,无法更新!`})}).delete(function(e,t){const{name:s}=e.params;$.info(`正在删除组合订阅:${s}`);let r=$.read(n);delete r[s],$.write(r,n),t.json({status:"success"})}),t.route("/api/colLine truncated
|
||||
// UPDATED AT: 2020年11月24日 星期二 22时10分12秒 CST
|
||||
const $=API("sub-store"),Base64=new Base64Code;function service(){const e=heredoc(function(){});console.log(e);const t=express({debug:!0}),s="settings",r="subs",n="collections";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":"JSON"}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;const{body:i}=await s.get(e);if(0===i.replace(/\s/g,"").length)throw new Error("订阅内容为空!");return $.write(i,r),$.write((new Date).getTime(),o),i}$.read(r)||$.write({},r),$.read(n)||$.write({},n),$.read(s)||$.write({},s),t.get("/download/collection/:name",async function(e,t){const{name:s}=e.params,{cache:i}=e.query||"false",p=e.query.target||o(e.headers),l=$.read(n),c=$.read(r),u=l[s];if($.info(`正在下载组合订阅:${s}`),u){const e=u.subscriptions;let r=[];for(let t=0;t<e.length;t++){const s=c[e[t]];$.info(`正在处理子订阅:${s.name},进度--${100*(t+1/e.length).toFixed(1)}% `);try{const e=void 0===i?"JSON"===p||"URI"===p:i,t=await a(s.url,e);r=r.concat(ProxyUtils.parse(t)),r=await ProxyUtils.process(r,s.process||[])}catch(e){$.error(`处理组合订阅中的子订阅: ${s.name}时出现错误:${e}! 该订阅已被跳过。`)}}0===(r=await ProxyUtils.process(r,u.process||[])).length&&($.notify("🌍 [Sub-Store] 下载组合订阅失败",`❌ 未找到组合订阅:${s}!`),t.status(500).json({status:"failed",message:`❌ 组合订阅${s}中不含有${p}可用的节点!`}));try{const e=ProxyUtils.produce(r,p);"JSON"===p?t.set("Content-Type","application/json").send(e):t.send(e)}catch(e){$.notify("🌍 [Sub-Store] 下载组合订阅失败",`❌ 无法下载组合订阅:${s}!`,`🤔 原因:${e}`),t.status(500).json({status:"failed",message:e})}}else $.notify("🌍 [Sub-Store] 下载组合订阅失败",`❌ 未找到组合订阅:${s}!`),t.status(404).json({status:"failed"})}),t.get("/download/:name",async function(e,t){const{name:s}=e.params,{cache:n}=e.query,i=e.query.target||o(e.headers),p=$.read(r)[s];if(p)try{const e=void 0===n?"JSON"===i||"URI"===i:n,r=await a(p.url,e);let o=ProxyUtils.parse(r);o=await ProxyUtils.process(o,p.process||[]);const l=ProxyUtils.produce(o,i);"JSON"===i?t.set("Content-Type","application/json").send(l):t.send(l)}catch(e){$.notify("🌍 [Sub-Store] 下载订阅失败",`❌ 无法下载订阅:${s}!`,`🤔 原因:${e}`),t.status(500).json({status:"failed",message:e})}else $.notify("🌍 [Sub-Store] 下载订阅失败",`❌ 未找到订阅:${s}!`),t.status(404).json({status:"failed"})}),t.route("/api/sub/: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 o=e.body;const a=$.read(r);if(a[s]){const e={...a[s],...o};if($.info(`正在更新订阅: ${s}`),s!==o.name){const t=$.read(n);for(const e of Object.keys(t)){const r=t[e].subscriptions.indexOf(s);-1!==r&&(t[e].subscriptions[r]=o.name)}delete a[s],a[o.name]=e}else a[s]=e;$.write(a,r),t.json({status:"success",data:e})}else t.status(500).json({status:"failed",message:`订阅${s}不存在,无法更新!`})}).delete(function(e,t){const{name:s}=e.params;$.info(`删除订阅:${s}...`);let o=$.read(r);delete o[s],$.write(o,r);let a=$.read(n);for(const e of Object.keys(a))a[e].subscriptions=a[e].subscriptions.filter(e=>e!==s);$.write(a,n),t.json({status:"success"})}),t.route("/api/subs").get(function(e,t){const s=$.read(r);t.json({status:"success",data:s})}).post(function(e,t){const s=e.body,n=$.read(r);$.info(`正在创建订阅: ${s.name}`),n[s.name]&&t.status(500).json({status:"failed",message:`订阅${s.name}已存在!`});/^[\w-_]*$/.test(s.name)?(n[s.name]=s,$.write(n,r),t.status(201).json({status:"success",data:s})):t.status(500).json({status:"failed",message:`订阅名称 ${s.name} 中含有非法字符!名称中只能包含英文字母、数字、下划线、横杠。`})}),t.route("/api/collection/:name").get(function(e,t){const{name:s}=e.params,r=$.read(n)[s];r?t.json({status:"success",data:r}):t.status(404).json({status:"failed",message:`未找到订阅集:${s}!`})}).patch(function(e,t){const{name:s}=e.params;let r=e.body;const o=$.read(n);if(o[s]){const e={...o[s],...r};$.info(`正在更新组合订阅:${s}...`),delete o[s],o[r.name||s]=e,$.write(o,n),t.json({status:"success",data:e})}else t.status(500).json({status:"failed",message:`订阅集${s}不存在,无法更新!`})}).delete(function(e,t){const{name:s}=e.params;$.info(`正在删除组合订阅:${s}`);let r=$.read(n);delete r[s],$.write(r,n),t.json({status:"success"})}),t.route("/apLine truncated
|
||||
@@ -6,10 +6,10 @@
|
||||
grow
|
||||
v-model="activeItem"
|
||||
>
|
||||
<v-btn :to="{path:'/dashboard'}" value="dashboard">
|
||||
<span>首页</span>
|
||||
<v-icon>speed</v-icon>
|
||||
</v-btn>
|
||||
<!-- <v-btn :to="{path:'/dashboard'}" value="dashboard">-->
|
||||
<!-- <span>首页</span>-->
|
||||
<!-- <v-icon>speed</v-icon>-->
|
||||
<!-- </v-btn>-->
|
||||
|
||||
<v-btn :to="{path: '/'}" value="subscription">
|
||||
<span>订阅</span>
|
||||
|
||||
Reference in new issue
Block a user