lib/commandCenter/httpBatchHandler.js
function parseBatchData(fullPath, req, rawData, files) {
	assert.equal(typeof fullPath, 'string', 'invalidPath');

	var commandNames = fullPath.substr(fullPath.lastIndexOf('/') + 1).split(',');
	var commandCount = commandNames.length;
	var commands = new Array(commandCount);

	// split the string into lines

	var cmdData = rawData.split('\n');

	// line 0 is the header

	var header;

	try {
		header = JSON.parse(cmdData[0]);
	} catch (error) {
		logger.error
			.data('data', cmdData[0])
			.data('error', error.message)
			.log('Error parsing command header.');
	}

	assert(Array.isArray(header), 'invalid command header');

	for (var i = 0; i < commandCount; i++) {
		var commandData = cmdData[i + 1]; // +1 to offset the header at index 0

		var params;
		try {
			params = JSON.parse(commandData) || {};
		} catch (e) {
			logger.error.data(commandData).log('Error parsing command data.');
			throw e;
		}

		if (files) {
			resolveFilesInParams(params, files);
		}

		commands[i] = {
			name: commandNames[i],
			params: params
		};
	}

	return {
		transport: {
			type: 'http',
			req: req
		},
		rawData: rawData,           // useful for hashing
		header: header,
		commands: commands,
		commandNames: commandNames  // useful for logging
	};
}
function parseBatchData(fullPath, req, rawData, files) {
	assert.equal(typeof fullPath, 'string', 'invalidPath');

	var commandNames = fullPath.substr(fullPath.lastIndexOf('/') + 1).split(',');
	var commandCount = commandNames.length;
	var commands = new Array(commandCount);

	// split the string into lines

	var cmdData = rawData.split('\n');

	// line 0 is the header

	var header;

	try {
		header = JSON.parse(cmdData[0]);
	} catch (error) {
		logger.error
			.data('data', cmdData[0])
			.data('error', error.message)
			.log('Error parsing command header.');
	}

	assert(Array.isArray(header), 'invalid command header');

	for (var i = 0; i < commandCount; i++) {
		var commandData = cmdData[i + 1]; // +1 to offset the header at index 0

		var params;
		try {
			params = JSON.parse(commandData) || {};
		} catch (e) {
			logger.error.data(commandData).log('Error parsing command data.');
			throw e;
		}

		if (files) {
			resolveFilesInParams(params, files);
		}

		commands[i] = {
			name: commandNames[i],
			params: params
		};
	}

	return {
		transport: {
			type: 'http',
			req: req
		},
		rawData: rawData,           // useful for hashing
		header: header,
		commands: commands,
		commandNames: commandNames  // useful for logging
	};
}
function parseBatchData ( fullPath , req , rawData , files ) { assert . equal ( typeof fullPath , 'string' , 'invalidPath' ) ; var commandNames = fullPath . substr ( fullPath . lastIndexOf ( '/' ) + 1 ) . split ( ',' ) ; var commandCount = commandNames . length ; var commands = new Array ( commandCount ) ; // split the string into lines var cmdData = rawData . split ( '\n' ) ; // line 0 is the header var header ; try { header = JSON . parse ( cmdData [ 0 ] ) ; } catch ( error ) { logger . error . data ( 'data' , cmdData [ 0 ] ) . data ( 'error' , error . message ) . log ( 'Error parsing command header.' ) ; } assert ( Array . isArray ( header ) , 'invalid command header' ) ; for ( var i = 0 ; i < commandCount ; i ++ ) { var commandData = cmdData [ i + 1 ] ; // +1 to offset the header at index 0 var params ; try { params = JSON . parse ( commandData ) || { } ; } catch ( e ) { logger . error . data ( commandData ) . log ( 'Error parsing command data.' ) ; throw e ; } if ( files ) { resolveFilesInParams ( params , files ) ; } commands [ i ] = { name : commandNames [ i ] , params : params } ; } return { transport : { type : 'http' , req : req } , rawData : rawData , // useful for hashing header : header , commands : commands , commandNames : commandNames // useful for logging } ; }
Parses the uploaded data and files into a batch object

@param {string} fullPath   The full path of the HTTP request.
@param {Object} req        The HTTP request object.
@param {string} rawData    The POST data that contains the command parameters.
@param {Object} [files]    Any uploaded files.
@returns {Object}          The batch.
Parses the uploaded data and files into a batch object