summaryrefslogtreecommitdiffstats
path: root/model/client4.go
diff options
context:
space:
mode:
Diffstat (limited to 'model/client4.go')
-rw-r--r--model/client4.go50
1 files changed, 50 insertions, 0 deletions
diff --git a/model/client4.go b/model/client4.go
index 799fec802..df09174d5 100644
--- a/model/client4.go
+++ b/model/client4.go
@@ -190,6 +190,10 @@ func (c *Client4) GetLdapRoute() string {
return fmt.Sprintf("/ldap")
}
+func (c *Client4) GetBrandRoute() string {
+ return fmt.Sprintf("/brand")
+}
+
func (c *Client4) DoApiGet(url string, etag string) (*http.Response, *AppError) {
return c.DoApiRequest(http.MethodGet, url, "", etag)
}
@@ -1498,3 +1502,49 @@ func (c *Client4) TestLdap() (bool, *Response) {
return CheckStatusOK(r), BuildResponse(r)
}
}
+
+// Brand Section
+
+// GetBrandImage retrieves the previously uploaded brand image.
+func (c *Client4) GetBrandImage() ([]byte, *Response) {
+ if r, err := c.DoApiGet(c.GetBrandRoute()+"/image", ""); err != nil {
+ return nil, &Response{StatusCode: r.StatusCode, Error: err}
+ } else if data, err := ioutil.ReadAll(r.Body); err != nil {
+ return nil, &Response{StatusCode: r.StatusCode, Error: NewAppError("GetBrandImage", "model.client.read_file.app_error", nil, err.Error(), r.StatusCode)}
+ } else {
+ return data, BuildResponse(r)
+ }
+}
+
+// UploadBrandImage sets the brand image for the system.
+func (c *Client4) UploadBrandImage(data []byte) (bool, *Response) {
+ body := &bytes.Buffer{}
+ writer := multipart.NewWriter(body)
+
+ if part, err := writer.CreateFormFile("image", "brand.png"); err != nil {
+ return false, &Response{Error: NewAppError("UploadBrandImage", "model.client.set_profile_user.no_file.app_error", nil, err.Error(), http.StatusBadRequest)}
+ } else if _, err = io.Copy(part, bytes.NewBuffer(data)); err != nil {
+ return false, &Response{Error: NewAppError("UploadBrandImage", "model.client.set_profile_user.no_file.app_error", nil, err.Error(), http.StatusBadRequest)}
+ }
+
+ if err := writer.Close(); err != nil {
+ return false, &Response{Error: NewAppError("UploadBrandImage", "model.client.set_profile_user.writer.app_error", nil, err.Error(), http.StatusBadRequest)}
+ }
+
+ rq, _ := http.NewRequest("POST", c.ApiUrl+c.GetBrandRoute()+"/image", bytes.NewReader(body.Bytes()))
+ rq.Header.Set("Content-Type", writer.FormDataContentType())
+ rq.Close = true
+
+ if len(c.AuthToken) > 0 {
+ rq.Header.Set(HEADER_AUTH, c.AuthType+" "+c.AuthToken)
+ }
+
+ if rp, err := c.HttpClient.Do(rq); err != nil {
+ return false, &Response{StatusCode: http.StatusForbidden, Error: NewAppError(c.GetBrandRoute()+"/image", "model.client.connecting.app_error", nil, err.Error(), http.StatusForbidden)}
+ } else if rp.StatusCode >= 300 {
+ return false, &Response{StatusCode: rp.StatusCode, Error: AppErrorFromJson(rp.Body)}
+ } else {
+ defer closeBody(rp)
+ return CheckStatusOK(rp), BuildResponse(rp)
+ }
+}