适配QX TF 390+特性

This commit is contained in:
Peng-YM 2020-10-04 10:37:04 +08:00
parent 77ec9c6953
commit ea7f208882
6 changed files with 51 additions and 6 deletions

View File

@ -94,6 +94,18 @@ $app.route("/api/storage")
.get(exportData) .get(exportData)
.post(importData); .post(importData);
$app.get("/api/env", async (req, res) => {
const {isNode, isQX, isLoon, isSurge} = ENV();
let backend = "Node";
if (isNode) backend = "Node";
if (isQX) backend = "QX";
if (isLoon) backend = "Loon";
if (isSurge) backend = "Surge";
res.json({
backend
});
});
$app.all("/", async (req, res) => { $app.all("/", async (req, res) => {
res.send("Hello from Sub-Store! Made with ❤️ by Peng-YM."); res.send("Hello from Sub-Store! Made with ❤️ by Peng-YM.");
}); });

File diff suppressed because one or more lines are too long

11
config/QX.conf Normal file
View File

@ -0,0 +1,11 @@
# QX TF最新版本(build 390+)配置,请复制到配置的指定位置使用
[rewrite_local]
^https?:\/\/sub\.store url script-analyze-echo-response https://raw.githubusercontent.com/Peng-YM/Sub-Store/master/backend/sub-store.min.js
[mitm]
# 添加一个sub.store域名
hostname=sub.store
simple_cert_hostname=sub.store
[http_backend]
https://raw.githubusercontent.com/Peng-YM/Sub-Store/master/backend/sub-store.min.js, tag=Sub-Store, path=/, enabled=true, img-url=https://raw.githubusercontent.com/58xinian/icon/master/Sub-Store1.png

View File

@ -40,6 +40,9 @@ function initStore(store) {
store.dispatch("FETCH_COLLECTIONS").catch(() => { store.dispatch("FETCH_COLLECTIONS").catch(() => {
showError(`无法拉取组合订阅列表!`); showError(`无法拉取组合订阅列表!`);
}); });
store.dispatch("FETCH_ENV").catch(() => {
showError(`无法获取当前运行环境!`);
});
} }
export default { export default {

View File

@ -15,13 +15,14 @@ const store = new Vuex.Store({
subscriptions: {}, subscriptions: {},
collections: {}, collections: {},
env: {},
settings: {} settings: {}
}, },
mutations: { mutations: {
COPY(state, text) { COPY(state, text) {
state.clipboard = text; state.clipboard = text;
}, },
// UI // UI
SET_NAV_TITLE(state, title) { SET_NAV_TITLE(state, title) {
@ -56,6 +57,12 @@ const store = new Vuex.Store({
state.collections = data; state.collections = data;
}); });
}, },
// fetch env
async FETCH_ENV({state}) {
return axios.get("/env").then(resp => {
state.env = resp.data;
})
},
// update subscriptions // update subscriptions
async UPDATE_SUBSCRIPTION({dispatch}, {name, sub}) { async UPDATE_SUBSCRIPTION({dispatch}, {name, sub}) {
return axios.patch(`/sub/${name}`, sub).then(() => { return axios.patch(`/sub/${name}`, sub).then(() => {

View File

@ -184,11 +184,23 @@ export default {
}, },
computed: { computed: {
subscriptions: function () { subscriptionBaseURL() {
const backend = this.$store.state.env.backend;
switch (backend) {
case "QX":
return "http://127.0.0.1:9999";
case "Node":
case "Surge":
case "Loon":
default:
return BACKEND_BASE;
}
},
subscriptions() {
const subs = this.$store.state.subscriptions; const subs = this.$store.state.subscriptions;
return Object.keys(subs).map(k => subs[k]); return Object.keys(subs).map(k => subs[k]);
}, },
collections: function () { collections() {
const cols = this.$store.state.collections; const cols = this.$store.state.collections;
return Object.keys(cols).map(k => cols[k]); return Object.keys(cols).map(k => cols[k]);
} }
@ -199,7 +211,7 @@ export default {
console.log(`${action} --> ${sub.name}`); console.log(`${action} --> ${sub.name}`);
switch (action) { switch (action) {
case 'COPY': case 'COPY':
this.$clipboard(`${BACKEND_BASE}/download/${sub.name}`); this.$clipboard(`${this.subscriptionBaseURL}/download/${sub.name}`);
this.$store.commit("SET_SUCCESS_MESSAGE", "成功复制订阅链接"); this.$store.commit("SET_SUCCESS_MESSAGE", "成功复制订阅链接");
break break
case 'EDIT': case 'EDIT':
@ -214,7 +226,7 @@ export default {
console.log(`${action} --> ${collection.name}`); console.log(`${action} --> ${collection.name}`);
switch (action) { switch (action) {
case 'COPY': case 'COPY':
this.$clipboard(`${BACKEND_BASE}/download/collection/${collection.name}`); this.$clipboard(`${this.subscriptionBaseURL}/download/collection/${collection.name}`);
this.$store.commit("SET_SUCCESS_MESSAGE", "成功复制订阅链接"); this.$store.commit("SET_SUCCESS_MESSAGE", "成功复制订阅链接");
break break
case 'EDIT': case 'EDIT':