From 8a2048af22bef12484e5c17fc67ccc0bbbd9b88e Mon Sep 17 00:00:00 2001 From: Luk Date: Tue, 2 Jul 2024 20:04:00 +0800 Subject: [PATCH] return error state if upload file size exceeds limit --- unitool.js | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/unitool.js b/unitool.js index 28fcb5c..3816cd1 100644 --- a/unitool.js +++ b/unitool.js @@ -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) {