summaryrefslogtreecommitdiffstats
path: root/api
diff options
context:
space:
mode:
authorhmhealey <harrisonmhealey@gmail.com>2015-12-16 16:48:34 -0500
committerhmhealey <harrisonmhealey@gmail.com>2015-12-18 12:24:52 -0500
commitd4a139c09afa5fc0bcdcd1276cf0d2121dbdd226 (patch)
tree65f77e593fbd64551fc64fc9f5eeeb821d8511dc /api
parent58358ddd7cd0152bf16a7326e1d595524fb51246 (diff)
downloadchat-d4a139c09afa5fc0bcdcd1276cf0d2121dbdd226.tar.gz
chat-d4a139c09afa5fc0bcdcd1276cf0d2121dbdd226.tar.bz2
chat-d4a139c09afa5fc0bcdcd1276cf0d2121dbdd226.zip
Added additional information to getFileInfo api call
Diffstat (limited to 'api')
-rw-r--r--api/file.go36
1 files changed, 10 insertions, 26 deletions
diff --git a/api/file.go b/api/file.go
index 4339e610b..d31abfb1d 100644
--- a/api/file.go
+++ b/api/file.go
@@ -23,7 +23,6 @@ import (
"image/jpeg"
"io"
"io/ioutil"
- "mime"
"net/http"
"net/url"
"os"
@@ -323,25 +322,22 @@ func getFileInfo(c *Context, w http.ResponseWriter, r *http.Request) {
cchan := Srv.Store.Channel().CheckPermissionsTo(c.Session.TeamId, channelId, c.Session.UserId)
path := "teams/" + c.Session.TeamId + "/channels/" + channelId + "/users/" + userId + "/" + filename
- size := ""
+ var info *model.FileInfo
- if s, ok := fileInfoCache.Get(path); ok {
- size = s.(string)
+ if cached, ok := fileInfoCache.Get(path); ok {
+ info = cached.(*model.FileInfo)
} else {
-
fileData := make(chan []byte)
getFileAndForget(path, fileData)
- f := <-fileData
-
- if f == nil {
- c.Err = model.NewAppError("getFileInfo", "Could not find file.", "path="+path)
- c.Err.StatusCode = http.StatusNotFound
+ newInfo, err := model.GetInfoForBytes(filename, <-fileData)
+ if err != nil {
+ c.Err = err
return
+ } else {
+ fileInfoCache.Add(path, newInfo)
+ info = newInfo
}
-
- size = strconv.Itoa(len(f))
- fileInfoCache.Add(path, size)
}
if !c.HasPermissionsToChannel(cchan, "getFileInfo") {
@@ -350,19 +346,7 @@ func getFileInfo(c *Context, w http.ResponseWriter, r *http.Request) {
w.Header().Set("Cache-Control", "max-age=2592000, public")
- var mimeType string
- ext := filepath.Ext(filename)
- if model.IsFileExtImage(ext) {
- mimeType = model.GetImageMimeType(ext)
- } else {
- mimeType = mime.TypeByExtension(ext)
- }
-
- result := make(map[string]string)
- result["filename"] = filename
- result["size"] = size
- result["mime"] = mimeType
- w.Write([]byte(model.MapToJson(result)))
+ w.Write([]byte(info.ToJson()))
}
func getFile(c *Context, w http.ResponseWriter, r *http.Request) {