mirror of
https://github.com/sub-store-org/Sub-Store.git
synced 2026-11-27 06:43:08 +00:00
修复Loon和Surge上无法保存的bug
This commit is contained in:
1 parent
f9dd77ed41
commit
710d5b14e5
2 files changed
+8
-14
No files matched your search
+6
-12
@@ -64,10 +64,6 @@ function service() {
|
||||
// gist backup
|
||||
$app.get("/api/backup");
|
||||
|
||||
$app.all("/", (req, res) => {
|
||||
res.status(405).end();
|
||||
});
|
||||
|
||||
// Storage management
|
||||
$app.route("/api/storage")
|
||||
.get((req, res) => {
|
||||
@@ -96,12 +92,10 @@ function service() {
|
||||
res.set("location", "https://sub-store.vercel.app/").status(302).end();
|
||||
});
|
||||
|
||||
// handle preflight request for QX
|
||||
if (ENV().isQX) {
|
||||
$app.options("/", async (req, res) => {
|
||||
res.status(200).end();
|
||||
});
|
||||
}
|
||||
// handle preflight request
|
||||
$app.options("/", async (req, res) => {
|
||||
res.status(200).end();
|
||||
});
|
||||
|
||||
$app.all("/", (req, res) => {
|
||||
res.send("Hello from sub-store, made with ❤️ by Peng-YM");
|
||||
@@ -2951,7 +2945,7 @@ function Gist(backupKey, token) {
|
||||
* Mini Express Framework
|
||||
* https://github.com/Peng-YM/QuanX/blob/master/Tools/OpenAPI/Express.js
|
||||
*/
|
||||
function express(port = 3000) {
|
||||
function express({port} = {port: 3000}) {
|
||||
const {isNode} = ENV();
|
||||
const DEFAULT_HEADERS = {
|
||||
"Content-Type": "text/plain;charset=UTF-8",
|
||||
@@ -3008,7 +3002,7 @@ function express(port = 3000) {
|
||||
method = method.toUpperCase();
|
||||
const {path, query} = extractURL(url);
|
||||
|
||||
// path matching
|
||||
// pattern match
|
||||
let handler = null;
|
||||
let i;
|
||||
let longestMatchedPattern = 0;
|
||||
|
||||
Vendored
+2
-2
@@ -1,2 +1,2 @@
|
||||
// UPDATED AT: 2020年11月24日 星期二 22时28分39秒 CST
|
||||
const $=API("sub-store"),Base64=new Base64Code;function service(){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/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("/api/collectiLine truncated
|
||||
// UPDATED AT: 2020年11月24日 星期二 22时58分40秒 CST
|
||||
const $=API("sub-store"),Base64=new Base64Code;function service(){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/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("/api/collectiLine truncated
|
||||
Reference in new issue
Block a user