bug修复
This commit is contained in:
parent
15917e926e
commit
53f9111046
|
@ -72,9 +72,10 @@ func (rp *repo) GetList(ctx context.Context, req proto.ListRequest) (rsp *proto.
|
||||||
if err != nil {
|
if err != nil {
|
||||||
goto ReturnPoint
|
goto ReturnPoint
|
||||||
}
|
}
|
||||||
list := make([]proto.FileBaseInfo, len(files))
|
list := make([]proto.FileBaseInfo, 0)
|
||||||
for k, v := range files {
|
for _, v := range files {
|
||||||
info, _ := v.Info()
|
info, _ := v.Info()
|
||||||
|
if utils.IsImage(v.Name()) || v.IsDir() {
|
||||||
item := proto.FileBaseInfo{
|
item := proto.FileBaseInfo{
|
||||||
Name: v.Name(),
|
Name: v.Name(),
|
||||||
Path: path.Join(req.Path, v.Name()),
|
Path: path.Join(req.Path, v.Name()),
|
||||||
|
@ -82,7 +83,8 @@ func (rp *repo) GetList(ctx context.Context, req proto.ListRequest) (rsp *proto.
|
||||||
Size: info.Size(),
|
Size: info.Size(),
|
||||||
ModTime: info.ModTime().Unix(),
|
ModTime: info.ModTime().Unix(),
|
||||||
}
|
}
|
||||||
list[k] = item
|
list = append(list, item)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
rsp.Code = http.StatusOK
|
rsp.Code = http.StatusOK
|
||||||
|
@ -127,13 +129,15 @@ func (rp *repo) GetInfo(ctx context.Context, req proto.ListRequest) (rsp *proto.
|
||||||
goto ReturnPoint
|
goto ReturnPoint
|
||||||
}
|
}
|
||||||
buff := utils.ReadFile(req.Path)
|
buff := utils.ReadFile(req.Path)
|
||||||
|
img := utils.BuffToImage(buff)
|
||||||
|
buf := utils.ImageToBuff(img, "jpeg")
|
||||||
res := new(proto.FileContent)
|
res := new(proto.FileContent)
|
||||||
res.Name = fileInfo.Name()
|
res.Name = fileInfo.Name()
|
||||||
res.IsDir = false
|
res.IsDir = false
|
||||||
res.Path = req.Path
|
res.Path = req.Path
|
||||||
res.Size = fileInfo.Size()
|
res.Size = fileInfo.Size()
|
||||||
res.ModTime = fileInfo.ModTime().Unix()
|
res.ModTime = fileInfo.ModTime().Unix()
|
||||||
res.ContentBase = base64.StdEncoding.EncodeToString(buff)
|
res.ContentBase = "data:image/jpeg;base64," + base64.StdEncoding.EncodeToString(buf.Bytes())
|
||||||
b, ok := global.FileLabelList[req.Path]
|
b, ok := global.FileLabelList[req.Path]
|
||||||
if ok {
|
if ok {
|
||||||
if b {
|
if b {
|
||||||
|
|
|
@ -12,6 +12,8 @@ import (
|
||||||
"image/jpeg"
|
"image/jpeg"
|
||||||
"image/png"
|
"image/png"
|
||||||
"math"
|
"math"
|
||||||
|
"path"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
func BuffToImage(in []byte) image.Image {
|
func BuffToImage(in []byte) image.Image {
|
||||||
|
@ -153,7 +155,7 @@ func ImageToBuff(img image.Image, imgType string) *bytes.Buffer {
|
||||||
case "png":
|
case "png":
|
||||||
imgType = "png"
|
imgType = "png"
|
||||||
_ = png.Encode(buff, img)
|
_ = png.Encode(buff, img)
|
||||||
case "tiff":
|
case "tiff", "tif":
|
||||||
imgType = "tiff"
|
imgType = "tiff"
|
||||||
_ = tiff.Encode(buff, img, nil)
|
_ = tiff.Encode(buff, img, nil)
|
||||||
default:
|
default:
|
||||||
|
@ -214,3 +216,18 @@ func width(i image.Image) int {
|
||||||
func height(i image.Image) int {
|
func height(i image.Image) int {
|
||||||
return i.Bounds().Max.Y - i.Bounds().Min.Y
|
return i.Bounds().Max.Y - i.Bounds().Min.Y
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func IsImage(fileName string) bool {
|
||||||
|
fileType := path.Ext(fileName)
|
||||||
|
return InSlice([]string{".png", ".jpg", ".jpeg", ".bmp", ".tif", ".tiff"}, strings.ToLower(fileType))
|
||||||
|
}
|
||||||
|
|
||||||
|
// InSlice 判断字符串是否在 slice 中。
|
||||||
|
func InSlice(items []string, item string) bool {
|
||||||
|
for _, eachItem := range items {
|
||||||
|
if eachItem == item {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue