mirror of
https://github.com/scratchfoundation/scratch-www.git
synced 2024-11-27 01:25:52 -05:00
Merge pull request #2616 from benjiwheeler/hotfix/proxy-love-favorite
[Develop] love and favorite proxy, and use x-requested-with header
This commit is contained in:
commit
dd60b692b8
3 changed files with 93 additions and 3 deletions
|
@ -574,6 +574,51 @@ module.exports.setFavedStatus = (faved, id, username, token) => (dispatch => {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
module.exports.setFavedStatusViaProxy = (faved, id, username, token) => (dispatch => {
|
||||||
|
dispatch(module.exports.setFetchStatus('faved', module.exports.Status.FETCHING));
|
||||||
|
if (faved) {
|
||||||
|
api({
|
||||||
|
uri: `/proxy/projects/${id}/favorites/user/${username}`,
|
||||||
|
authentication: token,
|
||||||
|
withCredentials: true,
|
||||||
|
method: 'POST',
|
||||||
|
useCsrf: true,
|
||||||
|
headers: {'X-Requested-With': 'XMLHttpRequest'}
|
||||||
|
}, (err, body, res) => {
|
||||||
|
if (err || res.statusCode !== 200) {
|
||||||
|
dispatch(module.exports.setError(err));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (typeof body === 'undefined') {
|
||||||
|
dispatch(module.exports.setError('Set favorites returned no data'));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
dispatch(module.exports.setFetchStatus('faved', module.exports.Status.FETCHED));
|
||||||
|
dispatch(module.exports.setFaved(body.userFavorite));
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
api({
|
||||||
|
uri: `/proxy/projects/${id}/favorites/user/${username}`,
|
||||||
|
authentication: token,
|
||||||
|
withCredentials: true,
|
||||||
|
method: 'DELETE',
|
||||||
|
useCsrf: true,
|
||||||
|
headers: {'X-Requested-With': 'XMLHttpRequest'}
|
||||||
|
}, (err, body, res) => {
|
||||||
|
if (err || res.statusCode !== 200) {
|
||||||
|
dispatch(module.exports.setError(err));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (typeof body === 'undefined') {
|
||||||
|
dispatch(module.exports.setError('Set favorites returned no data'));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
dispatch(module.exports.setFetchStatus('faved', module.exports.Status.FETCHED));
|
||||||
|
dispatch(module.exports.setFaved(false));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
module.exports.getLovedStatus = (id, username, token) => (dispatch => {
|
module.exports.getLovedStatus = (id, username, token) => (dispatch => {
|
||||||
dispatch(module.exports.setFetchStatus('loved', module.exports.Status.FETCHING));
|
dispatch(module.exports.setFetchStatus('loved', module.exports.Status.FETCHING));
|
||||||
api({
|
api({
|
||||||
|
@ -634,6 +679,51 @@ module.exports.setLovedStatus = (loved, id, username, token) => (dispatch => {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
module.exports.setLovedStatusViaProxy = (loved, id, username, token) => (dispatch => {
|
||||||
|
dispatch(module.exports.setFetchStatus('loved', module.exports.Status.FETCHING));
|
||||||
|
if (loved) {
|
||||||
|
api({
|
||||||
|
uri: `/proxy/projects/${id}/loves/user/${username}`,
|
||||||
|
authentication: token,
|
||||||
|
withCredentials: true,
|
||||||
|
method: 'POST',
|
||||||
|
useCsrf: true,
|
||||||
|
headers: {'X-Requested-With': 'XMLHttpRequest'}
|
||||||
|
}, (err, body, res) => {
|
||||||
|
if (err || res.statusCode !== 200) {
|
||||||
|
dispatch(module.exports.setError(err));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (typeof body === 'undefined') {
|
||||||
|
dispatch(module.exports.setError('Set loved returned no data'));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
dispatch(module.exports.setFetchStatus('loved', module.exports.Status.FETCHED));
|
||||||
|
dispatch(module.exports.setLoved(body.userLove));
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
api({
|
||||||
|
uri: `/proxy/projects/${id}/loves/user/${username}`,
|
||||||
|
authentication: token,
|
||||||
|
withCredentials: true,
|
||||||
|
method: 'DELETE',
|
||||||
|
useCsrf: true,
|
||||||
|
headers: {'X-Requested-With': 'XMLHttpRequest'}
|
||||||
|
}, (err, body, res) => {
|
||||||
|
if (err || res.statusCode !== 200) {
|
||||||
|
dispatch(module.exports.setError(err));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (typeof body === 'undefined') {
|
||||||
|
dispatch(module.exports.setError('Set loved returned no data'));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
dispatch(module.exports.setFetchStatus('loved', module.exports.Status.FETCHED));
|
||||||
|
dispatch(module.exports.setLoved(body.userLove));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
module.exports.getRemixes = id => (dispatch => {
|
module.exports.getRemixes = id => (dispatch => {
|
||||||
dispatch(module.exports.setFetchStatus('remixes', module.exports.Status.FETCHING));
|
dispatch(module.exports.setFetchStatus('remixes', module.exports.Status.FETCHING));
|
||||||
api({
|
api({
|
||||||
|
|
|
@ -948,7 +948,7 @@ const mapDispatchToProps = dispatch => ({
|
||||||
dispatch(previewActions.getFavedStatus(id, username, token));
|
dispatch(previewActions.getFavedStatus(id, username, token));
|
||||||
},
|
},
|
||||||
setFavedStatus: (faved, id, username, token) => {
|
setFavedStatus: (faved, id, username, token) => {
|
||||||
dispatch(previewActions.setFavedStatus(faved, id, username, token));
|
dispatch(previewActions.setFavedStatusViaProxy(faved, id, username, token));
|
||||||
},
|
},
|
||||||
getLovedStatus: (id, username, token) => {
|
getLovedStatus: (id, username, token) => {
|
||||||
dispatch(previewActions.getLovedStatus(id, username, token));
|
dispatch(previewActions.getLovedStatus(id, username, token));
|
||||||
|
@ -957,7 +957,7 @@ const mapDispatchToProps = dispatch => ({
|
||||||
dispatch(previewActions.logProjectView(id, authorUsername, token));
|
dispatch(previewActions.logProjectView(id, authorUsername, token));
|
||||||
},
|
},
|
||||||
setLovedStatus: (loved, id, username, token) => {
|
setLovedStatus: (loved, id, username, token) => {
|
||||||
dispatch(previewActions.setLovedStatus(loved, id, username, token));
|
dispatch(previewActions.setLovedStatusViaProxy(loved, id, username, token));
|
||||||
},
|
},
|
||||||
shareProject: (id, token) => {
|
shareProject: (id, token) => {
|
||||||
dispatch(previewActions.shareProject(id, token));
|
dispatch(previewActions.shareProject(id, token));
|
||||||
|
|
Loading…
Reference in a new issue