Fix build logs on Safari by having the client JS handle the redirect manually, rather than the browser itself; Safari doesn't support 302 redirects to another domain inside an XHR.

This commit is contained in:
Joseph Schorr 2015-04-22 15:16:59 -04:00
parent 2b9902b72c
commit d6a1493d52
3 changed files with 68 additions and 35 deletions

View file

@ -288,9 +288,11 @@ class RepositoryBuildLogs(RepositoryParamResource):
build.repository.namespace_user.username != namespace):
raise NotFound()
# If the logs have been archived, just redirect to the completed archive
# If the logs have been archived, just return a URL of the completed archive
if build.logs_archived:
return redirect(log_archive.get_file_url(build.uuid))
return {
'logs_url': log_archive.get_file_url(build.uuid)
}
start = int(request.args.get('start', 0))

View file

@ -67,6 +67,28 @@ angular.module('quay').directive('buildLogsView', function () {
return endIndex;
};
var handleLogsData = function(logsData, callback) {
// Process the logs we've received.
$scope.logStartIndex = processLogs(logsData['logs'], logsData['start'], logsData['total']);
// If the build status is an error, open the last two log entries.
var currentBuild = $scope.currentBuild;
if (currentBuild['phase'] == 'error' && $scope.logEntries.length > 1) {
var openLogEntries = function(entry) {
if (entry.logs) {
entry.logs.setVisible(true);
}
};
openLogEntries($scope.logEntries[$scope.logEntries.length - 2]);
openLogEntries($scope.logEntries[$scope.logEntries.length - 1]);
}
// If the build phase is an error or a complete, then we mark the channel
// as closed.
callback(currentBuild['phase'] != 'error' && currentBuild['phase'] != 'complete');
}
var getBuildStatusAndLogs = function(build, callback) {
var params = {
'repository': build.repository.namespace + '/' + build.repository.name,
@ -88,25 +110,18 @@ angular.module('quay').directive('buildLogsView', function () {
};
ApiService.getRepoBuildLogsAsResource(params, true).withOptions(options).get(function(resp) {
// Process the logs we've received.
$scope.logStartIndex = processLogs(resp['logs'], resp['start'], resp['total']);
// If the build status is an error, open the last two log entries.
var currentBuild = $scope.currentBuild;
if (currentBuild['phase'] == 'error' && $scope.logEntries.length > 1) {
var openLogEntries = function(entry) {
if (entry.logs) {
entry.logs.setVisible(true);
}
};
openLogEntries($scope.logEntries[$scope.logEntries.length - 2]);
openLogEntries($scope.logEntries[$scope.logEntries.length - 1]);
// If we get a logs url back, then we need to make another XHR request to retrieve the
// data.
if (resp['logs_url']) {
$.ajax({
url: resp['logs_url'],
}).done(function(r) {
handleLogsData(r, callback);
});
return;
}
// If the build phase is an error or a complete, then we mark the channel
// as closed.
callback(currentBuild['phase'] != 'error' && currentBuild['phase'] != 'complete');
handleLogsData(resp, callback);
}, function() {
callback(false);
});

View file

@ -186,6 +186,28 @@
return endIndex;
};
var handleLogsData = function(logsData, callback) {
// Process the logs we've received.
$scope.logStartIndex = processLogs(logsData['logs'], logsData['start'], logsData['total']);
// If the build status is an error, open the last two log entries.
var currentBuild = $scope.currentBuild;
if (currentBuild['phase'] == 'error' && $scope.logEntries.length > 1) {
var openLogEntries = function(entry) {
if (entry.logs) {
entry.logs.setVisible(true);
}
};
openLogEntries($scope.logEntries[$scope.logEntries.length - 2]);
openLogEntries($scope.logEntries[$scope.logEntries.length - 1]);
}
// If the build phase is an error or a complete, then we mark the channel
// as closed.
callback(currentBuild['phase'] != 'error' && currentBuild['phase'] != 'complete');
};
var getBuildStatusAndLogs = function(build, callback) {
var params = {
'repository': namespace + '/' + name,
@ -217,24 +239,18 @@
ApiService.getRepoBuildLogsAsResource(params, true).withOptions(options).get(function(resp) {
if (build != $scope.currentBuild) { callback(false); return; }
// Process the logs we've received.
$scope.logStartIndex = processLogs(resp['logs'], resp['start'], resp['total']);
// If the build status is an error, open the last two log entries.
if (currentBuild['phase'] == 'error' && $scope.logEntries.length > 1) {
var openLogEntries = function(entry) {
if (entry.logs) {
entry.logs.setVisible(true);
}
};
openLogEntries($scope.logEntries[$scope.logEntries.length - 2]);
openLogEntries($scope.logEntries[$scope.logEntries.length - 1]);
// If we get a logs url back, then we need to make another XHR request to retrieve the
// data.
if (resp['logs_url']) {
$.ajax({
url: resp['logs_url'],
}).done(function(r) {
handleLogsData(r, callback);
});
return;
}
// If the build phase is an error or a complete, then we mark the channel
// as closed.
callback(currentBuild['phase'] != 'error' && currentBuild['phase'] != 'complete');
handleLogsData(resp, callback);
}, function() {
callback(false);
});