mirror of
https://github.com/sub-store-org/Sub-Store.git
synced 2026-11-29 07:50:33 +00:00
多项改进
1. 现在可以编辑远程配置了。 2. 远程配置增加自动同步的选项,配合Cron脚本可以定期同步并上传配置到gist。
This commit is contained in:
1 parent
85ee743988
commit
a0691bedaf
4 files changed
+157
-59
No files matched your search
+57
-2
@@ -116,6 +116,9 @@ function service() {
|
||||
$app.get("/api/utils/env", getEnv); // get runtime environment
|
||||
$app.get("/api/utils/backup", gistBackup); // gist backup actions
|
||||
|
||||
// cron triggered functions
|
||||
$app.get("/api/cron/sync-artifacts", cronSyncArtifacts); // sync all artifacts
|
||||
|
||||
// Redirect sub.store to vercel webpage
|
||||
$app.get("/", async (req, res) => {
|
||||
// 302 redirect
|
||||
@@ -600,7 +603,7 @@ function service() {
|
||||
}
|
||||
|
||||
function updateArtifact(req, res) {
|
||||
const allArtifacts = $.read(SETTINGS_KEY);
|
||||
const allArtifacts = $.read(ARTIFACTS_KEY);
|
||||
const oldName = req.params.name;
|
||||
const artifact = allArtifacts[oldName];
|
||||
if (artifact) {
|
||||
@@ -632,9 +635,61 @@ function service() {
|
||||
}
|
||||
}
|
||||
|
||||
async function cronSyncArtifacts(req, res) {
|
||||
$.info("开始同步所有远程配置...");
|
||||
const allArtifacts = $.read(ARTIFACTS_KEY);
|
||||
let success = [], failed = [];
|
||||
for (const artifact of Object.values(allArtifacts)) {
|
||||
if (artifact.sync) {
|
||||
$.info(`正在同步云配置:${artifact.name}...`);
|
||||
try {
|
||||
let item;
|
||||
switch (artifact.type) {
|
||||
case 'subscription':
|
||||
item = $.read(SUBS_KEY)[artifact.source];
|
||||
break;
|
||||
case 'collection':
|
||||
item = $.read(COLLECTIONS_KEY)[artifact.source];
|
||||
break;
|
||||
case 'rule':
|
||||
item = $.read(RULES_KEY)[artifact.source];
|
||||
break;
|
||||
}
|
||||
const output = await produceArtifact({
|
||||
type: artifact.type,
|
||||
item,
|
||||
platform: artifact.platform
|
||||
});
|
||||
const resp = await syncArtifact({
|
||||
filename: artifact.name,
|
||||
content: output
|
||||
});
|
||||
artifact.updated = new Date().getTime();
|
||||
const body = JSON.parse(resp.body);
|
||||
artifact.url = body.files[artifact.name].raw_url.replace(/\/raw\/[^\/]*\/(.*)/, "/raw/$1");
|
||||
$.write(allArtifacts, ARTIFACTS_KEY);
|
||||
$.info(`✅ 成功同步云配置:${artifact.name}`);
|
||||
success.push(artifact);
|
||||
} catch (err) {
|
||||
$.error(`云配置: ${artifact.name} 同步失败!原因:${err}`);
|
||||
$.notify(
|
||||
`🌍 『 𝑺𝒖𝒃-𝑺𝒕𝒐𝒓𝒆 』 同步订阅失败`,
|
||||
`❌ 无法同步订阅:${artifact.name}!`,
|
||||
`🤔 原因:${err}`
|
||||
);
|
||||
failed.push(artifact);
|
||||
}
|
||||
}
|
||||
}
|
||||
res.json({
|
||||
success,
|
||||
failed
|
||||
});
|
||||
}
|
||||
|
||||
async function deleteArtifact(req, res) {
|
||||
const name = req.params.name;
|
||||
$.info(`正在删除Artifact:${name}`);
|
||||
$.info(`正在删除远程配置:${name}`);
|
||||
const allArtifacts = $.read(ARTIFACTS_KEY);
|
||||
try {
|
||||
const artifact = allArtifacts[name];
|
||||
|
||||
Vendored
+2
-2
@@ -1,2 +1,2 @@
|
||||
// UPDATED AT: 2021年 1月25日 星期一 14时23分07秒 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,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);return o||(a=await ProxyUtils.process(a,e.process||[])),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||l(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||l(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(l(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("🌍 『 𝑺𝒖𝒃-𝑺𝒕𝒐𝒓𝒆 』 下载订阅失败",`❌ 未找到订阅:${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{nameLine truncated
|
||||
// UPDATED AT: 2021年 2月27日 星期六 12时39分10秒 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,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);return o||(a=await ProxyUtils.process(a,e.process||[])),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||l(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||l(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(l(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("🌍 『 𝑺𝒖𝒃-𝑺𝒕𝒐𝒓𝒆 』 下载订阅失败",`❌ 未找到订阅:${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{nameLine truncated
|
||||
@@ -0,0 +1,6 @@
|
||||
const $ = API();
|
||||
$.http.get('https://sub.store/api/cron/sync-artifacts');
|
||||
$.done();
|
||||
|
||||
// prettier ignore
|
||||
function ENV(){const e="undefined"!=typeof $task,t="undefined"!=typeof $loon,s="undefined"!=typeof $httpClient&&!t,i="function"==typeof require&&"undefined"!=typeof $jsbox;return{isQX:e,isLoon:t,isSurge:s,isNode:"function"==typeof require&&!i,isJSBox:i,isRequest:"undefined"!=typeof $request,isScriptable:"undefined"!=typeof importModule}}function HTTP(e={baseURL:""}){const{isQX:t,isLoon:s,isSurge:i,isScriptable:n,isNode:o}=ENV(),r=/https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&\/\/=]*)/;const u={};return["GET","POST","PUT","DELETE","HEAD","OPTIONS","PATCH"].forEach(l=>u[l.toLowerCase()]=(u=>(function(u,l){l="string"==typeof l?{url:l}:l;const h=e.baseURL;h&&!r.test(l.url||"")&&(l.url=h?h+l.url:l.url);const a=(l={...e,...l}).timeout,c={onRequest:()=>{},onResponse:e=>e,onTimeout:()=>{},...l.events};let f,d;if(c.onRequest(u,l),t)f=$task.fetch({method:u,...l});else if(s||i||o)f=new Promise((e,t)=>{(o?require("request"):$httpClient)[u.toLowerCase()](l,(s,i,n)=>{s?t(s):e({statusCode:i.status||i.statusCode,headers:i.headers,body:n})})});else if(n){const e=new Request(l.url);e.method=u,e.headers=l.headers,e.body=l.body,f=new Promise((t,s)=>{e.loadString().then(s=>{t({statusCode:e.response.statusCode,headers:e.response.headers,body:s})}).catch(e=>s(e))})}const p=a?new Promise((e,t)=>{d=setTimeout(()=>(c.onTimeout(),t(`${u} URL: ${l.url} exceeds the timeout ${a} ms`)),a)}):null;return(p?Promise.race([p,f]).then(e=>(clearTimeout(d),e)):f).then(e=>c.onResponse(e))})(l,u))),u}function API(e="untitled",t=!1){const{isQX:s,isLoon:i,isSurge:n,isNode:o,isJSBox:r,isScriptable:u}=ENV();return new class{constructor(e,t){this.name=e,this.debug=t,this.http=HTTP(),this.env=ENV(),this.node=(()=>{if(o){return{fs:require("fs")}}return null})(),this.initCache();Promise.prototype.delay=function(e){return this.then(function(t){return((e,t)=>new Promise(function(s){setTimeout(s.bind(null,t),e)}))(e,t)})}}initCache(){if(s&&(this.cache=JSON.parse($prefs.valueForKey(this.name)||"{}")),(i||n)&&(this.cache=JSON.parse($persistentStore.read(this.name)||"{}")),o){let e="root.json";this.node.fs.existsSync(e)||this.node.fs.writeFileSync(e,JSON.stringify({}),{flag:"wx"},e=>console.log(e)),this.root={},e=`${this.name}.json`,this.node.fs.existsSync(e)?this.cache=JSON.parse(this.node.fs.readFileSync(`${this.name}.json`)):(this.node.fs.writeFileSync(e,JSON.stringify({}),{flag:"wx"},e=>console.log(e)),this.cache={})}}persistCache(){const e=JSON.stringify(this.cache,null,2);s&&$prefs.setValueForKey(e,this.name),(i||n)&&$persistentStore.write(e,this.name),o&&(this.node.fs.writeFileSync(`${this.name}.json`,e,{flag:"w"},e=>console.log(e)),this.node.fs.writeFileSync("root.json",JSON.stringify(this.root,null,2),{flag:"w"},e=>console.log(e)))}write(e,t){if(this.log(`SET ${t}`),-1!==t.indexOf("#")){if(t=t.substr(1),n||i)return $persistentStore.write(e,t);if(s)return $prefs.setValueForKey(e,t);o&&(this.root[t]=e)}else this.cache[t]=e;this.persistCache()}read(e){return this.log(`READ ${e}`),-1===e.indexOf("#")?this.cache[e]:(e=e.substr(1),n||i?$persistentStore.read(e):s?$prefs.valueForKey(e):o?this.root[e]:void 0)}delete(e){if(this.log(`DELETE ${e}`),-1!==e.indexOf("#")){if(e=e.substr(1),n||i)return $persistentStore.write(null,e);if(s)return $prefs.removeValueForKey(e);o&&delete this.root[e]}else delete this.cache[e];this.persistCache()}notify(e,t="",l="",h={}){const a=h["open-url"],c=h["media-url"];if(s&&$notify(e,t,l,h),n&&$notification.post(e,t,l+`${c?"\n多媒体:"+c:""}`,{url:a}),i){let s={};a&&(s.openUrl=a),c&&(s.mediaUrl=c),"{}"===JSON.stringify(s)?$notification.post(e,t,l):$notification.post(e,t,l,s)}if(o||u){const s=l+(a?`\n点击跳转: ${a}`:"")+(c?`\n多媒体: ${c}`:"");if(r){require("push").schedule({title:e,body:(t?t+"\n":"")+s})}else console.log(`${e}\n${t}\n${s}\n\n`)}}log(e){this.debug&&console.log(`[${this.name}] LOG: ${this.stringify(e)}`)}info(e){console.log(`[${this.name}] INFO: ${this.stringify(e)}`)}error(e){console.log(`[${this.name}] ERROR: ${this.stringify(e)}`)}wait(e){return new Promise(t=>setTimeout(t,e))}done(e={}){s||i||n?$done(e):o&&!r&&"undefined"!=typeof $context&&($context.headers=e.headers,$context.statusCode=e.statusCode,$context.body=e.body)}stringify(e){if("string"==typeof e||e instanceof String)return e;try{return JSON.stringify(e,null,2)}catch(e){return"[object Object]"}}}(e,t)}
|
||||
+92
-55
@@ -8,34 +8,35 @@
|
||||
<v-btn icon @click="openGist()">
|
||||
<v-icon>visibility</v-icon>
|
||||
</v-btn>
|
||||
<v-dialog max-width="400px" v-model="addArtifactDialog">
|
||||
<v-dialog v-model="showArtifactDialog" max-width="400px">
|
||||
<template #activator="{on}">
|
||||
<v-btn icon v-on="on">
|
||||
<v-btn v-on="on" icon>
|
||||
<v-icon color="primary">mdi-plus-circle</v-icon>
|
||||
</v-btn>
|
||||
</template>
|
||||
<v-card class="pl-4 pr-4 pb-4 pt-4">
|
||||
<v-subheader>
|
||||
<v-icon left>mdi-plus-circle</v-icon>
|
||||
<h3>添加同步配置</h3>
|
||||
<v-icon left>{{ editing ? 'edit_off' : 'mdi-plus-circle' }}</v-icon>
|
||||
<h3>{{ editing ? '修改' : '添加' }}同步配置</h3>
|
||||
</v-subheader>
|
||||
<v-divider></v-divider>
|
||||
<v-form class="pt-4 pl-4 pr-4 pb-0" v-model="formValid">
|
||||
<v-form v-model="formValid" class="pt-4 pl-4 pr-4 pb-0">
|
||||
<v-text-field
|
||||
v-model="newArtifact.name"
|
||||
v-model="currentArtifact.name"
|
||||
:disabled="editing"
|
||||
:rules="validations.nameRules"
|
||||
clear-icon="clear"
|
||||
clearable
|
||||
label="配置名称"
|
||||
placeholder="填入生成配置名称,名称需唯一,如Clash.yaml。"
|
||||
:rules="validations.nameRules"
|
||||
clearable
|
||||
clear-icon="clear"
|
||||
/>
|
||||
<v-menu offset-y>
|
||||
<template v-slot:activator="{on}">
|
||||
<v-text-field
|
||||
label="类型"
|
||||
v-on="on"
|
||||
:rules="validations.required"
|
||||
:value="getType(newArtifact.type)"
|
||||
:value="getType(currentArtifact.type)"
|
||||
label="类型"
|
||||
/>
|
||||
</template>
|
||||
<v-list dense>
|
||||
@@ -56,22 +57,22 @@
|
||||
<v-menu offset-y>
|
||||
<template v-slot:activator="{on}">
|
||||
<v-text-field
|
||||
v-model="newArtifact.source"
|
||||
label="来源"
|
||||
:rules="validations.required"
|
||||
:placeholder="`填入${getType(newArtifact.type) || '来源'}的名称。`"
|
||||
v-model="currentArtifact.source"
|
||||
v-on="on"
|
||||
:placeholder="`填入${getType(currentArtifact.type) || '来源'}的名称。`"
|
||||
:rules="validations.required"
|
||||
label="来源"
|
||||
/>
|
||||
</template>
|
||||
<v-list dense>
|
||||
<v-list-item
|
||||
v-for="(sub, idx) in getSources(newArtifact.type)"
|
||||
@click="newArtifact.source = sub.name"
|
||||
v-for="(sub, idx) in getSources(currentArtifact.type)"
|
||||
:key="idx"
|
||||
@click="currentArtifact.source = sub.name"
|
||||
>
|
||||
<v-list-item-avatar>
|
||||
<v-icon v-if="!sub.icon" color="teal darken-1">mdi-cloud</v-icon>
|
||||
<v-img :src="sub.icon" v-else :class="getIconClass(sub.icon)"/>
|
||||
<v-img v-else :class="getIconClass(sub.icon)" :src="sub.icon"/>
|
||||
</v-list-item-avatar>
|
||||
<v-list-item-title>{{ sub.name }}</v-list-item-title>
|
||||
</v-list-item>
|
||||
@@ -81,20 +82,20 @@
|
||||
<v-menu offset-y>
|
||||
<template v-slot:activator="{on}">
|
||||
<v-text-field
|
||||
label="目标"
|
||||
v-on="on"
|
||||
:rules="validations.required"
|
||||
:value="newArtifact.platform"
|
||||
:value="currentArtifact.platform"
|
||||
label="目标"
|
||||
/>
|
||||
</template>
|
||||
<v-list dense>
|
||||
<v-list-item
|
||||
v-for="platform in ['Surge', 'Loon', 'QX', 'Clash']"
|
||||
:key="platform"
|
||||
@click="newArtifact.platform = platform"
|
||||
@click="currentArtifact.platform = platform"
|
||||
>
|
||||
<v-list-item-avatar>
|
||||
<v-img :src="getIcon(platform)" :class="getIconClass('#invert')"></v-img>
|
||||
<v-img :class="getIconClass('#invert')" :src="getIcon(platform)"></v-img>
|
||||
</v-list-item-avatar>
|
||||
<v-list-item-title>{{ platform }}</v-list-item-title>
|
||||
</v-list-item>
|
||||
@@ -104,10 +105,10 @@
|
||||
<v-divider></v-divider>
|
||||
<v-card-actions>
|
||||
<v-spacer></v-spacer>
|
||||
<v-btn color="primary" text small :disabled="!formValid" @click="createArtifact()">
|
||||
<v-btn :disabled="!formValid" color="primary" small text @click="doneEditArtifact()">
|
||||
确认
|
||||
</v-btn>
|
||||
<v-btn text small @click="clear()">
|
||||
<v-btn small text @click="clear()">
|
||||
取消
|
||||
</v-btn>
|
||||
</v-card-actions>
|
||||
@@ -116,9 +117,9 @@
|
||||
</v-card-title>
|
||||
|
||||
<template v-for="(artifact, idx) in artifacts">
|
||||
<v-list-item three-line dense :key="artifact.name">
|
||||
<v-list-item :key="artifact.name" dense three-line>
|
||||
<v-list-item-avatar>
|
||||
<v-img :src="getIcon(artifact.platform)" :class="getIconClass('#invert')"/>
|
||||
<v-img :class="getIconClass('#invert')" :src="getIcon(artifact.platform)"/>
|
||||
</v-list-item-avatar>
|
||||
<v-list-item-content>
|
||||
<v-list-item-title>
|
||||
@@ -137,27 +138,39 @@
|
||||
<v-list-item-subtitle>更新于:{{ getUpdatedTime(artifact.updated) }}</v-list-item-subtitle>
|
||||
</v-list-item-content>
|
||||
<v-list-item-action>
|
||||
<v-menu bottom left>
|
||||
<template #activator="{ on }">
|
||||
<v-btn icon v-on="on">
|
||||
<v-icon>mdi-dots-vertical</v-icon>
|
||||
<v-row>
|
||||
<v-col>
|
||||
<v-btn icon @click="toggleSync(artifact)">
|
||||
<v-icon :color="artifact.sync ? undefined: 'red'">{{ artifact.sync ? "alarm" : "alarm_off" }}</v-icon>
|
||||
</v-btn>
|
||||
</template>
|
||||
<v-list dense>
|
||||
<v-list-item @click="copy(artifact.url)" v-if="artifact.url">
|
||||
<v-list-item-title>复制</v-list-item-title>
|
||||
</v-list-item>
|
||||
<v-list-item @click="preview(artifact.name)">
|
||||
<v-list-item-title>预览</v-list-item-title>
|
||||
</v-list-item>
|
||||
<v-list-item @click="sync(artifact.name)">
|
||||
<v-list-item-title>同步</v-list-item-title>
|
||||
</v-list-item>
|
||||
<v-list-item @click="deleteArtifact(idx, artifact.name)">
|
||||
<v-list-item-title>删除</v-list-item-title>
|
||||
</v-list-item>
|
||||
</v-list>
|
||||
</v-menu>
|
||||
</v-col>
|
||||
<v-col>
|
||||
<v-menu bottom left>
|
||||
<template #activator="{ on }">
|
||||
<v-btn v-on="on" icon>
|
||||
<v-icon>mdi-dots-vertical</v-icon>
|
||||
</v-btn>
|
||||
</template>
|
||||
<v-list dense>
|
||||
<v-list-item v-if="artifact.url" @click="copy(artifact.url)">
|
||||
<v-list-item-title>复制</v-list-item-title>
|
||||
</v-list-item>
|
||||
<v-list-item @click="editArtifact(artifact)">
|
||||
<v-list-item-title>编辑</v-list-item-title>
|
||||
</v-list-item>
|
||||
<v-list-item @click="preview(artifact.name)">
|
||||
<v-list-item-title>预览</v-list-item-title>
|
||||
</v-list-item>
|
||||
<v-list-item @click="sync(artifact.name)">
|
||||
<v-list-item-title>同步</v-list-item-title>
|
||||
</v-list-item>
|
||||
<v-list-item @click="deleteArtifact(idx, artifact.name)">
|
||||
<v-list-item-title>删除</v-list-item-title>
|
||||
</v-list-item>
|
||||
</v-list>
|
||||
</v-menu>
|
||||
</v-col>
|
||||
</v-row>
|
||||
</v-list-item-action>
|
||||
</v-list-item>
|
||||
</template>
|
||||
@@ -174,13 +187,14 @@ export default {
|
||||
name: "Cloud",
|
||||
data() {
|
||||
return {
|
||||
addArtifactDialog: false,
|
||||
newArtifact: {
|
||||
showArtifactDialog: false,
|
||||
currentArtifact: {
|
||||
name: "",
|
||||
type: "subscription",
|
||||
source: "",
|
||||
platform: "",
|
||||
},
|
||||
editing: null,
|
||||
formValid: false,
|
||||
validations: {
|
||||
nameRules: [
|
||||
@@ -230,13 +244,35 @@ export default {
|
||||
}
|
||||
},
|
||||
|
||||
async createArtifact() {
|
||||
async doneEditArtifact() {
|
||||
console.log(JSON.stringify(this.currentArtifact, null, 2));
|
||||
try {
|
||||
await axios.post("/artifacts", this.newArtifact);
|
||||
if (this.editing) {
|
||||
await axios.patch(`/artifact/${this.currentArtifact.name}`, this.currentArtifact);
|
||||
} else {
|
||||
await axios.post("/artifacts", this.currentArtifact);
|
||||
}
|
||||
await this.$store.dispatch("FETCH_ARTIFACTS");
|
||||
this.clear();
|
||||
} catch (err) {
|
||||
this.$store.commit("SET_ERROR_MESSAGE", `创建配置失败!${err}`);
|
||||
this.$store.commit("SET_ERROR_MESSAGE", `${this.editing ? "更新" : "创建"}配置失败!${err}`);
|
||||
}
|
||||
},
|
||||
|
||||
async editArtifact(artifact) {
|
||||
this.editing = true;
|
||||
Object.assign(this.currentArtifact, artifact);
|
||||
this.showArtifactDialog = true;
|
||||
},
|
||||
|
||||
async toggleSync(artifact) {
|
||||
artifact.sync = !artifact.sync;
|
||||
try {
|
||||
await axios.patch(`/artifact/${artifact.name}`, artifact);
|
||||
await this.$store.dispatch("FETCH_ARTIFACTS");
|
||||
this.$store.commit("SET_SUCCESS_MESSAGE", `已${artifact.sync ? '启用' : '禁用'}自动同步配置${artifact.name}`);
|
||||
} catch (err) {
|
||||
this.$store.commit("SET_ERROR_MESSAGE", `更改同步配置失败!${err}`);
|
||||
}
|
||||
},
|
||||
|
||||
@@ -250,13 +286,14 @@ export default {
|
||||
},
|
||||
|
||||
clear() {
|
||||
this.newArtifact = {
|
||||
this.currentArtifact = {
|
||||
name: "",
|
||||
type: "subscription",
|
||||
source: "",
|
||||
platform: ""
|
||||
}
|
||||
this.addArtifactDialog = false;
|
||||
this.showArtifactDialog = false;
|
||||
this.editing = false;
|
||||
},
|
||||
|
||||
copy(url) {
|
||||
@@ -282,8 +319,8 @@ export default {
|
||||
},
|
||||
|
||||
setArtifactType(type) {
|
||||
this.newArtifact.type = type;
|
||||
this.newArtifact.source = "";
|
||||
this.currentArtifact.type = type;
|
||||
this.currentArtifact.source = "";
|
||||
},
|
||||
|
||||
getSources(type) {
|
||||
|
||||
Reference in new issue
Block a user