feat: 增加 OpenResty 设置的校验

pull/184/head
zhengkunwang223 2023-03-02 15:46:42 +08:00 committed by ssongliu
parent f0923169d3
commit 0ec65c3e24
4 changed files with 28 additions and 10 deletions

View File

@ -186,6 +186,17 @@ const checkParamUrlAndPort = (rule: any, value: any, callback: any) => {
} }
}; };
export function checkNumberRange(min: number, max: number): FormItemRule {
return {
required: true,
trigger: 'blur',
min: min,
max: max,
type: 'number',
message: i18n.global.t('commons.rule.numberRange', [min, max]),
};
}
interface CommonRule { interface CommonRule {
requiredInput: FormItemRule; requiredInput: FormItemRule;
requiredSelect: FormItemRule; requiredSelect: FormItemRule;

View File

@ -136,8 +136,10 @@ export default {
domain: 'domain name format error', domain: 'domain name format error',
databaseName: 'Support English, numbers, _, length 1-30', databaseName: 'Support English, numbers, _, length 1-30',
ipErr: 'IP [{0}] format error, please check', ipErr: 'IP [{0}] format error, please check',
numberRange: 'Number range: {0} - {1}',
paramName: 'Support English, numbers, .- and _, length 2-30', paramName: 'Support English, numbers, .- and _, length 2-30',
paramComplexity: 'Support English, numbers, {0}, length 6-30', paramComplexity: 'Support English, numbers, {0}, length 6-30',
paramUrlAndPort: 'The format is http(s)://(domain name/ip):(port)',
}, },
res: { res: {
paramError: 'The request failed, please try again later!', paramError: 'The request failed, please try again later!',

View File

@ -141,6 +141,7 @@ export default {
domain: '', domain: '',
databaseName: '_,1-30', databaseName: '_,1-30',
ipErr: 'IP [{0}] ,', ipErr: 'IP [{0}] ,',
numberRange: ': {0} - {1}',
paramName: '.-_,2-30', paramName: '.-_,2-30',
paramComplexity: '{0},6-30', paramComplexity: '{0},6-30',
paramUrlAndPort: ' http(s)://(域名/ip):(端口)', paramUrlAndPort: ' http(s)://(域名/ip):(端口)',

View File

@ -5,23 +5,27 @@
<el-col :span="1"><br /></el-col> <el-col :span="1"><br /></el-col>
<el-col :span="9"> <el-col :span="9">
<el-form-item label="server_names_hash_bucket_size" prop="server_names_hash_bucket_size"> <el-form-item label="server_names_hash_bucket_size" prop="server_names_hash_bucket_size">
<el-input clearable v-model.number="form.server_names_hash_bucket_size"></el-input> <el-input
clearable
type="number"
v-model.number="form.server_names_hash_bucket_size"
></el-input>
<span class="input-help">{{ $t('nginx.serverNamesHashBucketSizeHelper') }}</span> <span class="input-help">{{ $t('nginx.serverNamesHashBucketSizeHelper') }}</span>
</el-form-item> </el-form-item>
<el-form-item label="client_header_buffer_size" prop="client_header_buffer_size"> <el-form-item label="client_header_buffer_size" prop="client_header_buffer_size">
<el-input clearable v-model.number="form.client_header_buffer_size"> <el-input clearable type="number" v-model.number="form.client_header_buffer_size">
<template #append>K</template> <template #append>K</template>
</el-input> </el-input>
<span class="input-help">{{ $t('nginx.clientHeaderBufferSizeHelper') }}</span> <span class="input-help">{{ $t('nginx.clientHeaderBufferSizeHelper') }}</span>
</el-form-item> </el-form-item>
<el-form-item label="client_max_body_size" prop="client_max_body_size"> <el-form-item label="client_max_body_size" prop="client_max_body_size">
<el-input clearable v-model.number="form.client_max_body_size"> <el-input clearable type="number" v-model.number="form.client_max_body_size">
<template #append>MB</template> <template #append>MB</template>
</el-input> </el-input>
<span class="input-help">{{ $t('nginx.clientMaxBodySizeHelper') }}</span> <span class="input-help">{{ $t('nginx.clientMaxBodySizeHelper') }}</span>
</el-form-item> </el-form-item>
<el-form-item label="keepalive_timeout" prop="keepalive_timeout"> <el-form-item label="keepalive_timeout" prop="keepalive_timeout">
<el-input clearable v-model.number="form.keepalive_timeout"></el-input> <el-input clearable type="number" v-model.number="form.keepalive_timeout"></el-input>
<span class="input-help">{{ $t('nginx.keepaliveTimeoutHelper') }}</span> <span class="input-help">{{ $t('nginx.keepaliveTimeoutHelper') }}</span>
</el-form-item> </el-form-item>
<el-form-item> <el-form-item>
@ -57,7 +61,7 @@
<script lang="ts" setup> <script lang="ts" setup>
import { Nginx } from '@/api/interface/nginx'; import { Nginx } from '@/api/interface/nginx';
import { GetNginxConfigByScope, UpdateNginxConfigByScope } from '@/api/modules/nginx'; import { GetNginxConfigByScope, UpdateNginxConfigByScope } from '@/api/modules/nginx';
import { Rules } from '@/global/form-rules'; import { checkNumberRange, Rules } from '@/global/form-rules';
import i18n from '@/lang'; import i18n from '@/lang';
import { MsgSuccess } from '@/utils/message'; import { MsgSuccess } from '@/utils/message';
import { FormInstance } from 'element-plus'; import { FormInstance } from 'element-plus';
@ -85,13 +89,13 @@ let nginxFormRef = ref();
let loading = ref(false); let loading = ref(false);
const variablesRules = reactive({ const variablesRules = reactive({
server_names_hash_bucket_size: [Rules.number], server_names_hash_bucket_size: [checkNumberRange(1, 9999)],
client_header_buffer_size: [Rules.number], client_header_buffer_size: [checkNumberRange(0, 999999999)],
client_max_body_size: [Rules.number], client_max_body_size: [checkNumberRange(0, 999999999)],
keepalive_timeout: [Rules.number], keepalive_timeout: [checkNumberRange(0, 999999999)],
gzip: [Rules.requiredSelect], gzip: [Rules.requiredSelect],
gzip_min_length: [Rules.requiredSelect], gzip_min_length: [Rules.requiredSelect],
gzip_comp_level: [Rules.number], gzip_comp_level: [checkNumberRange(1, 9)],
}); });
const getParams = async () => { const getParams = async () => {