Skip to content

Commit

Permalink
后端支持上传失败时自动切换其他渠道重试
Browse files Browse the repository at this point in the history
  • Loading branch information
MarSeventh committed Dec 12, 2024
1 parent 940ab3f commit 9d5a2cd
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 4 deletions.
7 changes: 6 additions & 1 deletion src/components/UploadForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,11 @@ props: {
type: String,
default: '',
required: false
},
autoRetry: {
type: Boolean,
default: true,
required: false
}
},
data() {
Expand Down Expand Up @@ -280,7 +285,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 + '&uploadNameType=' + this.uploadNameType,
url: '/upload' + '?authCode=' + cookies.get('authCode') + '&serverCompress=' + needServerCompress + '&uploadChannel=' + this.uploadChannel + '&uploadNameType=' + this.uploadNameType + '&autoRetry=' + this.autoRetry,
method: 'post',
data: formData,
onUploadProgress: (progressEvent) => {
Expand Down
7 changes: 6 additions & 1 deletion src/store/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export default createStore({
serverCompress: true,
},
storeUploadChannel: 'telegram',
storeAutoRetry: true,
storeUploadNameType: 'default',
customUrlSettings: {
useCustomUrl: 'false',
Expand All @@ -29,6 +30,7 @@ export default createStore({
storeUploadChannel: state => state.storeUploadChannel,
storeUploadNameType: state => state.storeUploadNameType,
customUrlSettings: state => state.customUrlSettings,
storeAutoRetry: state => state.storeAutoRetry,
},
mutations: {
setUserConfig(state, userConfig) {
Expand All @@ -54,7 +56,10 @@ export default createStore({
},
setCustomUrlSettings(state, { key, value }) {
state.customUrlSettings[key] = value;
}
},
setStoreAutoRetry(state, storeAutoRetry) {
state.storeAutoRetry = storeAutoRetry;
},
},
actions: {
async fetchUserConfig({ commit }) {
Expand Down
20 changes: 18 additions & 2 deletions src/views/UploadHome.vue
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
:uploadNameType="uploadNameType"
:useCustomUrl="useCustomUrl"
:customUrlPrefix="customUrlPrefix"
:autoRetry="autoRetry"
class="upload"
/>
<el-dialog title="链接格式设置" v-model="showUrlDialog" :width="dialogWidth" :show-close="false">
Expand Down Expand Up @@ -79,6 +80,15 @@
<el-radio label="cfr2">Cloudflare R2</el-radio>
</el-radio-group>
</el-form-item>
<el-form-item label="失败自动切换">
<el-switch
v-model="autoRetry"
active-text="开启"
inactive-text="关闭"
active-color="#13ce66"
inactive-color="#ff4949"
/>
</el-form-item>
<p style="font-size: medium; font-weight: bold">文件命名方式</p>
<el-form-item label="命名方式">
<el-radio-group v-model="uploadNameType">
Expand Down Expand Up @@ -156,7 +166,8 @@ export default {
uploadChannel: 'telegram', //上传渠道
uploadNameType: 'default', //上传文件命名方式
customUrlPrefix: '', //自定义链接前缀
useCustomUrl: 'false' //是否启用自定义链接格式
useCustomUrl: 'false', //是否启用自定义链接格式
autoRetry: true //失败自动切换
}
},
watch: {
Expand All @@ -183,10 +194,13 @@ export default {
},
useCustomUrl(val) {
this.$store.commit('setCustomUrlSettings', { key: 'useCustomUrl', value: val })
},
autoRetry(val) {
this.$store.commit('setStoreAutoRetry', val)
}
},
computed: {
...mapGetters(['userConfig', 'bingWallPapers', 'uploadCopyUrlForm', 'compressConfig', 'storeUploadChannel', 'storeUploadNameType', 'customUrlSettings']),
...mapGetters(['userConfig', 'bingWallPapers', 'uploadCopyUrlForm', 'compressConfig', 'storeUploadChannel', 'storeUploadNameType', 'customUrlSettings', 'storeAutoRetry']),
ownerName() {
return this.userConfig?.ownerName || 'Sanyue'
},
Expand Down Expand Up @@ -266,6 +280,8 @@ export default {
this.serverCompress = this.compressConfig.serverCompress
// 读取用户选择的上传渠道
this.uploadChannel = this.storeUploadChannel
// 用户定义的失败自动切换
this.autoRetry = this.storeAutoRetry
// 读取用户选择的上传文件命名方式
this.uploadNameType = this.storeUploadNameType
// 读取用户自定义链接格式
Expand Down

0 comments on commit 9d5a2cd

Please sign in to comment.