fix: 解决 halo 用户名设置为大写之后导致安装失败的问题 (#1190)

Refs https://github.com/1Panel-dev/1Panel/issues/1161
pull/1192/head
zhengkunwang223 2023-05-30 15:04:57 +08:00 committed by GitHub
parent ce0342e235
commit 1e96a1ae84
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 25 additions and 9 deletions

View File

@ -456,19 +456,14 @@ func (b *BaseApi) MoveFile(c *gin.Context) {
// @x-panel-log {"bodyKeys":["name"],"paramKeys":[],"BeforeFuntions":[],"formatZH":"下载文件 [name]","formatEN":"Download file [name]"}
func (b *BaseApi) Download(c *gin.Context) {
filePath := c.Query("path")
file, err := os.Open(filePath)
if err != nil {
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
}
info, _ := file.Stat()
c.Header("Content-Length", strconv.FormatInt(info.Size(), 10))
c.Header("Content-Disposition", "attachment; filename*=utf-8''"+url.PathEscape(info.Name()))
http.ServeContent(c.Writer, c.Request, info.Name(), info.ModTime(), file)
return
}
// @Tags File

View File

@ -191,7 +191,7 @@ 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._-]{1,29}$/;
const reg = /^[a-zA-Z0-9]{1}[a-zA-Z0-9._-]{1,63}$/;
if (!reg.test(value) && value !== '') {
callback(new Error(i18n.global.t('commons.rule.paramName')));
} else {
@ -204,7 +204,7 @@ 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.%@$!&~_-]{5,29}$/;
const reg = /^[a-zA-Z0-9]{1}[a-zA-Z0-9.%@$!&~_-]{5,127}$/;
if (!reg.test(value) && value !== '') {
callback(new Error(i18n.global.t('commons.rule.paramComplexity', ['.%@$!&~_-'])));
} else {
@ -303,6 +303,19 @@ const checkLeechExts = (rule: any, value: any, callback: any) => {
}
};
const checkParamSimple = (rule: any, value: any, callback: any) => {
if (value === '' || typeof value === 'undefined' || value == null) {
callback();
} else {
const reg = /^[a-z0-9][a-z0-9]{1,64}$/;
if (!reg.test(value) && value !== '') {
callback(new Error(i18n.global.t('commons.rule.paramSimple')));
} else {
callback();
}
}
};
interface CommonRule {
requiredInput: FormItemRule;
requiredSelect: FormItemRule;
@ -333,6 +346,7 @@ interface CommonRule {
paramComplexity: FormItemRule;
paramPort: FormItemRule;
paramExtUrl: FormItemRule;
paramSimple: FormItemRule;
}
export const Rules: CommonRule = {
@ -484,4 +498,9 @@ export const Rules: CommonRule = {
trigger: 'blur',
validator: checkLeechExts,
},
paramSimple: {
required: true,
trigger: 'blur',
validator: checkParamSimple,
},
};

View File

@ -162,6 +162,7 @@ const message = {
'Supports letters, numbers, underscores, hyphens and dots, cannot end with hyphen- or dot.1-127',
disableFunction: 'Only support letters and,',
leechExts: 'Only support letters, numbers and,',
paramSimple: 'Support lowercase letters and numbers, length 1-64',
},
res: {
paramError: 'The request failed, please try again later!',

View File

@ -156,14 +156,15 @@ const message = {
databaseName: '_,1-30',
ipErr: 'IP [{0}] ,',
numberRange: ': {0} - {1}',
paramName: '.-_,2-30',
paramComplexity: '{0},6-30',
paramName: '.-_,2-64',
paramComplexity: '{0},6-128',
paramUrlAndPort: ' http(s)://(域名/ip):(端口)',
nginxDoc: '.',
appName: '-_,2-30,-_',
conatinerName: '线,-.,1-127',
disableFunction: ',',
leechExts: ',',
paramSimple: ',1-64',
},
res: {
paramError: ',!',