filer: simplify image resize

This commit is contained in:
Chris Lu
2020-04-28 00:05:47 -07:00
parent 5c57297bd1
commit fb81f12686
2 changed files with 43 additions and 3 deletions

View File

@@ -1,6 +1,7 @@
package weed_server
import (
"bytes"
"context"
"io"
"mime"
@@ -114,8 +115,13 @@ func (fs *FilerServer) GetOrHeadHandler(w http.ResponseWriter, r *http.Request,
ext := filepath.Ext(filename)
width, height, mode, shouldResize := shouldResizeImages(ext, r)
if shouldResize {
chunkedFileReader := filer2.NewChunkStreamReaderFromFiler(fs.filer.MasterClient, entry.Chunks)
rs, _, _ := images.Resized(ext, chunkedFileReader, width, height, mode)
data, err := filer2.ReadAll(fs.filer.MasterClient, entry.Chunks)
if err != nil {
glog.Errorf("failed to read %s: %v", path, err)
w.WriteHeader(http.StatusNotModified)
return
}
rs, _, _ := images.Resized(ext, bytes.NewReader(data), width, height, mode)
io.Copy(w, rs)
return
}