bug修复
This commit is contained in:
parent
15917e926e
commit
53f9111046
|
@ -72,17 +72,19 @@ func (rp *repo) GetList(ctx context.Context, req proto.ListRequest) (rsp *proto.
|
|||
if err != nil {
|
||||
goto ReturnPoint
|
||||
}
|
||||
list := make([]proto.FileBaseInfo, len(files))
|
||||
for k, v := range files {
|
||||
list := make([]proto.FileBaseInfo, 0)
|
||||
for _, v := range files {
|
||||
info, _ := v.Info()
|
||||
item := proto.FileBaseInfo{
|
||||
Name: v.Name(),
|
||||
Path: path.Join(req.Path, v.Name()),
|
||||
IsDir: v.IsDir(),
|
||||
Size: info.Size(),
|
||||
ModTime: info.ModTime().Unix(),
|
||||
if utils.IsImage(v.Name()) || v.IsDir() {
|
||||
item := proto.FileBaseInfo{
|
||||
Name: v.Name(),
|
||||
Path: path.Join(req.Path, v.Name()),
|
||||
IsDir: v.IsDir(),
|
||||
Size: info.Size(),
|
||||
ModTime: info.ModTime().Unix(),
|
||||
}
|
||||
list = append(list, item)
|
||||
}
|
||||
list[k] = item
|
||||
}
|
||||
|
||||
rsp.Code = http.StatusOK
|
||||
|
@ -127,13 +129,15 @@ func (rp *repo) GetInfo(ctx context.Context, req proto.ListRequest) (rsp *proto.
|
|||
goto ReturnPoint
|
||||
}
|
||||
buff := utils.ReadFile(req.Path)
|
||||
img := utils.BuffToImage(buff)
|
||||
buf := utils.ImageToBuff(img, "jpeg")
|
||||
res := new(proto.FileContent)
|
||||
res.Name = fileInfo.Name()
|
||||
res.IsDir = false
|
||||
res.Path = req.Path
|
||||
res.Size = fileInfo.Size()
|
||||
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]
|
||||
if ok {
|
||||
if b {
|
||||
|
|
|
@ -12,6 +12,8 @@ import (
|
|||
"image/jpeg"
|
||||
"image/png"
|
||||
"math"
|
||||
"path"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func BuffToImage(in []byte) image.Image {
|
||||
|
@ -153,7 +155,7 @@ func ImageToBuff(img image.Image, imgType string) *bytes.Buffer {
|
|||
case "png":
|
||||
imgType = "png"
|
||||
_ = png.Encode(buff, img)
|
||||
case "tiff":
|
||||
case "tiff", "tif":
|
||||
imgType = "tiff"
|
||||
_ = tiff.Encode(buff, img, nil)
|
||||
default:
|
||||
|
@ -214,3 +216,18 @@ func width(i image.Image) int {
|
|||
func height(i image.Image) int {
|
||||
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