From f00bb12941da8a78293f50a00d9ef849f850a2a6 Mon Sep 17 00:00:00 2001 From: MarSeventh <1193267292@qq.com> Date: Wed, 4 Dec 2024 23:25:54 +0800 Subject: [PATCH] =?UTF-8?q?TG=E6=B8=A0=E9=81=93=E8=AE=B0=E5=BD=95=E6=9B=B4?= =?UTF-8?q?=E8=AF=A6=E7=BB=86=EF=BC=9B=E6=94=AF=E6=8C=81=E8=87=AA=E5=AE=9A?= =?UTF-8?q?=E4=B9=89=E5=91=BD=E5=90=8D=EF=BC=9B=E6=94=AF=E6=8C=81=E8=87=AA?= =?UTF-8?q?=E5=AE=9A=E4=B9=89=E9=93=BE=E6=8E=A5=E5=89=8D=E7=BC=80=EF=BC=9B?= =?UTF-8?q?R2=E6=B8=A0=E9=81=93=E5=88=A0=E9=99=A4=E6=97=B6=EF=BC=8C?= =?UTF-8?q?=E5=AD=98=E5=82=A8=E6=A1=B6=E5=90=8C=E6=AD=A5=E5=88=A0=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/UploadForm.vue | 67 +++++++++++++++++++++++++++++++---- src/store/index.js | 13 +++++++ src/views/UploadHome.vue | 55 +++++++++++++++++++++++++--- 3 files changed, 124 insertions(+), 11 deletions(-) diff --git a/src/components/UploadForm.vue b/src/components/UploadForm.vue index 716cba0..27de4de 100644 --- a/src/components/UploadForm.vue +++ b/src/components/UploadForm.vue @@ -157,6 +157,21 @@ props: { type: String, default: 'telegram', required: false + }, + uploadNameType: { + type: String, + default: 'default', + required: false + }, + useCustomUrl: { + type: String, + default: 'false', + required: false + }, + customUrlPrefix: { + type: String, + default: '', + required: false } }, data() { @@ -185,6 +200,40 @@ watch: { this.fileListLength = this.fileList.length }, deep: true + }, + useCustomUrl: { + handler() { + if (this.useCustomUrl === 'true') { + this.fileList.forEach(item => { + item.finalURL = this.customUrlPrefix + item.srcID + item.mdURL = `![${item.name}](${this.customUrlPrefix + item.srcID})` + item.htmlURL = `` + item.ubbURL = `[img]${this.customUrlPrefix + item.srcID}[/img]` + }) + } else { + const rootUrl = `${window.location.protocol}//${window.location.host}/file/` + this.fileList.forEach(item => { + item.finalURL = rootUrl + item.srcID + item.mdURL = `![${item.name}](${rootUrl + item.srcID})` + item.htmlURL = `` + item.ubbURL = `[img]${rootUrl + item.srcID}[/img]` + }) + } + }, + immediate: true + }, + customUrlPrefix: { + handler() { + if (this.useCustomUrl === 'true') { + this.fileList.forEach(item => { + item.finalURL = this.customUrlPrefix + item.srcID + item.mdURL = `![${item.name}](${this.customUrlPrefix + item.srcID})` + item.htmlURL = `` + item.ubbURL = `[img]${this.customUrlPrefix + item.srcID}[/img]` + }) + } + }, + immediate: true } }, computed: { @@ -232,7 +281,7 @@ methods: { // 判断是否需要服务端压缩 const needServerCompress = this.fileList.find(item => item.uid === file.file.uid).serverCompress axios({ - url: '/upload' + '?authCode=' + cookies.get('authCode') + '&serverCompress=' + needServerCompress + '&uploadChannel=' + this.uploadChannel, + url: '/upload' + '?authCode=' + cookies.get('authCode') + '&serverCompress=' + needServerCompress + '&uploadChannel=' + this.uploadChannel + '&uploadNameType=' + this.uploadNameType, method: 'post', data: formData, onUploadProgress: (progressEvent) => { @@ -266,12 +315,15 @@ methods: { }, handleSuccess(response, file) { try { - const rootUrl = `${window.location.protocol}//${window.location.host}` - this.fileList.find(item => item.uid === file.uid).url = rootUrl + response.data[0].src - this.fileList.find(item => item.uid === file.uid).finalURL = rootUrl + response.data[0].src - this.fileList.find(item => item.uid === file.uid).mdURL = `![${file.name}](${rootUrl + response.data[0].src})` - this.fileList.find(item => item.uid === file.uid).htmlURL = `` - this.fileList.find(item => item.uid === file.uid).ubbURL = `[img]${rootUrl + response.data[0].src}[/img]` + const rootUrl = this.useCustomUrl === 'true'? this.customUrlPrefix : `${window.location.protocol}//${window.location.host}/file/` + // 从response.data[0].src中去除/file/前缀 + const srcID = response.data[0].src.replace('/file/', '') + this.fileList.find(item => item.uid === file.uid).url = `${window.location.protocol}//${window.location.host}/file/` + srcID + this.fileList.find(item => item.uid === file.uid).finalURL = rootUrl + srcID + this.fileList.find(item => item.uid === file.uid).mdURL = `![${file.name}](${rootUrl + srcID})` + this.fileList.find(item => item.uid === file.uid).htmlURL = `` + this.fileList.find(item => item.uid === file.uid).ubbURL = `[img]${rootUrl + srcID}[/img]` + this.fileList.find(item => item.uid === file.uid).srcID = srcID this.fileList.find(item => item.uid === file.uid).progreess = 100 this.fileList.find(item => item.uid === file.uid).status = 'success' this.$message({ @@ -346,6 +398,7 @@ methods: { mdURL: '', htmlURL: '', ubbURL: '', + srcID: '', status: 'uploading', progreess: 0, serverCompress: serverCompress diff --git a/src/store/index.js b/src/store/index.js index fc28339..4e376e8 100644 --- a/src/store/index.js +++ b/src/store/index.js @@ -14,6 +14,11 @@ export default createStore({ serverCompress: true, }, storeUploadChannel: 'telegram', + storeUploadNameType: 'default', + customUrlSettings: { + useCustomUrl: 'false', + customUrlPrefix: '', + } }, getters: { userConfig: state => state.userConfig, @@ -22,6 +27,8 @@ export default createStore({ uploadCopyUrlForm: state => state.uploadCopyUrlForm, compressConfig: state => state.compressConfig, storeUploadChannel: state => state.storeUploadChannel, + storeUploadNameType: state => state.storeUploadNameType, + customUrlSettings: state => state.customUrlSettings, }, mutations: { setUserConfig(state, userConfig) { @@ -42,6 +49,12 @@ export default createStore({ setStoreUploadChannel(state, uploadChannel) { state.storeUploadChannel = uploadChannel; }, + setStoreUploadNameType(state, storeUploadNameType) { + state.storeUploadNameType = storeUploadNameType; + }, + setCustomUrlSettings(state, { key, value }) { + state.customUrlSettings[key] = value; + } }, actions: { async fetchUserConfig({ commit }) { diff --git a/src/views/UploadHome.vue b/src/views/UploadHome.vue index 6fa9ae6..d86d196 100644 --- a/src/views/UploadHome.vue +++ b/src/views/UploadHome.vue @@ -38,15 +38,34 @@ :compressBar="compressBar" :serverCompress="serverCompress" :uploadChannel="uploadChannel" + :uploadNameType="uploadNameType" + :useCustomUrl="useCustomUrl" + :customUrlPrefix="customUrlPrefix" class="upload" /> - + + 默认复制链接 原始链接 MarkDown HTML BBCode + 自定义链接格式 + + + + 是 + 否 + + + + + + + *Tips: 默认链接为https://your.domain/file/xxx.jpg,如果启用自定义链接格式,只保留xxx.jpg部分,其他部分请自行输入 + + 确定 @@ -54,12 +73,20 @@ 上传渠道 - + Telegram Cloudflare R2 + 文件命名方式 + + + 默认 + 仅前缀 + 仅原名 + + 客户端压缩
默认复制链接
自定义链接格式
+ *Tips: 默认链接为https://your.domain/file/xxx.jpg,如果启用自定义链接格式,只保留xxx.jpg部分,其他部分请自行输入 +
上传渠道
文件命名方式
客户端压缩