Add support for .tar.gz build packs in the build package viewer

This commit is contained in:
Joseph Schorr 2014-04-01 00:23:53 -04:00
parent e7c20e1052
commit 35f69b9f5b
10 changed files with 480 additions and 95 deletions

View file

@ -185,24 +185,147 @@ quayApp = angular.module('quay', ['ngRoute', 'chieffancypants.loadingBar', 'angu
return service;
}]);
$provide.factory('UtilService', ['$sanitize', function($sanitize) {
var utilService = {};
utilService.textToSafeHtml = function(text) {
var adjusted = text.replace(/&/g, "&")
.replace(/</g, "&lt;")
.replace(/>/g, "&gt;")
.replace(/"/g, "&quot;")
.replace(/'/g, "&#039;");
$provide.factory('DataFileService', [function() {
var dataFileService = {};
return $sanitize(adjusted);
dataFileService.getName_ = function(filePath) {
var parts = filePath.split('/');
return parts[parts.length - 1];
};
dataFileService.tryAsZip_ = function(buf, success, failure) {
var zip = null;
var zipFiles = null;
try {
var zip = new JSZip(buf);
zipFiles = zip.files;
} catch (e) {
failure();
return;
}
var files = [];
for (var filePath in zipFiles) {
if (zipFiles.hasOwnProperty(filePath)) {
files.push({
'name': dataFileService.getName_(filePath),
'path': filePath,
'canRead': true,
'toBlob': (function(fp) {
return function() {
return new Blob([zip.file(fp).asArrayBuffer()]);
};
}(filePath))
});
}
}
success(files);
};
dataFileService.tryAsTarGz_ = function(buf, success, failure) {
var gunzip = new Zlib.Gunzip(buf);
var plain = gunzip.decompress();
var handler = new MultiFile();
handler.files = [];
handler.processTarChunks(dataFileService.arrayToString(plain), 0);
if (!handler.files.length) {
failure();
return;
}
var files = [];
for (var i = 0; i < handler.files.length; ++i) {
var currentFile = handler.files[i];
files.push({
'name': dataFileService.getName_(currentFile.filename),
'path': currentFile.filename,
'canRead': true,
'toBlob': (function(currentFile) {
return function() {
return new Blob([currentFile.data], {type: 'application/octet-binary'});
};
}(currentFile))
});
}
success(files);
};
dataFileService.blobToString = function(blob, callback) {
var reader = new FileReader();
reader.onload = function(event){
callback(reader.result);
};
reader.readAsText(blob);
};
dataFileService.arrayToString = function(buf) {
return String.fromCharCode.apply(null, new Uint16Array(buf));
};
dataFileService.readDataArrayAsPossibleArchive = function(buf, success, failure) {
dataFileService.tryAsZip_(buf, success, function() {
dataFileService.tryAsTarGz_(buf, success, failure);
});
};
dataFileService.downloadDataFileAsArrayBuffer = function($scope, url, progress, error, loaded) {
var request = new XMLHttpRequest();
request.open('GET', url, true);
request.responseType = 'arraybuffer';
request.onprogress = function(e) {
$scope.$apply(function() {
var percentLoaded;
if (e.lengthComputable) {
progress(e.loaded / e.total);
}
});
};
request.onerror = function() {
$scope.$apply(function() {
error();
});
};
request.onload = function() {
if (this.status == 200) {
$scope.$apply(function() {
var uint8array = new Uint8Array(request.response);
loaded(uint8array);
});
return;
}
};
request.send();
};
return dataFileService;
}]);
$provide.factory('UtilService', ['$sanitize', function($sanitize) {
var utilService = {};
utilService.textToSafeHtml = function(text) {
var adjusted = text.replace(/&/g, "&amp;")
.replace(/</g, "&lt;")
.replace(/>/g, "&gt;")
.replace(/"/g, "&quot;")
.replace(/'/g, "&#039;");
return $sanitize(adjusted);
};
return utilService;
}]);
$provide.factory('TriggerDescriptionBuilder', ['UtilService', '$sanitize', function(UtilService, $sanitize) {
$provide.factory('TriggerDescriptionBuilder', ['UtilService', '$sanitize', function(UtilService, $sanitize) {
var builderService = {};
builderService.getDescription = function(name, config) {