feat: 植物识别
This commit is contained in:
@@ -4,7 +4,6 @@ import (
|
||||
"crypto/md5"
|
||||
"errors"
|
||||
"fmt"
|
||||
"image"
|
||||
_ "image/jpeg"
|
||||
_ "image/png"
|
||||
"io"
|
||||
@@ -58,24 +57,7 @@ func (o *OssService) Upload(multipartFile multipart.File, header *multipart.File
|
||||
}
|
||||
//文件后缀
|
||||
s := strings.Split(header.Filename, ".")
|
||||
height := 0
|
||||
width := 0
|
||||
//mime类型
|
||||
contentType := header.Header.Get("Content-Type")
|
||||
allowedImageTypes := map[string]bool{
|
||||
"image/jpeg": true,
|
||||
"image/png": true,
|
||||
}
|
||||
isPossibleImage := allowedImageTypes[contentType]
|
||||
//仅当可能是图片时 才计算图片宽高
|
||||
if isPossibleImage {
|
||||
img, _, err1 := image.Decode(multipartFile)
|
||||
if err1 != nil {
|
||||
return file, err
|
||||
}
|
||||
height = img.Bounds().Max.Y
|
||||
width = img.Bounds().Max.X
|
||||
}
|
||||
f := system.Oss{
|
||||
Key: key, // uploads/2025-09-17/
|
||||
Name: header.Filename,
|
||||
@@ -83,8 +65,6 @@ func (o *OssService) Upload(multipartFile multipart.File, header *multipart.File
|
||||
Tag: s[len(s)-1],
|
||||
Url: filepath, // http://127.0.0.1:9000/planting-fun/uploads/2025-09-17/211476f3837fc7acbaebf0f901c1bd68.png
|
||||
MD5: hashString,
|
||||
Height: height,
|
||||
Width: width,
|
||||
}
|
||||
return f, global.DB.Create(&f).Error
|
||||
}
|
||||
|
||||
@@ -96,7 +96,7 @@ func (s *MenuService) GetUserRoutes(userId string) (menus []*system.Menu, err er
|
||||
var menuIds []string
|
||||
err = global.DB.Model(&system.RoleMenu{}).Where("role_id in ?", roleIds).Pluck("menu_id", &menuIds).Error
|
||||
var menuList []*system.Menu
|
||||
err = global.DB.Model(&system.Menu{}).Where("id in ?", menuIds).Order("sort asc").Find(&menuList).Error
|
||||
err = global.DB.Model(&system.Menu{}).Where("id in ? and category = 1 ", menuIds).Order("sort asc").Find(&menuList).Error
|
||||
return buildMenuTree(menuList), nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user