feat(系统设置): 支持上传文件大小限制

--task=1016193 --user=宋昌昌 系统配置支持自定义文件大小限制-后端-V2 https://www.tapd.cn/55049933/s/1576397
This commit is contained in:
song-cc-rock 2024-09-10 11:56:46 +08:00 committed by Craftsman
parent f201dbfe91
commit bfc17f9eeb
7 changed files with 50 additions and 11 deletions

View File

@ -622,6 +622,9 @@ const message = {
url_tip: 'example: http://localhost:4444', url_tip: 'example: http://localhost:4444',
}, },
local_selenium_url: 'Local selenium-server URL', local_selenium_url: 'Local selenium-server URL',
file_upload_size: 'File size limit(MB)',
file_upload_size_is_null: 'The file size limit cannot be empty',
file_upload_tips: 'Please fill in the integer [1-1024]'
}, },
custom_field: { custom_field: {
add_option: 'Add Option', add_option: 'Add Option',

View File

@ -620,6 +620,9 @@ const message = {
url_tip: '例如:http://localhost:4444', url_tip: '例如:http://localhost:4444',
}, },
local_selenium_url: '本地 selenium-server 地址', local_selenium_url: '本地 selenium-server 地址',
file_upload_size: '文件大小限制(MB)',
file_upload_size_is_null: '文件大小限制不能为空',
file_upload_tips: '请填写[1-1024]的整数'
}, },
custom_field: { custom_field: {
add_option: '添加选项', add_option: '添加选项',

View File

@ -619,6 +619,9 @@ const message = {
url_tip: '例如:http://localhost:4444', url_tip: '例如:http://localhost:4444',
}, },
local_selenium_url: '本地 selenium-server 地址', local_selenium_url: '本地 selenium-server 地址',
file_upload_size: '文件大小限制(MB)',
file_upload_size_is_null: '文件大小限制不能爲空',
file_upload_tips: '請填寫[1-1024]的整數'
}, },
custom_field: { custom_field: {
add_option: '添加選項', add_option: '添加選項',

View File

@ -12,4 +12,5 @@ public class BaseSystemConfigDTO {
private String seleniumDockerUrl; private String seleniumDockerUrl;
private String runMode; private String runMode;
private String docUrl; private String docUrl;
private String maxSize;
} }

View File

@ -106,7 +106,7 @@ public interface ParamConstants {
@Override @Override
public String getValue() { public String getValue() {
return this.value; return value;
} }
} }
@ -117,7 +117,8 @@ public interface ParamConstants {
PROMETHEUS_HOST("base.prometheus.host"), PROMETHEUS_HOST("base.prometheus.host"),
SELENIUM_DOCKER_URL("base.selenium.docker.url"), SELENIUM_DOCKER_URL("base.selenium.docker.url"),
RUN_MODE("base.run.mode"), RUN_MODE("base.run.mode"),
DOC_URL("base.doc.url"); DOC_URL("base.doc.url"),
MAX_SIZE("base.file.upload.size");
private String value; private String value;

View File

@ -28,7 +28,6 @@ import io.metersphere.quota.service.BaseQuotaService;
import io.metersphere.request.HeaderRequest; import io.metersphere.request.HeaderRequest;
import io.metersphere.request.resourcepool.QueryResourcePoolRequest; import io.metersphere.request.resourcepool.QueryResourcePoolRequest;
import jakarta.annotation.Resource; import jakarta.annotation.Resource;
import jakarta.mail.MessagingException;
import jakarta.mail.internet.InternetAddress; import jakarta.mail.internet.InternetAddress;
import jakarta.mail.internet.MimeMessage; import jakarta.mail.internet.MimeMessage;
import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.CollectionUtils;
@ -96,7 +95,7 @@ public class SystemParameterService {
} }
public void editMail(List<SystemParameter> parameters) { public void editMail(List<SystemParameter> parameters) {
List<SystemParameter> paramList = this.getParamList(ParamConstants.Classify.MAIL.getValue()); List<SystemParameter> paramList = getParamList(ParamConstants.Classify.MAIL.getValue());
boolean empty = paramList.size() <= 0; boolean empty = paramList.size() <= 0;
parameters.forEach(parameter -> { parameters.forEach(parameter -> {
@ -188,7 +187,7 @@ public class SystemParameterService {
} }
public MailInfo mailInfo(String type) { public MailInfo mailInfo(String type) {
List<SystemParameter> paramList = this.getParamList(type); List<SystemParameter> paramList = getParamList(type);
MailInfo mailInfo = new MailInfo(); MailInfo mailInfo = new MailInfo();
if (!CollectionUtils.isEmpty(paramList)) { if (!CollectionUtils.isEmpty(paramList)) {
for (SystemParameter param : paramList) { for (SystemParameter param : paramList) {
@ -275,7 +274,7 @@ public class SystemParameterService {
public BaseSystemConfigDTO getBaseInfo() { public BaseSystemConfigDTO getBaseInfo() {
BaseSystemConfigDTO baseSystemConfigDTO = new BaseSystemConfigDTO(); BaseSystemConfigDTO baseSystemConfigDTO = new BaseSystemConfigDTO();
List<SystemParameter> paramList = this.getParamList(ParamConstants.Classify.BASE.getValue()); List<SystemParameter> paramList = getParamList(ParamConstants.Classify.BASE.getValue());
if (!CollectionUtils.isEmpty(paramList)) { if (!CollectionUtils.isEmpty(paramList)) {
for (SystemParameter param : paramList) { for (SystemParameter param : paramList) {
if (StringUtils.equals(param.getParamKey(), ParamConstants.BASE.URL.getValue())) { if (StringUtils.equals(param.getParamKey(), ParamConstants.BASE.URL.getValue())) {
@ -296,6 +295,9 @@ public class SystemParameterService {
if (StringUtils.equals(param.getParamKey(), ParamConstants.BASE.DOC_URL.getValue())) { if (StringUtils.equals(param.getParamKey(), ParamConstants.BASE.DOC_URL.getValue())) {
baseSystemConfigDTO.setDocUrl(param.getParamValue()); baseSystemConfigDTO.setDocUrl(param.getParamValue());
} }
if (StringUtils.equals(param.getParamKey(), ParamConstants.BASE.MAX_SIZE.getValue())) {
baseSystemConfigDTO.setMaxSize(param.getParamValue());
}
} }
} }
return baseSystemConfigDTO; return baseSystemConfigDTO;
@ -469,7 +471,7 @@ public class SystemParameterService {
} }
public String getLogDetails() { public String getLogDetails() {
LdapInfo ldapInfo = this.getLdapInfo(ParamConstants.Classify.LDAP.getValue()); LdapInfo ldapInfo = getLdapInfo(ParamConstants.Classify.LDAP.getValue());
if (ldapInfo != null) { if (ldapInfo != null) {
List<DetailColumn> columns = ReflexObjectUtil.getColumns(ldapInfo, SystemReference.ldapColumns); List<DetailColumn> columns = ReflexObjectUtil.getColumns(ldapInfo, SystemReference.ldapColumns);
OperatingLogDetails details = new OperatingLogDetails(JSON.toJSONString(ldapInfo.getUrl()), null, "LDAP设置", null, columns); OperatingLogDetails details = new OperatingLogDetails(JSON.toJSONString(ldapInfo.getUrl()), null, "LDAP设置", null, columns);
@ -479,7 +481,7 @@ public class SystemParameterService {
} }
public String getMailLogDetails() { public String getMailLogDetails() {
MailInfo mailInfo = this.mailInfo(ParamConstants.Classify.MAIL.getValue()); MailInfo mailInfo = mailInfo(ParamConstants.Classify.MAIL.getValue());
if (mailInfo != null) { if (mailInfo != null) {
List<DetailColumn> columns = ReflexObjectUtil.getColumns(mailInfo, SystemReference.mailColumns); List<DetailColumn> columns = ReflexObjectUtil.getColumns(mailInfo, SystemReference.mailColumns);
OperatingLogDetails details = new OperatingLogDetails(JSON.toJSONString(mailInfo.getAccount()), null, "邮件设置", null, columns); OperatingLogDetails details = new OperatingLogDetails(JSON.toJSONString(mailInfo.getAccount()), null, "邮件设置", null, columns);
@ -489,7 +491,7 @@ public class SystemParameterService {
} }
public String getBaseLogDetails() { public String getBaseLogDetails() {
BaseSystemConfigDTO configDTO = this.getBaseInfo(); BaseSystemConfigDTO configDTO = getBaseInfo();
if (configDTO != null) { if (configDTO != null) {
List<DetailColumn> columns = ReflexObjectUtil.getColumns(configDTO, SystemReference.baseColumns); List<DetailColumn> columns = ReflexObjectUtil.getColumns(configDTO, SystemReference.baseColumns);
OperatingLogDetails details = new OperatingLogDetails(JSON.toJSONString(configDTO.getUrl()), null, "基本配置", null, columns); OperatingLogDetails details = new OperatingLogDetails(JSON.toJSONString(configDTO.getUrl()), null, "基本配置", null, columns);

View File

@ -19,6 +19,9 @@
<el-form-item :label="$t('commons.help_documentation')" prop="docUrl"> <el-form-item :label="$t('commons.help_documentation')" prop="docUrl">
<el-input v-model="formInline.docUrl" placeholder="https://metersphere.io/docs/index.html"/> <el-input v-model="formInline.docUrl" placeholder="https://metersphere.io/docs/index.html"/>
</el-form-item> </el-form-item>
<el-form-item :label="$t('system_config.file_upload_size')" prop="maxSize">
<el-input v-model="formInline.maxSize" :placeholder="$t('system_config.file_upload_tips')"/>
</el-form-item>
</el-col> </el-col>
</el-row> </el-row>
</el-form> </el-form>
@ -39,8 +42,23 @@ import {getSystemBaseSetting, saveSystemBaseSetting} from "../../../api/system";
export default { export default {
name: "BaseSetting", name: "BaseSetting",
data() { data() {
const checkUploadSize = (rule, value, callback) => {
if (!value) {
return callback(new Error(this.$t('system_config.file_upload_size_is_null')));
}
if (isNaN(value) || !Number.isInteger(Number(value))) {
callback(new Error(this.$t('system_config.file_upload_tips')));
} else {
const size = Number.parseInt(value);
if (size < 1 || size > 1024) {
callback(new Error(this.$t('system_config.file_upload_tips')));
} else {
callback();
}
}
};
return { return {
formInline: {runMode: true, docUrl: 'https://metersphere.io/docs/index.html'}, formInline: {runMode: true, docUrl: 'https://metersphere.io/docs/index.html', maxSize: null},
input: '', input: '',
visible: true, visible: true,
showEdit: true, showEdit: true,
@ -65,6 +83,12 @@ export default {
trigger: ['change', 'blur'] trigger: ['change', 'blur']
}, },
], ],
maxSize: [
{
validator: checkUploadSize,
trigger: ['change', 'blur']
}
],
} }
} }
}, },
@ -82,6 +106,7 @@ export default {
res.data.docUrl = 'https://metersphere.io/docs/index.html' res.data.docUrl = 'https://metersphere.io/docs/index.html'
} }
this.formInline = res.data; this.formInline = res.data;
console.log(this.formInline);
this.$nextTick(() => { this.$nextTick(() => {
if (this.$refs.formInline) { if (this.$refs.formInline) {
this.$refs.formInline.clearValidate(); this.$refs.formInline.clearValidate();
@ -109,7 +134,8 @@ export default {
{paramKey: "base.concurrency", paramValue: this.formInline.concurrency, type: "text", sort: 2}, {paramKey: "base.concurrency", paramValue: this.formInline.concurrency, type: "text", sort: 2},
{paramKey: "base.prometheus.host", paramValue: this.formInline.prometheusHost, type: "text", sort: 1}, {paramKey: "base.prometheus.host", paramValue: this.formInline.prometheusHost, type: "text", sort: 1},
{paramKey: "base.selenium.docker.url", paramValue: this.formInline.seleniumDockerUrl, type: "text", sort: 1}, {paramKey: "base.selenium.docker.url", paramValue: this.formInline.seleniumDockerUrl, type: "text", sort: 1},
{paramKey: "base.doc.url", paramValue: this.formInline.docUrl, type: "text", sort: 1} {paramKey: "base.doc.url", paramValue: this.formInline.docUrl, type: "text", sort: 1},
{paramKey: "base.file.upload.size", paramValue: this.formInline.maxSize, type: "text", sort: 1},
]; ];
this.loading = saveSystemBaseSetting(param).then(res => { this.loading = saveSystemBaseSetting(param).then(res => {
if (res.success) { if (res.success) {