Added support for non-ascii characters in subscriptions, collections and artifacts

This commit is contained in:
Peng-YM
2022-05-30 13:47:54 +08:00
parent 4dbafb77c5
commit e28e440dc5
9 changed files with 80 additions and 106 deletions

View File

@@ -48,7 +48,7 @@ const router = new Router({
name: "collection-edit",
component: SubEditor,
props: {isCollection: true},
meta: {title: "订阅编辑"}
meta: {title: "组合订阅编辑"}
}
]
});

View File

@@ -27,7 +27,6 @@
<v-text-field
v-model="currentArtifact.name"
:disabled="editing"
:rules="validations.nameRules"
clear-icon="clear"
clearable
label="配置名称"
@@ -155,7 +154,7 @@
</v-btn>
</template>
<v-list dense>
<v-list-item v-if="artifact.url" @click="copy(artifact.url)">
<v-list-item v-if="artifact.url" @click="copy(artifact)">
<v-list-item-title>复制</v-list-item-title>
</v-list-item>
<v-list-item @click="editArtifact(artifact)">
@@ -200,10 +199,6 @@ export default {
editing: null,
formValid: false,
validations: {
nameRules: [
v => !!v || "订阅名称不能为空!",
v => /^[\w-_.]*$/.test(v) || "订阅名称只能包含英文字符、横杠、点和下划线!"
],
required: [
v => !!v || "不能为空!"
]
@@ -299,9 +294,11 @@ export default {
this.editing = false;
},
copy(url) {
this.$clipboard(url);
this.$store.commit("SET_SUCCESS_MESSAGE", "成功复制配置链接");
copy(artifact) {
if (artifact.url) {
this.$clipboard(artifact.url + (isPlainName(artifact.name) ? '' : `#${artifact.name}`));
this.$store.commit("SET_SUCCESS_MESSAGE", "成功复制配置链接");
}
},
preview(name) {
@@ -360,6 +357,10 @@ export default {
}
}
}
function isPlainName(name) {
return /^[\w-_]*$/.test(name);
}
</script>
<style scoped>

View File

@@ -3,7 +3,7 @@
<v-card class="mb-4">
<v-subheader>订阅配置</v-subheader>
<v-form v-model="formState.basicValid" class="pl-4 pr-4 pb-0">
<v-text-field v-model="options.name" :rules="validations.nameRules" class="mt-2" clear-icon="clear" clearable
<v-text-field v-model="options.name" class="mt-2" clear-icon="clear" clearable
label="订阅名称" placeholder="填入订阅名称,名称需唯一" required />
<!--For Subscription-->
<v-radio-group v-if="!isCollection" v-model="options.source" class="mt-0 mb-0">
@@ -20,7 +20,7 @@
<v-col></v-col>
</v-row>
</v-radio-group>
<v-textarea v-if="options.source !== 'local'" v-model="options.url" :rules="validations.urlRules" auto-grow
<v-textarea v-if="!isCollection && options.source !== 'local'" v-model="options.url" :rules="validations.urlRules" auto-grow
class="mt-0" clear-icon="clear" clearable label="订阅链接" placeholder="填入机场原始订阅链接" required rows="2" />
<v-textarea v-if="options.source === 'local'" v-model="options.content" clear-icon="clear" clearable
label="订阅内容" placeholder="填入原始订阅内容" autogrow rows="5" row-height="15" class="mt-0">
@@ -300,10 +300,6 @@ export default {
imported: "",
dialog: false,
validations: {
nameRules: [
v => !!v || "订阅名称不能为空!",
v => /^[\w-_]*$/.test(v) || "订阅名称只能包含英文字符、横杠和下划线!"
],
urlRules: [
v => this.options.source === 'remote' && (!!v || "订阅链接不能为空!"),
v => this.options.source === 'remote' && (/^https?:\/\//.test(v) || "订阅链接不合法!")
@@ -335,7 +331,7 @@ export default {
},
created() {
const name = this.$route.params.name;
const name = decodeURIComponent(this.$route.params.name);
let source;
if (this.isCollection) {
source = (typeof name === 'undefined' || name === 'UNTITLED') ? {} : this.$store.state.collections[name];

View File

@@ -195,19 +195,7 @@ export default {
{
title: "删除",
action: "DELETE"
},
// {
// title: "副本",
// action: "DUPLICATE"
// }
// {
// title: "上移",
// action: "MOVE_UP"
// },
// {
// title: "下移",
// action: "MOVE_DOWN"
// }
}
]
}
},
@@ -236,27 +224,22 @@ export default {
console.log(`${action} --> ${sub.name}`);
switch (action) {
case 'COPY':
this.$clipboard(`${this.subscriptionBaseURL}/download/${sub.name}`);
this.$clipboard(`${this.subscriptionBaseURL}/download/${encodeURIComponent(sub.name)}${isPlainName(sub.name) ? '' : '#' + sub.name}`);
this.$store.commit("SET_SUCCESS_MESSAGE", "成功复制订阅链接");
break
case 'EDIT':
this.$router.push(`/sub-edit/${sub.name}`);
this.$router.push(`/sub-edit/${encodeURIComponent(sub.name)}`);
break
case 'DELETE':
this.$store.dispatch("DELETE_SUBSCRIPTION", sub.name);
break
case 'MOVE_UP':
this.moveUpSubscription(sub.name);
break
case 'MOVE_DOWN':
break
}
},
collectionMenu(action, collection) {
console.log(`${action} --> ${collection.name}`);
switch (action) {
case 'COPY':
this.$clipboard(`${this.subscriptionBaseURL}/download/collection/${collection.name}`);
this.$clipboard(`${this.subscriptionBaseURL}/download/collection/${encodeURIComponent(collection.name)}${isPlainName(collection.name) ? '' : '#' + collection.name}`);
this.$store.commit("SET_SUCCESS_MESSAGE", "成功复制订阅链接");
break
case 'EDIT':
@@ -269,10 +252,10 @@ export default {
},
preview(item, type = 'sub') {
if (type === 'sub') {
this.url = `${BACKEND_BASE}/download/${item.name}`;
this.url = `${BACKEND_BASE}/download/${encodeURIComponent(item.name)}`;
this.sub = item.url;
} else {
this.url = `${BACKEND_BASE}/download/collection/${item.name}`
this.url = `${BACKEND_BASE}/download/collection/${encodeURIComponent(item.name)}`
}
this.showProxyList = true;
},
@@ -295,6 +278,10 @@ export default {
}
}
}
function isPlainName(name) {
return /^[\w-_]*$/.test(name);
}
</script>
<style scoped>