f
This commit is contained in:
@@ -10,6 +10,8 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/go-playground/validator/v10"
|
||||
|
||||
"hyapi-server/internal/shared/pdfvalidate"
|
||||
)
|
||||
|
||||
// RegisterCustomValidators 注册所有自定义验证器
|
||||
@@ -104,6 +106,9 @@ func RegisterCustomValidators(validate *validator.Validate) {
|
||||
// Base64编码格式验证器
|
||||
validate.RegisterValidation("base64", validateBase64)
|
||||
validate.RegisterValidation("validBase64", validateBase64)
|
||||
|
||||
// 汇博授权 PDF Base64 验证器(解码后校验 PDF 魔数与大小上限)
|
||||
validate.RegisterValidation("validAuthPDFBase64", validateAuthPDFBase64)
|
||||
}
|
||||
|
||||
// validatePhone 手机号验证
|
||||
@@ -1037,3 +1042,16 @@ func validateBase64(fl validator.FieldLevel) bool {
|
||||
_, err := base64.StdEncoding.DecodeString(base64Str)
|
||||
return err == nil
|
||||
}
|
||||
|
||||
// validateAuthPDFBase64 汇博授权 PDF Base64 验证器
|
||||
func validateAuthPDFBase64(fl validator.FieldLevel) bool {
|
||||
base64Str := strings.TrimSpace(fl.Field().String())
|
||||
if base64Str == "" {
|
||||
return true
|
||||
}
|
||||
raw, err := base64.StdEncoding.DecodeString(base64Str)
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
return pdfvalidate.ValidateDecodedPDFBinary(raw) == nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user