|
|
@ -1,7 +1,48 @@ |
|
|
|
"use strict"; |
|
|
|
"use strict"; |
|
|
|
|
|
|
|
|
|
|
|
var path = require('path'); |
|
|
|
var path = require('path'), |
|
|
|
var Zip = require('adm-zip'); |
|
|
|
fs = require('fs'), |
|
|
|
|
|
|
|
Zip = require('adm-zip'); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var getReport = function(releasePath, callback) { |
|
|
|
|
|
|
|
var reportFile = releasePath + "/report.json"; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fs.exists(reportFile, function (exists) { |
|
|
|
|
|
|
|
if (!exists) { |
|
|
|
|
|
|
|
return callback("ReportFileNotFound"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return fs.readFile(reportFile, function (err, dataBuffer) { |
|
|
|
|
|
|
|
if (err) { |
|
|
|
|
|
|
|
return callback(err, options); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
var data = dataBuffer.toString(); |
|
|
|
|
|
|
|
if (!data) { |
|
|
|
|
|
|
|
return callback("ReportFileNotFound", options); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
var report = JSON.parse(data); |
|
|
|
|
|
|
|
return callback(null, report); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var getDatePart = function (report) { |
|
|
|
|
|
|
|
if (!report.date) { |
|
|
|
|
|
|
|
return "unknowndate"; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var date = new Date(report.date), |
|
|
|
|
|
|
|
paddingLeft = function (str, paddingValue) { |
|
|
|
|
|
|
|
return String(paddingValue + str).slice(-paddingValue.length); |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return date.getFullYear() + "." + |
|
|
|
|
|
|
|
paddingLeft(date.getMonth() + 1, "00") + "." + |
|
|
|
|
|
|
|
paddingLeft(date.getDate(), "00") + "." + |
|
|
|
|
|
|
|
paddingLeft(date.getHours(), "00") + "." + |
|
|
|
|
|
|
|
paddingLeft(date.getMinutes(), "00") + "." + |
|
|
|
|
|
|
|
paddingLeft(date.getSeconds(), "00"); |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
module.exports = function(req, res, next) { |
|
|
|
module.exports = function(req, res, next) { |
|
|
|
var options = { |
|
|
|
var options = { |
|
|
@ -15,11 +56,17 @@ module.exports = function(req, res, next) { |
|
|
|
var zip = new Zip(), |
|
|
|
var zip = new Zip(), |
|
|
|
releasePath = path.normalize(req.app.get('releasepath') + "/" + options.owner + "/" + options.reponame + "/" + options.branch + "/" + options.rev + "/"); |
|
|
|
releasePath = path.normalize(req.app.get('releasepath') + "/" + options.owner + "/" + options.reponame + "/" + options.branch + "/" + options.rev + "/"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
getReport(releasePath, function (err, report) { |
|
|
|
|
|
|
|
if (err) { |
|
|
|
|
|
|
|
return next(err); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
zip.addLocalFolder(releasePath); |
|
|
|
zip.addLocalFolder(releasePath); |
|
|
|
zip.toBuffer(function (buffer) { |
|
|
|
zip.toBuffer(function (buffer) { |
|
|
|
res.attachment(options.reponame + '.' + options.rev + '.zip', '.'); |
|
|
|
res.attachment(options.reponame + '.' + getDatePart(report) + '.' + options.rev + '.zip', '.'); |
|
|
|
res.send(buffer); |
|
|
|
res.send(buffer); |
|
|
|
}, function (error) { |
|
|
|
}, function (error) { |
|
|
|
next(error); |
|
|
|
next(error); |
|
|
|
}, function () { }, function () { }); |
|
|
|
}, function () { }, function () { }); |
|
|
|
|
|
|
|
}); |
|
|
|
}; |
|
|
|
}; |
|
|
|