return error state if upload file size exceeds limit

This commit is contained in:
Luk 2024-07-02 20:04:00 +08:00
parent 0b18c15347
commit 8a2048af22

View File

@ -321,8 +321,14 @@ export default {
}
if (!fileSize) {
this.showToast({ type: this.c2t.YELLOW, title: this.localizeText({ zhCN: '文件为空,无法上传', enUS: 'Empty files cannot be uploaded' }) })
return { _state: 'CER_EMPTY_FILE' }
let _msg = { zhCN: '文件为空,无法上传。', enUS: 'Empty files cannot be uploaded.' }
this.showToast({ type: this.c2t.YELLOW, title: this.localizeText(_msg) })
return { _state: 'CER_EMPTY_FILE', _msg }
} else if (fileSize > (globalThis.wo?.envar?.fileSizeLimit || 10485760)) {
let sizeLimitMB = parseInt((globalThis.wo?.envar?.fileSizeLimit || 10485760) / 1048576) + 'MB'
let _msg = { zhCN: `文件太大了,无法上传。最大允许 ${sizeLimitMB}`, enUS: `File too large to upload. Maximum allowed is ${sizeLimitMB}` }
this.showToast({ type: this.c2t.YELLOW, title: this.localizeText(_msg) })
return { _state: 'CER_FILE_TOO_LARGE', _msg }
}
if (filePath) {
@ -421,8 +427,14 @@ export default {
}
if (!fileSize) {
this.showToast({ type: this.c2t.YELLOW, title: this.localizeText({ zhCN: '文件为空,无法上传', enUS: 'Empty files cannot be uploaded' }) })
return { _state: 'CER_EMPTY_FILE' }
let _msg = { zhCN: '文件为空,无法上传。', enUS: 'Empty files cannot be uploaded.' }
this.showToast({ type: this.c2t.YELLOW, title: this.localizeText(_msg) })
return { _state: 'CER_EMPTY_FILE', _msg }
} else if (fileSize > (globalThis.wo?.envar?.fileSizeLimit || 10485760)) {
let sizeLimitMB = parseInt((globalThis.wo?.envar?.fileSizeLimit || 10485760) / 1048576) + 'MB'
let _msg = { zhCN: `文件太大了,无法上传。最大允许 ${sizeLimitMB}`, enUS: `File too large to upload. Maximum allowed is ${sizeLimitMB}` }
this.showToast({ type: this.c2t.YELLOW, title: this.localizeText(_msg) })
return { _state: 'CER_FILE_TOO_LARGE', _msg }
}
if (filePath) {