Moved file attachments to be stored in data/channels instead of data/teams/ID/channels (#3416)
Этот коммит содержится в:
коммит произвёл
Christopher Speller
родитель
b9cf09b5a4
Коммит
ed75dfc6c0
37
api/file.go
37
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
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Ссылка в новой задаче
Block a user