зеркало из https://github.com/mozilla/osumo.git
Worked around bug 911299 on Firefox OS
This commit is contained in:
Родитель
83023595d5
Коммит
95f9123647
|
@ -180,8 +180,14 @@ app.run(['$rootScope', '$location', '$q', 'AppService', 'DataService', 'L10NServ
|
|||
product = $rootScope.bundlesToUpdate[i].product;
|
||||
locale = $rootScope.bundlesToUpdate[i].locale;
|
||||
DataService.getBundleFromSource(product, locale).success(function(data, status, headers) {
|
||||
DataService.saveBundle(data, headers('X-Content-Hash'), product, locale).then(function() {
|
||||
d.resolve();
|
||||
|
||||
// Normally we just get headers('X-Content-Hash')..
|
||||
// But... bug 911299
|
||||
console.log(product, locale);
|
||||
DataService.getBundleHash(product, locale).then(function(hash) {
|
||||
DataService.saveBundle(data, hash, product, locale).then(function() {
|
||||
d.resolve();
|
||||
});
|
||||
});
|
||||
}).error(function(data, status, headers) {
|
||||
d.reject(status);
|
||||
|
|
|
@ -104,14 +104,17 @@ angular.module('osumo').controller('InstallController', ['$q', '$scope', '$rootS
|
|||
return;
|
||||
}
|
||||
|
||||
var hash = headers('X-Content-Hash');
|
||||
|
||||
DataService.saveBundle(data, hash, product, $scope.locale).then(function() {
|
||||
$scope.toast({message: L10NService._('Downloaded!'), type: 'success', autoclose: 1500});
|
||||
$scope.downloading[product] = false;
|
||||
$scope.downloaded[product] = true;
|
||||
$scope.bundles = DataService.getAvailableBundles();
|
||||
// Normally we do this, but we need to work around bug 911299
|
||||
// var hash = headers('X-Content-Hash');
|
||||
DataService.getBundleHash(product, $scope.locale).then(function(hash) {
|
||||
DataService.saveBundle(data, hash, product, $scope.locale).then(function() {
|
||||
$scope.toast({message: L10NService._('Downloaded!'), type: 'success', autoclose: 1500});
|
||||
$scope.downloading[product] = false;
|
||||
$scope.downloaded[product] = true;
|
||||
$scope.bundles = DataService.getAvailableBundles();
|
||||
});
|
||||
});
|
||||
|
||||
}).error(function(data, status, headers) {
|
||||
if (status === 0) {
|
||||
$scope.toast({message: L10NService._('It seems like you don\'t have a network connection'), type: 'error'});
|
||||
|
|
|
@ -164,6 +164,31 @@
|
|||
return deferred.promise;
|
||||
};
|
||||
|
||||
this.getBundleHash = function(product, locale) {
|
||||
var bkey = bundleKey(locale, product);
|
||||
var deferred = $q.defer();
|
||||
|
||||
var req = $http({
|
||||
url: window.SUMO_URL + 'offline/bundle-meta',
|
||||
method: 'GET',
|
||||
params: {product: product, locale: locale}
|
||||
});
|
||||
|
||||
req.success(function(data, status, headers, config) {
|
||||
if (data.error) {
|
||||
deferred.reject(data);
|
||||
} else {
|
||||
deferred.resolve(data.hash.trim());
|
||||
}
|
||||
});
|
||||
|
||||
req.error(function() {
|
||||
deferred.reject(arguments);
|
||||
});
|
||||
|
||||
return deferred.promise;
|
||||
};
|
||||
|
||||
this.checkUpdate = function(product, locale) {
|
||||
var bkey = bundleKey(locale, product);
|
||||
var deferred = $q.defer();
|
||||
|
@ -173,29 +198,14 @@
|
|||
return store.get(bkey);
|
||||
});
|
||||
|
||||
var checkRequest = $http({
|
||||
url: window.SUMO_URL + 'offline/bundle-meta',
|
||||
method: 'GET',
|
||||
params: {product: product, locale: locale}
|
||||
});
|
||||
var hashCheck = this.getBundleHash(product, locale);
|
||||
|
||||
checkRequest.success(function(data, status, headers, config) {
|
||||
hashCheck.then(function(hash) {
|
||||
currentVersionPromise.then(function(currentVersionHash) {
|
||||
if (!data.error) {
|
||||
console.log(data.hash, currentVersionHash);
|
||||
deferred.resolve(data.hash.trim() !== currentVersionHash);
|
||||
} else {
|
||||
deferred.resolve(false);
|
||||
}
|
||||
deferred.resolve(hash !== currentVersionHash);
|
||||
});
|
||||
});
|
||||
|
||||
checkRequest.error(function(data, status, headers, config) {
|
||||
if (status === 404 || status === 503) {
|
||||
// In this case the server might not have the hash yet as it is
|
||||
// not generated or redis is down. So we say that our version is okay
|
||||
deferred.resolve(false);
|
||||
}
|
||||
}, function() {
|
||||
deferred.resolve(false);
|
||||
});
|
||||
|
||||
deferred.promise.then(function() {
|
||||
|
|
Загрузка…
Ссылка в новой задаче