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:
Benjamin Wheeler 2019-01-07 14:36:15 -05:00 committed by GitHub
commit dd60b692b8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 93 additions and 3 deletions

View file

@ -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({

View file

@ -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));