in sonic-build/routes/api.js [23:54]
async function RedirectArtifacts(req, res, next) {
var params = req.params;
var query = req.query;
var buildId = params.buildId;
if (isNaN(parseInt(buildId))){
if (buildId != 'latest'){
var message = util.format("The parameter buildId '%s' is not correct, should be a number value or the value 'laster'.", buildId);
return res.status(400).json({status: 400, message: message});
}
var build = await GetLatestBuild(req);
var value = build.value[0];
buildId = value.id;
}
var artifactUrl = util.format(artifactUrlFormat, params.organization, params.project, buildId, query.artifactName);
var artifactRes = await request('GET', artifactUrl, {headers: {"Content-type": "application/json"}});
var artifact = JSON.parse(artifactRes);
var downloadUrl = artifact.resource.downloadUrl;
if (query.subPath != null){
if (query.format != "zip"){
var queryFormat = query.format == null ? 'file' : query.format;
downloadUrl = downloadUrl.replace('format=zip', util.format('format=%s', queryFormat));
}
var subPath = query.subPath;
if (!subPath.startsWith('/')){
subPath = '/' + subPath;
}
downloadUrl = downloadUrl + "&subPath=" + encodeURIComponent(subPath);
}
res.redirect(downloadUrl);
}