Skip to content

Commit

Permalink
TG渠道记录更详细;支持自定义命名;支持自定义链接前缀;R2渠道删除时,存储桶同步删除
Browse files Browse the repository at this point in the history
  • Loading branch information
MarSeventh committed Dec 4, 2024
1 parent 5e132e5 commit f00bb12
Show file tree
Hide file tree
Showing 3 changed files with 124 additions and 11 deletions.
67 changes: 60 additions & 7 deletions src/components/UploadForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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 = `<img src="${this.customUrlPrefix + item.srcID}" alt="${item.name}" width=100% />`
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 = `<img src="${rootUrl + item.srcID}" alt="${item.name}" width=100% />`
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 = `<img src="${this.customUrlPrefix + item.srcID}" alt="${item.name}" width=100% />`
item.ubbURL = `[img]${this.customUrlPrefix + item.srcID}[/img]`
})
}
},
immediate: true
}
},
computed: {
Expand Down Expand Up @@ -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) => {
Expand Down Expand Up @@ -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 = `<img src="${rootUrl + response.data[0].src}" alt="${file.name}" width=100% />`
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 = `<img src="${rootUrl + srcID}" alt="${file.name}" width=100% />`
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({
Expand Down Expand Up @@ -346,6 +398,7 @@ methods: {
mdURL: '',
htmlURL: '',
ubbURL: '',
srcID: '',
status: 'uploading',
progreess: 0,
serverCompress: serverCompress
Expand Down
13 changes: 13 additions & 0 deletions src/store/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ export default createStore({
serverCompress: true,
},
storeUploadChannel: 'telegram',
storeUploadNameType: 'default',
customUrlSettings: {
useCustomUrl: 'false',
customUrlPrefix: '',
}
},
getters: {
userConfig: state => state.userConfig,
Expand All @@ -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) {
Expand All @@ -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 }) {
Expand Down
55 changes: 51 additions & 4 deletions src/views/UploadHome.vue
Original file line number Diff line number Diff line change
Expand Up @@ -38,28 +38,55 @@
:compressBar="compressBar"
:serverCompress="serverCompress"
:uploadChannel="uploadChannel"
:uploadNameType="uploadNameType"
:useCustomUrl="useCustomUrl"
:customUrlPrefix="customUrlPrefix"
class="upload"
/>
<el-dialog title="选择复制链接格式" v-model="showUrlDialog" :width="dialogWidth" :show-close="false">
<el-dialog title="链接格式设置" v-model="showUrlDialog" :width="dialogWidth" :show-close="false">
<p style="font-size: medium; font-weight: bold">默认复制链接</p>
<el-radio-group v-model="selectedUrlForm" @change="changeUrlForm">
<el-radio value="url">原始链接</el-radio>
<el-radio value="md">MarkDown</el-radio>
<el-radio value="html">HTML</el-radio>
<el-radio value="ubb">BBCode</el-radio>
</el-radio-group>
<p style="font-size: medium; font-weight: bold">自定义链接格式</p>
<el-form label-width="25%">
<el-form-item label="启用自定义">
<el-radio-group v-model="useCustomUrl">
<el-radio value="true">是</el-radio>
<el-radio value="false">否</el-radio>
</el-radio-group>
</el-form-item>
<el-form-item label="自定义前缀" v-if="useCustomUrl === 'true'">
<el-input v-model="customUrlPrefix" placeholder="请输入自定义链接前缀"/>
</el-form-item>
<p style="text-align: left;font-size: small;">
<br/>*Tips: 默认链接为https://your.domain/file/xxx.jpg,如果启用自定义链接格式,只保留xxx.jpg部分,其他部分请自行输入
</p>
</el-form>
<div class="dialog-action">
<el-button type="primary" @click="showUrlDialog = false">确定</el-button>
</div>
</el-dialog>
<el-dialog title="上传设置" v-model="showCompressDialog" :width="dialogWidth" :show-close="false">
<el-form label-width="25%">
<p style="font-size: medium; font-weight: bold">上传渠道</p>
<el-form-item label="选择上传渠道">
<el-form-item label="上传渠道">
<el-radio-group v-model="uploadChannel">
<el-radio label="telegram">Telegram</el-radio>
<el-radio label="cfr2">Cloudflare R2</el-radio>
</el-radio-group>
</el-form-item>
<p style="font-size: medium; font-weight: bold">文件命名方式</p>
<el-form-item label="命名方式">
<el-radio-group v-model="uploadNameType">
<el-radio label="default">默认</el-radio>
<el-radio label="index">仅前缀</el-radio>
<el-radio label="origin">仅原名</el-radio>
</el-radio-group>
</el-form-item>
<p style="font-size: medium; font-weight: bold">客户端压缩</p>
<el-form-item label="开启压缩">
<el-switch
Expand Down Expand Up @@ -126,7 +153,10 @@ export default {
compressQuality: 4, //压缩后大小
compressBar: 5, //压缩阈值
serverCompress: true, //服务器端压缩
uploadChannel: 'telegram' //上传渠道
uploadChannel: 'telegram', //上传渠道
uploadNameType: 'default', //上传文件命名方式
customUrlPrefix: '', //自定义链接前缀
useCustomUrl: 'false' //是否启用自定义链接格式
}
},
watch: {
Expand All @@ -144,10 +174,19 @@ export default {
},
uploadChannel(val) {
this.updateStoreUploadChannel(val)
},
uploadNameType(val) {
this.updateStoreUploadNameType(val)
},
customUrlPrefix(val) {
this.$store.commit('setCustomUrlSettings', { key: 'customUrlPrefix', value: val })
},
useCustomUrl(val) {
this.$store.commit('setCustomUrlSettings', { key: 'useCustomUrl', value: val })
}
},
computed: {
...mapGetters(['userConfig', 'bingWallPapers', 'uploadCopyUrlForm', 'compressConfig', 'storeUploadChannel']),
...mapGetters(['userConfig', 'bingWallPapers', 'uploadCopyUrlForm', 'compressConfig', 'storeUploadChannel', 'storeUploadNameType', 'customUrlSettings']),
ownerName() {
return this.userConfig?.ownerName || 'Sanyue'
},
Expand Down Expand Up @@ -227,6 +266,11 @@ export default {
this.serverCompress = this.compressConfig.serverCompress
// 读取用户选择的上传渠道
this.uploadChannel = this.storeUploadChannel
// 读取用户选择的上传文件命名方式
this.uploadNameType = this.storeUploadNameType
// 读取用户自定义链接格式
this.customUrlPrefix = this.customUrlSettings.customUrlPrefix
this.useCustomUrl = this.customUrlSettings.useCustomUrl
},
components: {
UploadForm,
Expand Down Expand Up @@ -255,6 +299,9 @@ export default {
},
updateStoreUploadChannel(value) {
this.$store.commit('setStoreUploadChannel', value)
},
updateStoreUploadNameType(value) {
this.$store.commit('setStoreUploadNameType', value)
}
}
}
Expand Down

0 comments on commit f00bb12

Please sign in to comment.