Worked around bug 911299 on Firefox OS

This commit is contained in:
Shuhao Wu 2013-08-30 16:45:01 -07:00
Родитель 83023595d5
Коммит 95f9123647
3 изменённых файлов: 48 добавлений и 29 удалений

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

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