mirror of
https://github.com/superseriousbusiness/gotosocial
synced 2025-06-05 21:59:39 +02:00
[chore]: Bump github.com/go-playground/validator/v10 (#1812)
Bumps [github.com/go-playground/validator/v10](https://github.com/go-playground/validator) from 10.13.0 to 10.14.0. - [Release notes](https://github.com/go-playground/validator/releases) - [Commits](https://github.com/go-playground/validator/compare/v10.13.0...v10.14.0) --- updated-dependencies: - dependency-name: github.com/go-playground/validator/v10 dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
This commit is contained in:
63
vendor/github.com/go-playground/validator/v10/baked_in.go
generated
vendored
63
vendor/github.com/go-playground/validator/v10/baked_in.go
generated
vendored
@ -22,6 +22,7 @@ import (
|
||||
"golang.org/x/crypto/sha3"
|
||||
"golang.org/x/text/language"
|
||||
|
||||
"github.com/gabriel-vasile/mimetype"
|
||||
"github.com/leodido/go-urn"
|
||||
)
|
||||
|
||||
@ -144,6 +145,7 @@ var (
|
||||
"endswith": endsWith,
|
||||
"startsnotwith": startsNotWith,
|
||||
"endsnotwith": endsNotWith,
|
||||
"image": isImage,
|
||||
"isbn": isISBN,
|
||||
"isbn10": isISBN10,
|
||||
"isbn13": isISBN13,
|
||||
@ -1488,6 +1490,67 @@ func isFile(fl FieldLevel) bool {
|
||||
panic(fmt.Sprintf("Bad field type %T", field.Interface()))
|
||||
}
|
||||
|
||||
// isImage is the validation function for validating if the current field's value contains the path to a valid image file
|
||||
func isImage(fl FieldLevel) bool {
|
||||
mimetypes := map[string]bool{
|
||||
"image/bmp": true,
|
||||
"image/cis-cod": true,
|
||||
"image/gif": true,
|
||||
"image/ief": true,
|
||||
"image/jpeg": true,
|
||||
"image/jp2": true,
|
||||
"image/jpx": true,
|
||||
"image/jpm": true,
|
||||
"image/pipeg": true,
|
||||
"image/png": true,
|
||||
"image/svg+xml": true,
|
||||
"image/tiff": true,
|
||||
"image/webp": true,
|
||||
"image/x-cmu-raster": true,
|
||||
"image/x-cmx": true,
|
||||
"image/x-icon": true,
|
||||
"image/x-portable-anymap": true,
|
||||
"image/x-portable-bitmap": true,
|
||||
"image/x-portable-graymap": true,
|
||||
"image/x-portable-pixmap": true,
|
||||
"image/x-rgb": true,
|
||||
"image/x-xbitmap": true,
|
||||
"image/x-xpixmap": true,
|
||||
"image/x-xwindowdump": true,
|
||||
}
|
||||
field := fl.Field()
|
||||
|
||||
switch field.Kind() {
|
||||
case reflect.String:
|
||||
filePath := field.String()
|
||||
fileInfo, err := os.Stat(filePath)
|
||||
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
|
||||
if fileInfo.IsDir() {
|
||||
return false
|
||||
}
|
||||
|
||||
file, err := os.Open(filePath)
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
defer file.Close()
|
||||
|
||||
mime, err := mimetype.DetectReader(file)
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
|
||||
if _, ok := mimetypes[mime.String()]; ok {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// isFilePath is the validation function for validating if the current field's value is a valid file path.
|
||||
func isFilePath(fl FieldLevel) bool {
|
||||
|
||||
|
Reference in New Issue
Block a user