data['transaction_id'] = result[0].body['output']['transaction-id'];
// Add a status checker on the transaction and then to delete the file later
- PackageFileHandler.checkCreatePackageStatusAndHandleFile(req, data['transaction_id'], true);
+ PackageFileHandler.checkCreatePackageStatusAndHandleFile(req, data['transaction_id'], false);
// Return status to composer UI to update the status.
resolve({
uri: uri,
method: 'POST',
headers: _.extend({}, constants.HTTP_HEADERS.accept.collection, {
- 'Authorization': req.get('Authorization')
+ 'Authorization': req.session && req.session.authorization
}),
forever: constants.FOREVER_ON,
rejectUnauthorized: false,
}
/**
- * This methods retrieves the status of package operations. It takes an optional
+ * This methods retrieves the status of package operations. It takes an optional
* transaction id (id) this if present will return only that status otherwise
* an array of status' will be response.
*/
url: url,
method: 'GET',
headers: _.extend({}, constants.HTTP_HEADERS.accept.data, {
- 'Authorization': req.get('Authorization')
+ 'Authorization': req.session && req.session.authorization
}),
forever: constants.FOREVER_ON,
rejectUnauthorized: false
}, function(error, response, body) {
- if (utils.validateResponse('restconfAPI.streams', error, response, body, resolve, reject)) {
+ if (utils.validateResponse('PackageManager.getJobStatus', error, response, body, resolve, reject)) {
var returnData;
if (id) {
returnData = JSON.parse(response.body)['rw-pkg-mgmt:job'];
})
}
+function makeAssetTypeParamName (type) {
+ return type.toLowerCase() + '-file-type';
+}
FileManager.addFile = function(req) {
console.log(' Uploading file', req.file.originalname, 'as', req.file.filename);
var api_server = req.query['api_server'];
var package_id = req.query['package_id'];
var package_type = req.query['package_type'].toUpperCase();
var package_path = req.query['package_path'];
- if (!download_host) {
+ if (!download_host) {
download_host = req.protocol + '://' + req.get('host');//api_server + ':' + utils.getPortForProtocol(req.protocol);
}
var input = {
'external-url': download_host + '/composer/upload/' + req.query['package_id'] + '/' + req.file.filename,
'package-type': package_type,
'package-id': package_id,
- 'package-path': package_path + '/' + req.file.filename
+ 'package-path': package_path ? package_path + '/' + req.file.filename : req.file.filename
};
var uri = utils.projectContextUrl(req, utils.confdPort(api_server) + '/api/operations/package-file-add');
input = utils.addProjectContextToRPCPayload(req, uri, input);
-
+ var assetType = req.query['asset_type'].toUpperCase();
+ input[makeAssetTypeParamName(package_type)] = assetType;
return new Promise(function(resolve, reject) {
Promise.all([
rp({
uri: uri,
method: 'POST',
headers: _.extend({}, constants.HTTP_HEADERS.accept.collection, {
- 'Authorization': req.get('Authorization')
+ 'Authorization': req.session && req.session.authorization
}),
forever: constants.FOREVER_ON,
rejectUnauthorized: false,
var id = req.query['package_id'];
var downloadUrl = req.query['url'];
var path = req.query['package_path'];
- var payload = {
- "input": {
- "package-type": type,
- "package-id": id
- }
+ var assetType = req.query['asset_type'];
+ var input = {
+ "package-type": type,
+ "package-id": id
}
+ var payload = {input: input};
if(req.method == 'GET') {
if(downloadUrl && path) {
payload.input['external-url'] = downloadUrl;
payload.input['package-path'] = path;
+ payload.input[makeAssetTypeParamName(type)] = assetType;
return download(payload);
} else {
return list(payload);
}
if(req.method == 'DELETE') {
payload.input['package-path'] = path;
+ payload.input[makeAssetTypeParamName(type)] = assetType;
return deleteFile(payload)
}