mirror of
https://github.com/sudoxnym/habitica.git
synced 2026-07-12 15:05:30 +00:00
fix siteVerion check & reload page after batchUpdate if needed, @lefnire let me know what do you think and if it needs to be applied to other routes too
This commit is contained in:
parent
524796ba25
commit
9b459e37f3
2 changed files with 9 additions and 2 deletions
|
|
@ -56,7 +56,7 @@ angular.module('userServices', []).
|
|||
sent.push(queue.shift());
|
||||
});
|
||||
|
||||
$http.post(API_URL + '/api/v1/user/batch-update', sent, {params: {data:+new Date, _v:user._v}})
|
||||
$http.post(API_URL + '/api/v1/user/batch-update', sent, {params: {data:+new Date, _v:user._v, siteVersion: $window.env.siteVersion}})
|
||||
.success(function (data, status, heacreatingders, config) {
|
||||
//make sure there are no pending actions to sync. If there are any it is not safe to apply model from server as we may overwrite user data.
|
||||
if (!queue.length) {
|
||||
|
|
@ -84,6 +84,13 @@ angular.module('userServices', []).
|
|||
syncQueue(); // call syncQueue to check if anyone pushed more actions to the queue while we were talking to server.
|
||||
})
|
||||
.error(function (data, status, headers, config) {
|
||||
if(status === 400 && data.needRefresh === true){
|
||||
alert("The site has been updated and the page needs to refresh. " +
|
||||
"The last action has not been recorded, please do it again once the page reloads."
|
||||
);
|
||||
|
||||
return location.reload();
|
||||
}
|
||||
//move sent actions back to queue
|
||||
_.times(sent.length, function () {
|
||||
queue.push(sent.shift())
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ module.exports.cors = function(req, res, next) {
|
|||
var siteVersion = 0;
|
||||
|
||||
module.exports.forceRefresh = function(req, res, next){
|
||||
if(req.query.siteVersion && req.query.siteVersion !== siteVersion){
|
||||
if(req.query.siteVersion && req.query.siteVersion != siteVersion){
|
||||
return res.json(400, {needRefresh: true});
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue