diff options
Diffstat (limited to 'api')
-rw-r--r-- | api/file.go | 54 | ||||
-rw-r--r-- | api/file_test.go | 7 | ||||
-rw-r--r-- | api/templates/verify_body.html | 2 | ||||
-rw-r--r-- | api/templates/welcome_body.html | 2 |
4 files changed, 31 insertions, 34 deletions
diff --git a/api/file.go b/api/file.go index 4339e610b..67ebc14b7 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) { @@ -538,7 +522,7 @@ func writeFile(f []byte, path string) *model.AppError { auth.AccessKey = utils.Cfg.FileSettings.AmazonS3AccessKeyId auth.SecretKey = utils.Cfg.FileSettings.AmazonS3SecretAccessKey - s := s3.New(auth, aws.Regions[utils.Cfg.FileSettings.AmazonS3Region]) + s := s3.New(auth, awsRegion()) bucket := s.Bucket(utils.Cfg.FileSettings.AmazonS3Bucket) ext := filepath.Ext(path) @@ -578,7 +562,7 @@ func readFile(path string) ([]byte, *model.AppError) { auth.AccessKey = utils.Cfg.FileSettings.AmazonS3AccessKeyId auth.SecretKey = utils.Cfg.FileSettings.AmazonS3SecretAccessKey - s := s3.New(auth, aws.Regions[utils.Cfg.FileSettings.AmazonS3Region]) + s := s3.New(auth, awsRegion()) bucket := s.Bucket(utils.Cfg.FileSettings.AmazonS3Bucket) // try to get the file from S3 with some basic retry logic @@ -629,3 +613,17 @@ func openFileWriteStream(path string) (io.Writer, *model.AppError) { func closeFileWriteStream(file io.Writer) { file.(*os.File).Close() } + +func awsRegion() aws.Region { + if region, ok := aws.Regions[utils.Cfg.FileSettings.AmazonS3Region]; ok { + return region + } + + return aws.Region{ + Name: utils.Cfg.FileSettings.AmazonS3Region, + S3Endpoint: utils.Cfg.FileSettings.AmazonS3Endpoint, + S3BucketEndpoint: utils.Cfg.FileSettings.AmazonS3BucketEndpoint, + S3LocationConstraint: *utils.Cfg.FileSettings.AmazonS3LocationConstraint, + S3LowercaseBucket: *utils.Cfg.FileSettings.AmazonS3LowercaseBucket, + } +} diff --git a/api/file_test.go b/api/file_test.go index b5501e4bd..b3fbd2a27 100644 --- a/api/file_test.go +++ b/api/file_test.go @@ -152,7 +152,6 @@ func TestGetFile(t *testing.T) { channel1 = Client.Must(Client.CreateChannel(channel1)).Data.(*model.Channel) if utils.Cfg.FileSettings.DriverName != "" { - body := &bytes.Buffer{} writer := multipart.NewWriter(body) part, err := writer.CreateFormFile("files", "test.png") @@ -204,9 +203,9 @@ func TestGetFile(t *testing.T) { if resp, downErr := Client.GetFileInfo(filenames[0]); downErr != nil { t.Fatal(downErr) } else { - m := resp.Data.(map[string]string) - if len(m["size"]) == 0 { - t.Fail() + info := resp.Data.(*model.FileInfo) + if info.Size == 0 { + t.Fatal("No file size returned") } } diff --git a/api/templates/verify_body.html b/api/templates/verify_body.html index 97571d9e3..c42b2a372 100644 --- a/api/templates/verify_body.html +++ b/api/templates/verify_body.html @@ -17,7 +17,7 @@ <table border="0" cellpadding="0" cellspacing="0" style="padding: 20px 50px 0; text-align: center; margin: 0 auto"> <tr> <td style="border-bottom: 1px solid #ddd; padding: 0 0 20px;"> - <h2 style="font-weight: normal; margin-top: 10px;">You've been invited</h2> + <h2 style="font-weight: normal; margin-top: 10px;">You've joined the {{ .Props.TeamDisplayName }} team</h2> <p>Please verify your email address by clicking below.</p> <p style="margin: 20px 0 15px"> <a href="{{.Props.VerifyUrl}}" style="background: #2389D7; border-radius: 3px; color: #fff; border: none; outline: none; min-width: 200px; padding: 15px 25px; font-size: 14px; font-family: inherit; cursor: pointer; -webkit-appearance: none;text-decoration: none;">Verify Email</a> diff --git a/api/templates/welcome_body.html b/api/templates/welcome_body.html index dbb94cf06..14f8e13c4 100644 --- a/api/templates/welcome_body.html +++ b/api/templates/welcome_body.html @@ -18,7 +18,7 @@ {{if .Props.VerifyUrl }} <tr> <td style="border-bottom: 1px solid #ddd; padding: 0 0 20px;"> - <h2 style="font-weight: normal; margin-top: 10px;">You've been invited</h2> + <h2 style="font-weight: normal; margin-top: 10px;">You've joined the {{ .Props.TeamDisplayName }} team</h2> <p>Please verify your email address by clicking below.</p> <p style="margin: 20px 0 15px"> <a href="{{.Props.VerifyUrl}}" style="background: #2389D7; border-radius: 3px; color: #fff; border: none; outline: none; min-width: 200px; padding: 15px 25px; font-size: 14px; font-family: inherit; cursor: pointer; -webkit-appearance: none;text-decoration: none;">Verify Email</a> |