You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
52 lines
1.5 KiB
52 lines
1.5 KiB
11 years ago
|
"use strict";
|
||
|
|
||
8 years ago
|
import path = require("path");
|
||
|
import Archiver = require("archiver");
|
||
10 years ago
|
|
||
8 years ago
|
import reportProcessor = require("../lib/report-processor");
|
||
10 years ago
|
|
||
8 years ago
|
const getDatePart = (report) => {
|
||
8 years ago
|
if (!report.date) {
|
||
|
return "unknowndate";
|
||
|
}
|
||
10 years ago
|
|
||
8 years ago
|
const date = new Date(report.date);
|
||
|
const paddingLeft = (str, paddingValue) => String(paddingValue + str).slice(-paddingValue.length);
|
||
10 years ago
|
|
||
8 years ago
|
const year = date.getFullYear();
|
||
|
const month = paddingLeft(date.getMonth() + 1, "00");
|
||
|
const day = paddingLeft(date.getDate(), "00");
|
||
|
const hours = paddingLeft(date.getHours(), "00");
|
||
|
const minutes = paddingLeft(date.getMinutes(), "00");
|
||
|
const seconds = paddingLeft(date.getSeconds(), "00");
|
||
|
|
||
|
return `${year}.${month}.${day}.${hours}.${minutes}.${seconds}`;
|
||
10 years ago
|
};
|
||
11 years ago
|
|
||
8 years ago
|
export = (req, res, next) => {
|
||
8 years ago
|
const options = {
|
||
8 years ago
|
"branch": `/refs/heads/${req.params.branch}`,
|
||
|
"branchName": req.params.branch,
|
||
|
"owner": req.params.owner,
|
||
|
"reponame": req.params.reponame,
|
||
|
"rev": req.params.rev
|
||
8 years ago
|
};
|
||
11 years ago
|
|
||
8 years ago
|
const releasePath = path.join(req.app.get("releasepath"), options.owner, options.reponame, options.branch, options.rev);
|
||
11 years ago
|
|
||
8 years ago
|
reportProcessor.readReport(releasePath, (err, report) => {
|
||
8 years ago
|
if (err) {
|
||
|
return next(err);
|
||
|
}
|
||
10 years ago
|
|
||
8 years ago
|
const archive = new Archiver("zip");
|
||
8 years ago
|
|
||
8 years ago
|
archive.on("error", next);
|
||
8 years ago
|
res.attachment(`${options.reponame}.${getDatePart(report)}.${options.rev}.zip`, ".");
|
||
8 years ago
|
archive.pipe(res);
|
||
|
archive.directory(releasePath, false);
|
||
8 years ago
|
|
||
|
return archive.finalize();
|
||
8 years ago
|
});
|
||
11 years ago
|
};
|