summaryrefslogtreecommitdiffstats
path: root/api/file.go
diff options
context:
space:
mode:
authorHarrison Healey <harrisonmhealey@gmail.com>2016-06-28 14:44:06 -0400
committerChristopher Speller <crspeller@gmail.com>2016-06-28 14:44:06 -0400
commited75dfc6c090bd247ab9fe2965aed82c552bbc08 (patch)
tree7ab8e245b5090771b2fd06ec94347c3425f9e6ab /api/file.go
parentb9cf09b5a40e590cdc13ca54558fe5431835df50 (diff)
downloadchat-ed75dfc6c090bd247ab9fe2965aed82c552bbc08.tar.gz
chat-ed75dfc6c090bd247ab9fe2965aed82c552bbc08.tar.bz2
chat-ed75dfc6c090bd247ab9fe2965aed82c552bbc08.zip
Moved file attachments to be stored in data/channels instead of data/teams/ID/channels (#3416)
Diffstat (limited to 'api/file.go')
-rw-r--r--api/file.go37
1 files changed, 19 insertions, 18 deletions
diff --git a/api/file.go b/api/file.go
index 92bceaa80..048a48882 100644
--- a/api/file.go
+++ b/api/file.go
@@ -149,7 +149,7 @@ func uploadFile(c *Context, w http.ResponseWriter, r *http.Request) {
}
}
- path := "teams/" + c.TeamId + "/channels/" + channelId + "/users/" + c.Session.UserId + "/" + uid + "/" + filename
+ path := "channels/" + channelId + "/users/" + c.Session.UserId + "/" + uid + "/" + filename
if err := WriteFile(buf.Bytes(), path); err != nil {
c.Err = err
@@ -172,7 +172,7 @@ func uploadFile(c *Context, w http.ResponseWriter, r *http.Request) {
}
func handleImages(filenames []string, fileData [][]byte, teamId, channelId, userId string) {
- dest := "teams/" + teamId + "/channels/" + channelId + "/users/" + userId + "/"
+ dest := "channels/" + channelId + "/users/" + userId + "/"
for i, filename := range filenames {
name := filename[:strings.LastIndex(filename, ".")]
@@ -318,18 +318,21 @@ func getFileInfo(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
- cchan := Srv.Store.Channel().CheckPermissionsTo(c.TeamId, channelId, c.Session.UserId)
+ cchan := Srv.Store.Channel().CheckPermissionsToNoTeam(channelId, c.Session.UserId)
- path := "teams/" + c.TeamId + "/channels/" + channelId + "/users/" + userId + "/" + filename
+ path := "channels/" + channelId + "/users/" + userId + "/" + filename
var info *model.FileInfo
if cached, ok := fileInfoCache.Get(path); ok {
info = cached.(*model.FileInfo)
} else {
- fileData := make(chan []byte)
- go readFile(path, fileData)
+ err, bytes := getFileData(c.TeamId, channelId, userId, filename)
+ if err != nil {
+ c.Err = err
+ return
+ }
- newInfo, err := model.GetInfoForBytes(filename, <-fileData)
+ newInfo, err := model.GetInfoForBytes(filename, bytes)
if err != nil {
c.Err = err
return
@@ -356,7 +359,7 @@ func getFile(c *Context, w http.ResponseWriter, r *http.Request) {
userId := params["user_id"]
filename := params["filename"]
- if !c.HasPermissionsToChannel(Srv.Store.Channel().CheckPermissionsTo(teamId, channelId, userId), "getFile") {
+ if !c.HasPermissionsToChannel(Srv.Store.Channel().CheckPermissionsToNoTeam(channelId, userId), "getFile") {
return
}
@@ -414,10 +417,6 @@ func getFileData(teamId string, channelId string, userId string, filename string
return err, nil
}
- if len(teamId) != 26 {
- return NewInvalidParamError("getFileData", "team_id"), nil
- }
-
if len(channelId) != 26 {
return NewInvalidParamError("getFileData", "channel_id"), nil
}
@@ -430,17 +429,19 @@ func getFileData(teamId string, channelId string, userId string, filename string
return NewInvalidParamError("getFileData", "filename"), nil
}
- path := "teams/" + teamId + "/channels/" + channelId + "/users/" + userId + "/" + filename
+ path := "channels/" + channelId + "/users/" + userId + "/" + filename
- fileChan := make(chan []byte)
- go readFile(path, fileChan)
+ // try using the new path and then fall back to the old one if that doesn't work
+ if bytes, readErr := ReadFile(path); readErr == nil {
+ return nil, bytes
+ } else if bytes, readErr := ReadFile("teams/" + teamId + "/" + path); readErr == nil {
+ return nil, bytes
+ } else {
+ l4g.Error(readErr)
- if bytes := <-fileChan; bytes == nil {
err := model.NewLocAppError("writeFileResponse", "api.file.get_file.not_found.app_error", nil, "path="+path)
err.StatusCode = http.StatusNotFound
return err, nil
- } else {
- return nil, bytes
}
}