mirror of
https://github.com/1Panel-dev/1Panel.git
synced 2025-01-31 22:18:07 +08:00
feat: 应用参数增加规则校验
This commit is contained in:
parent
f941cd9751
commit
cd921e7682
@ -146,6 +146,46 @@ const checkDomain = (rule: any, value: any, callback: any) => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const checkParamCommon = (rule: any, value: any, callback: any) => {
|
||||||
|
if (value === '' || typeof value === 'undefined' || value == null) {
|
||||||
|
callback(new Error(i18n.global.t('commons.rule.paramName')));
|
||||||
|
} else {
|
||||||
|
const reg = /^[a-zA-Z0-9]{1}[a-zA-Z0-9._-]{6,30}$/;
|
||||||
|
if (!reg.test(value) && value !== '') {
|
||||||
|
callback(new Error(i18n.global.t('commons.rule.paramName')));
|
||||||
|
} else {
|
||||||
|
callback();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const checkParamComplexity = (rule: any, value: any, callback: any) => {
|
||||||
|
if (value === '' || typeof value === 'undefined' || value == null) {
|
||||||
|
callback(new Error(i18n.global.t('commons.rule.paramComplexity', ['.%@$!&~_'])));
|
||||||
|
} else {
|
||||||
|
const reg = /^[a-zA-Z0-9]{1}[a-zA-Z0-9.%@$!&~_]{6,30}$/;
|
||||||
|
if (!reg.test(value) && value !== '') {
|
||||||
|
callback(new Error(i18n.global.t('commons.rule.paramComplexity', ['.%@$!&~_'])));
|
||||||
|
} else {
|
||||||
|
callback();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const checkParamUrlAndPort = (rule: any, value: any, callback: any) => {
|
||||||
|
if (value === '' || typeof value === 'undefined' || value == null) {
|
||||||
|
callback(new Error(i18n.global.t('commons.rule.paramUrlAndPort')));
|
||||||
|
} else {
|
||||||
|
const reg =
|
||||||
|
/^(https?:\/\/)?((localhost)|([a-zA-Z0-9_-]+\.)*[a-zA-Z0-9_-]+)(:[1-9]\d{0,3}|:[1-5]\d{4}|:6[0-4]\d{3}|:65[0-4]\d{2}|:655[0-2]\d|:6553[0-5])?(\/\S*)?$/;
|
||||||
|
if (!reg.test(value) && value !== '') {
|
||||||
|
callback(new Error(i18n.global.t('commons.rule.paramUrlAndPort')));
|
||||||
|
} else {
|
||||||
|
callback();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
interface CommonRule {
|
interface CommonRule {
|
||||||
requiredInput: FormItemRule;
|
requiredInput: FormItemRule;
|
||||||
requiredSelect: FormItemRule;
|
requiredSelect: FormItemRule;
|
||||||
@ -164,6 +204,11 @@ interface CommonRule {
|
|||||||
port: FormItemRule;
|
port: FormItemRule;
|
||||||
domain: FormItemRule;
|
domain: FormItemRule;
|
||||||
databaseName: FormItemRule;
|
databaseName: FormItemRule;
|
||||||
|
|
||||||
|
paramCommon: FormItemRule;
|
||||||
|
paramComplexity: FormItemRule;
|
||||||
|
paramPort: FormItemRule;
|
||||||
|
paramExtUrl: FormItemRule;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const Rules: CommonRule = {
|
export const Rules: CommonRule = {
|
||||||
@ -260,4 +305,27 @@ export const Rules: CommonRule = {
|
|||||||
validator: checkDomain,
|
validator: checkDomain,
|
||||||
trigger: 'blur',
|
trigger: 'blur',
|
||||||
},
|
},
|
||||||
|
paramCommon: {
|
||||||
|
required: true,
|
||||||
|
validator: checkParamCommon,
|
||||||
|
trigger: 'blur',
|
||||||
|
},
|
||||||
|
paramComplexity: {
|
||||||
|
required: true,
|
||||||
|
validator: checkParamComplexity,
|
||||||
|
trigger: 'blur',
|
||||||
|
},
|
||||||
|
paramPort: {
|
||||||
|
required: true,
|
||||||
|
trigger: 'blur',
|
||||||
|
min: 1,
|
||||||
|
max: 65535,
|
||||||
|
type: 'number',
|
||||||
|
message: i18n.global.t('commons.rule.port'),
|
||||||
|
},
|
||||||
|
paramExtUrl: {
|
||||||
|
required: true,
|
||||||
|
validator: checkParamUrlAndPort,
|
||||||
|
trigger: 'blur',
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
@ -133,6 +133,11 @@ export default {
|
|||||||
ip: 'Please enter the correct IP address',
|
ip: 'Please enter the correct IP address',
|
||||||
port: 'Please enter the correct port',
|
port: 'Please enter the correct port',
|
||||||
selectHelper: 'Please select the correct {0} file',
|
selectHelper: 'Please select the correct {0} file',
|
||||||
|
domain: 'domain name format error',
|
||||||
|
databaseName: 'Support English, numbers, _, length 1-30',
|
||||||
|
ipErr: 'IP [{0}] format error, please check',
|
||||||
|
paramName: 'Support English, numbers, .- and _, length 6-30',
|
||||||
|
paramComplexity: 'Support English, numbers, {0}, length 6-30',
|
||||||
},
|
},
|
||||||
res: {
|
res: {
|
||||||
paramError: 'The request failed, please try again later!',
|
paramError: 'The request failed, please try again later!',
|
||||||
|
@ -136,11 +136,14 @@ export default {
|
|||||||
email: '请输入正确的邮箱',
|
email: '请输入正确的邮箱',
|
||||||
number: '请输入正确的数字',
|
number: '请输入正确的数字',
|
||||||
ip: '请输入正确的 IP 地址',
|
ip: '请输入正确的 IP 地址',
|
||||||
port: '请输入正确的端口',
|
port: '请输入正确的端口,1-65535',
|
||||||
selectHelper: '请选择正确的 {0} 文件',
|
selectHelper: '请选择正确的 {0} 文件',
|
||||||
domain: '域名格式错误',
|
domain: '域名格式错误',
|
||||||
databaseName: '支持英文、数字、_,长度1-30',
|
databaseName: '支持英文、数字、_,长度1-30',
|
||||||
ipErr: 'IP [{0}] 格式错误,请检查',
|
ipErr: 'IP [{0}] 格式错误,请检查',
|
||||||
|
paramName: '支持英文、数字、.-和_,长度6-30',
|
||||||
|
paramComplexity: '支持英文、数字、{0},长度6-30',
|
||||||
|
paramUrlAndPort: '格式为 http(s)://(域名/ip):(端口)',
|
||||||
},
|
},
|
||||||
res: {
|
res: {
|
||||||
paramError: '请求失败,请稍后重试!',
|
paramError: '请求失败,请稍后重试!',
|
||||||
|
@ -114,8 +114,8 @@ const handleParams = () => {
|
|||||||
pObj.prop = propStart.value + p.envKey;
|
pObj.prop = propStart.value + p.envKey;
|
||||||
pObj.disabled = p.disabled;
|
pObj.disabled = p.disabled;
|
||||||
paramObjs.value.push(pObj);
|
paramObjs.value.push(pObj);
|
||||||
if (p.default == 'random') {
|
if (p.random) {
|
||||||
form[p.envKey] = getRandomStr(6);
|
form[p.envKey] = p.default + '_' + getRandomStr(6);
|
||||||
} else {
|
} else {
|
||||||
form[p.envKey] = p.default;
|
form[p.envKey] = p.default;
|
||||||
}
|
}
|
||||||
@ -124,8 +124,8 @@ const handleParams = () => {
|
|||||||
rules[p.envKey] = [Rules.requiredSelect];
|
rules[p.envKey] = [Rules.requiredSelect];
|
||||||
} else {
|
} else {
|
||||||
rules[p.envKey] = [Rules.requiredInput];
|
rules[p.envKey] = [Rules.requiredInput];
|
||||||
if (p.envKey === 'PANEL_DB_NAME') {
|
if (p.rule && p.rule != '') {
|
||||||
rules[p.envKey].push(Rules.dbName);
|
rules[p.envKey].push(Rules[p.rule]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user