diff options
-rw-r--r-- | api/file.go | 2 | ||||
-rw-r--r-- | model/client.go | 9 | ||||
-rw-r--r-- | model/utils.go | 20 | ||||
-rw-r--r-- | webapp/action_creators/global_actions.jsx | 4 | ||||
-rw-r--r-- | webapp/client/client.jsx | 4 | ||||
-rw-r--r-- | webapp/components/get_public_link_modal.jsx | 6 | ||||
-rw-r--r-- | webapp/components/view_image.jsx | 2 | ||||
-rw-r--r-- | webapp/utils/async_client.jsx | 6 |
8 files changed, 28 insertions, 25 deletions
diff --git a/api/file.go b/api/file.go index ca2aeee20..6cda48866 100644 --- a/api/file.go +++ b/api/file.go @@ -529,7 +529,7 @@ func getPublicLink(c *Context, w http.ResponseWriter, r *http.Request) { return } - w.Write([]byte(url)) + w.Write([]byte(model.StringToJson(url))) } func getExport(c *Context, w http.ResponseWriter, r *http.Request) { diff --git a/model/client.go b/model/client.go index a74adcd7a..f045401eb 100644 --- a/model/client.go +++ b/model/client.go @@ -997,15 +997,8 @@ func (c *Client) GetPublicLink(filename string) (*Result, *AppError) { if r, err := c.DoApiPost(c.GetTeamRoute()+"/files/get_public_link", MapToJson(map[string]string{"filename": filename})); err != nil { return nil, err } else { - var link string - if body, err := ioutil.ReadAll(r.Body); err == nil { - link = string(body) - } else { - // all the other Client methods return an empty string on invalid json, so we can too - } - return &Result{r.Header.Get(HEADER_REQUEST_ID), - r.Header.Get(HEADER_ETAG_SERVER), link}, nil + r.Header.Get(HEADER_ETAG_SERVER), StringFromJson(r.Body)}, nil } } diff --git a/model/utils.go b/model/utils.go index d9b06bd01..443a34bc4 100644 --- a/model/utils.go +++ b/model/utils.go @@ -178,6 +178,26 @@ func StringInterfaceFromJson(data io.Reader) map[string]interface{} { } } +func StringToJson(s string) string { + b, err := json.Marshal(s) + if err != nil { + return "" + } else { + return string(b) + } +} + +func StringFromJson(data io.Reader) string { + decoder := json.NewDecoder(data) + + var s string + if err := decoder.Decode(&s); err != nil { + return "" + } else { + return s + } +} + func IsLower(s string) bool { if strings.ToLower(s) == s { return true diff --git a/webapp/action_creators/global_actions.jsx b/webapp/action_creators/global_actions.jsx index c1bb4dbc8..6bb0c1732 100644 --- a/webapp/action_creators/global_actions.jsx +++ b/webapp/action_creators/global_actions.jsx @@ -281,12 +281,10 @@ export function showGetPostLinkModal(post) { }); } -export function showGetPublicLinkModal(channelId, userId, filename) { +export function showGetPublicLinkModal(filename) { AppDispatcher.handleViewAction({ type: ActionTypes.TOGGLE_GET_PUBLIC_LINK_MODAL, value: true, - channelId, - userId, filename }); } diff --git a/webapp/client/client.jsx b/webapp/client/client.jsx index d1e250e12..9bcbeed4e 100644 --- a/webapp/client/client.jsx +++ b/webapp/client/client.jsx @@ -1326,10 +1326,8 @@ export default class Client { end(this.handleResponse.bind(this, 'getFileInfo', success, error)); } - getPublicLink = (channelId, userId, filename, success, error) => { + getPublicLink = (filename, success, error) => { const data = { - channel_id: channelId, - user_id: userId, filename }; diff --git a/webapp/components/get_public_link_modal.jsx b/webapp/components/get_public_link_modal.jsx index 7f83651cd..c2604b3bc 100644 --- a/webapp/components/get_public_link_modal.jsx +++ b/webapp/components/get_public_link_modal.jsx @@ -23,8 +23,6 @@ export default class GetPublicLinkModal extends React.Component { this.state = { show: false, - channelId: '', - userId: '', filename: '', link: '' }; @@ -36,7 +34,7 @@ export default class GetPublicLinkModal extends React.Component { componentDidUpdate(prevProps, prevState) { if (this.state.show && !prevState.show) { - AsyncClient.getPublicLink(this.state.channelId, this.state.userId, this.state.filename, this.handlePublicLink); + AsyncClient.getPublicLink(this.state.filename, this.handlePublicLink); } } @@ -53,8 +51,6 @@ export default class GetPublicLinkModal extends React.Component { handleToggle(value, args) { this.setState({ show: value, - channelId: args.channelId, - userId: args.userId, filename: args.filename, link: '' }); diff --git a/webapp/components/view_image.jsx b/webapp/components/view_image.jsx index b88df19d4..ccde54c78 100644 --- a/webapp/components/view_image.jsx +++ b/webapp/components/view_image.jsx @@ -197,7 +197,7 @@ class ViewImageModal extends React.Component { handleGetPublicLink() { this.props.onModalDismissed(); - GlobalActions.showGetPublicLinkModal(this.props.channelId, this.props.userId, this.props.filenames[this.state.imgId]); + GlobalActions.showGetPublicLinkModal(this.props.filenames[this.state.imgId]); } onMouseEnterImage() { diff --git a/webapp/utils/async_client.jsx b/webapp/utils/async_client.jsx index ac651a7bb..1dcead326 100644 --- a/webapp/utils/async_client.jsx +++ b/webapp/utils/async_client.jsx @@ -1344,8 +1344,8 @@ export function regenCommandToken(id) { ); } -export function getPublicLink(channelId, userId, filename, success, error) { - const callName = 'getPublicLink' + channelId + userId + filename; +export function getPublicLink(filename, success, error) { + const callName = 'getPublicLink' + filename; if (isCallInProgress(callName)) { return; @@ -1354,8 +1354,6 @@ export function getPublicLink(channelId, userId, filename, success, error) { callTracker[callName] = utils.getTimestamp(); Client.getPublicLink( - channelId, - userId, filename, (link) => { callTracker[callName] = 0; |