<commit_before>var action = {};

/////////////////////////////////////////////////////////////////////
// metadata
action.name = "file";
action.description = "I will reutrn a static file saved on the API server (usually in /public/).  If fileName is not a param, then I will assume the path specified is the file name.  I will not return a normal API response. I will return the file with proper headers and mime-types on sucess, and a 404 on error.";
action.inputs = {
	"required" : [],
	"optional" : ["fileName"]
};
action.outputExample = {}

/////////////////////////////////////////////////////////////////////
// functional
action.run = function(api, connection, next)
{
	var fileName = connection.params.fileName || connection.req.params[0].split("/")[1];
	if (fileName == "" || fileName == null){fileName = "/";}
	fileName = api.configData.flatFileDirectory + fileName;
	api.path.exists(fileName, function(exists) {
		if(exists)
		{
			var isPath = false
			if (api.path.extname(fileName) == "" || api.path.extname(fileName).indexOf("/") > -1){
				isPath = true;
			}
			if(isPath){
				var indexPage = fileName + "index.html";
		  		api.path.exists(indexPage, function(indexExists) {
		  			if(indexExists){
		  				connection.res.sendfile(indexPage);
						next(connection, false);
		  			}else{
		  				connection.res.send(api.configData.flatFileIndexPageNotFoundMessage, 404);
						next(connection, false);
		  			}
		  		});
			}else{
		  		connection.res.sendfile(fileName);
				next(connection, false);
			}<commit_msg>better file handling<commit_after>var action = {};

/////////////////////////////////////////////////////////////////////
// metadata
action.name = "file";
action.description = "I will reutrn a static file saved on the API server (usually in /public/).  If fileName is not a param, then I will assume the path specified is the file name.  I will not return a normal API response. I will return the file with proper headers and mime-types on sucess, and a 404 on error.";
action.inputs = {
	"required" : [],
	"optional" : ["fileName"]
};
action.outputExample = {}

/////////////////////////////////////////////////////////////////////
// functional
action.run = function(api, connection, next)
{
	var fileName = "";
	if(connection.params.fileName == null || typeof connection.params.fileName == "undefined"){
		var parts = connection.req.params[0].split("/");
		parts.shift();
		for (var i in parts){
			if (fileName != ""){ fileName += "/"; }
			fileName += parts[i];
		}
	}else{
		fileName = connection.params.fileName;
	}
	fileName = api.configData.flatFileDirectory + fileName;
	api.path.exists(fileName, function(exists) {
		if(exists)
		{
			var isPath = false
			if (api.path.extname(fileName) == "" || api.path.extname(fileName).indexOf("/") > -1){
				isPath = true;
			}
			if(isPath){
				var indexPage = fileName + "index.html";
		  		api.path.exists(indexPage, function(indexExists) {
		  			if(indexExists){
		  				connection.res.sendfile(indexPage);
						next(connection, false);
		  			}else{
		  				connection.res.send(api.configData.flatFileIndexPageNotFoundMessage, 404);
						next(connection, false);
		  			}
		  		});
			}else{
		  		connection.res.sendfile(fileName);
				next(connection, false);
			}
{'fraction_non_alphanumeric': 0.21520539546290618, 'fraction_numerical': 0.005211526670754138, 'mean_word_length': 2.431125131440589, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3993835', 'n_tokens_mistral': 1069, 'n_tokens_neox': 961, 'n_words': 248}