summaryrefslogtreecommitdiffstats
path: root/api/file.go
diff options
context:
space:
mode:
author=Corey Hulen <corey@hulen.com>2015-08-02 09:41:12 -0800
committer=Corey Hulen <corey@hulen.com>2015-08-02 09:41:12 -0800
commit247708d924770737a3c03f956b19d8096da2bdea (patch)
tree3d6bd381545e660808f74a1379048e57cc0c6717 /api/file.go
parente76fc37b6df7d53ea86a5b42009d5d1161741270 (diff)
parent718d670d699e295fcad903d507bc989c51a1ef50 (diff)
downloadchat-247708d924770737a3c03f956b19d8096da2bdea.tar.gz
chat-247708d924770737a3c03f956b19d8096da2bdea.tar.bz2
chat-247708d924770737a3c03f956b19d8096da2bdea.zip
Merge branch 'master' into mm-1619
Diffstat (limited to 'api/file.go')
-rw-r--r--api/file.go20
1 files changed, 15 insertions, 5 deletions
diff --git a/api/file.go b/api/file.go
index 3ef50fbbd..4ec421eb9 100644
--- a/api/file.go
+++ b/api/file.go
@@ -33,7 +33,7 @@ func InitFile(r *mux.Router) {
sr := r.PathPrefix("/files").Subrouter()
sr.Handle("/upload", ApiUserRequired(uploadFile)).Methods("POST")
- sr.Handle("/get/{channel_id:[A-Za-z0-9]+}/{user_id:[A-Za-z0-9]+}/{filename:([A-Za-z0-9]+/)?.+(\\.[A-Za-z0-9]{3,})?}", ApiAppHandler(getFile)).Methods("GET")
+ sr.Handle("/get/{channel_id:[A-Za-z0-9]+}/{user_id:[A-Za-z0-9]+}/{filename:([A-Za-z0-9]+/)?.+(\\.[A-Za-z0-9]{3,})?}", ApiAppHandler(getFile)).Methods("GET", "HEAD")
sr.Handle("/get_public_link", ApiUserRequired(getPublicLink)).Methods("POST")
}
@@ -140,11 +140,18 @@ func fireAndForgetHandleImages(filenames []string, fileData [][]byte, teamId, ch
// Create thumbnail
go func() {
+ thumbWidth := float64(utils.Cfg.ImageSettings.ThumbnailWidth)
+ thumbHeight := float64(utils.Cfg.ImageSettings.ThumbnailHeight)
+ imgWidth := float64(imgConfig.Width)
+ imgHeight := float64(imgConfig.Height)
+
var thumbnail image.Image
- if imgConfig.Width > int(utils.Cfg.ImageSettings.ThumbnailWidth) {
- thumbnail = resize.Resize(utils.Cfg.ImageSettings.ThumbnailWidth, utils.Cfg.ImageSettings.ThumbnailHeight, img, resize.Lanczos3)
- } else {
+ if imgHeight < thumbHeight && imgWidth < thumbWidth {
thumbnail = img
+ } else if imgHeight/imgWidth < thumbHeight/thumbWidth {
+ thumbnail = resize.Resize(0, utils.Cfg.ImageSettings.ThumbnailHeight, img, resize.Lanczos3)
+ } else {
+ thumbnail = resize.Resize(utils.Cfg.ImageSettings.ThumbnailWidth, 0, img, resize.Lanczos3)
}
buf := new(bytes.Buffer)
@@ -261,7 +268,10 @@ func getFile(c *Context, w http.ResponseWriter, r *http.Request) {
w.Header().Set("Cache-Control", "max-age=2592000, public")
w.Header().Set("Content-Length", strconv.Itoa(len(f)))
- w.Write(f)
+
+ if r.Method != "HEAD" {
+ w.Write(f)
+ }
}
func asyncGetFile(path string, fileData chan []byte) {