diff --git a/src/views/Subconverter.vue b/src/views/Subconverter.vue index e221116..b94a90b 100644 --- a/src/views/Subconverter.vue +++ b/src/views/Subconverter.vue @@ -29,7 +29,7 @@ 前往项目仓库 @@ -107,33 +107,75 @@ - 生成订阅链接 + 生成订阅链接 生成短链接 + + 一键导入Clash + @click="dialogUploadConfigVisible = true" + icon="el-icon-upload" + :loading="loading" + >上传配置 一键导入Surge + :disabled="customSubUrl.length === 0" + >一键导入Clash + + + + + + + + + + + + @@ -143,6 +185,7 @@ const remoteConfigSample = const gayhubRelease = "https://github.com/tindy2013/subconverter/releases"; const defaultBackend = "https://api.wcc.best/sub?"; const shortUrlBackend = ""; +const configUploadBackend = "https://api.wcc.best/config/upload" export default { data() { @@ -234,7 +277,11 @@ export default { }, loading: false, - customSubUrl: "" + customSubUrl: "", + + dialogUploadConfigVisible: false, + uploadConfig: "", + uploadPassword: "" }; }, created() { @@ -330,7 +377,7 @@ export default { } this.$copyText(this.customSubUrl); - this.$message.success("定制订阅已复制到剪切板"); + this.$message.success("定制订阅已复制到剪贴板"); }, makeShortUrl() { if (shortUrlBackend === "") { @@ -352,7 +399,7 @@ export default { .then(res => { if (res.data.Code === 1 && res.data.ShortUrl !== "") { this.$copyText(res.data.ShortUrl); - this.$message.success("短链接已复制到剪切板"); + this.$message.success("短链接已复制到剪贴板"); } else { this.$message.error("短链接获取失败:" + res.data.Message); } @@ -376,6 +423,46 @@ export default { "各种订阅链接(短链接服务除外)生成纯前端实现,无隐私问题。默认提供后端转换服务,隐私担忧者请自行搭建后端服务。" ) }); + }, + confirmUploadConfig() { + if (this.uploadConfig === "") { + this.$message.warning("远程配置不能为空"); + return false; + } + + this.loading = true; + + let data = new FormData(); + data.append("password", this.uploadPassword); + data.append("config", this.uploadConfig); + + this.$axios + .post(configUploadBackend, data, { + header: { + "Content-Type": "application/form-data; charset=utf-8" + } + }) + .then(res => { + if (res.data.Code === 1 && res.data.url !== "") { + this.$message.success( + "远程配置上传成功,配置链接已复制到剪贴板,有效期三个月望知悉" + ); + + // 自动填充至『表单-远程配置』 + this.form.remoteConfig = res.data.Url; + this.$copyText(this.form.remoteConfig); + + this.dialogUploadConfigVisible = false; + } else { + this.$message.error("远程配置上传失败:" + res.data.Message); + } + }) + .catch(() => { + this.$message.error("远程配置上传失败"); + }) + .finally(() => { + this.loading = false; + }); } } };