PLT-2600/PLT-2770 Changed getPublicLink api call to return a proper JSON string (#2914)

* Removed unused channelId and userId parameters from web client getPublicLink method

* Changed getPublicLink api call to return a proper JSON string
Этот коммит содержится в:
Harrison Healey
2016-05-06 14:32:08 -04:00
коммит произвёл Corey Hulen
родитель 6c75662b82
Коммит e1cae3b15b
8 изменённых файлов: 28 добавлений и 25 удалений

Просмотреть файл

@@ -529,7 +529,7 @@ func getPublicLink(c *Context, w http.ResponseWriter, r *http.Request) {
return return
} }
w.Write([]byte(url)) w.Write([]byte(model.StringToJson(url)))
} }
func getExport(c *Context, w http.ResponseWriter, r *http.Request) { func getExport(c *Context, w http.ResponseWriter, r *http.Request) {

Просмотреть файл

@@ -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 { if r, err := c.DoApiPost(c.GetTeamRoute()+"/files/get_public_link", MapToJson(map[string]string{"filename": filename})); err != nil {
return nil, err return nil, err
} else { } 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), 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
} }
} }

Просмотреть файл

@@ -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 { func IsLower(s string) bool {
if strings.ToLower(s) == s { if strings.ToLower(s) == s {
return true return true

Просмотреть файл

@@ -281,12 +281,10 @@ export function showGetPostLinkModal(post) {
}); });
} }
export function showGetPublicLinkModal(channelId, userId, filename) { export function showGetPublicLinkModal(filename) {
AppDispatcher.handleViewAction({ AppDispatcher.handleViewAction({
type: ActionTypes.TOGGLE_GET_PUBLIC_LINK_MODAL, type: ActionTypes.TOGGLE_GET_PUBLIC_LINK_MODAL,
value: true, value: true,
channelId,
userId,
filename filename
}); });
} }

Просмотреть файл

@@ -1326,10 +1326,8 @@ export default class Client {
end(this.handleResponse.bind(this, 'getFileInfo', success, error)); end(this.handleResponse.bind(this, 'getFileInfo', success, error));
} }
getPublicLink = (channelId, userId, filename, success, error) => { getPublicLink = (filename, success, error) => {
const data = { const data = {
channel_id: channelId,
user_id: userId,
filename filename
}; };

Просмотреть файл

@@ -23,8 +23,6 @@ export default class GetPublicLinkModal extends React.Component {
this.state = { this.state = {
show: false, show: false,
channelId: '',
userId: '',
filename: '', filename: '',
link: '' link: ''
}; };
@@ -36,7 +34,7 @@ export default class GetPublicLinkModal extends React.Component {
componentDidUpdate(prevProps, prevState) { componentDidUpdate(prevProps, prevState) {
if (this.state.show && !prevState.show) { 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) { handleToggle(value, args) {
this.setState({ this.setState({
show: value, show: value,
channelId: args.channelId,
userId: args.userId,
filename: args.filename, filename: args.filename,
link: '' link: ''
}); });

Просмотреть файл

@@ -197,7 +197,7 @@ class ViewImageModal extends React.Component {
handleGetPublicLink() { handleGetPublicLink() {
this.props.onModalDismissed(); 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() { onMouseEnterImage() {

Просмотреть файл

@@ -1344,8 +1344,8 @@ export function regenCommandToken(id) {
); );
} }
export function getPublicLink(channelId, userId, filename, success, error) { export function getPublicLink(filename, success, error) {
const callName = 'getPublicLink' + channelId + userId + filename; const callName = 'getPublicLink' + filename;
if (isCallInProgress(callName)) { if (isCallInProgress(callName)) {
return; return;
@@ -1354,8 +1354,6 @@ export function getPublicLink(channelId, userId, filename, success, error) {
callTracker[callName] = utils.getTimestamp(); callTracker[callName] = utils.getTimestamp();
Client.getPublicLink( Client.getPublicLink(
channelId,
userId,
filename, filename,
(link) => { (link) => {
callTracker[callName] = 0; callTracker[callName] = 0;