<commit_before>
// ----------------------------------------------------------------
// ----------------------------------------------------------------
// ----------------------------------------------------------------

var libFs = require("fs");
var libPath = require("path");
var fuhahaUtil = require("./util");
var fuhahaFileServer = module.exports;

// ----------------------------------------------------------------
// ----------------------------------------------------------------
// ----------------------------------------------------------------

// ディレクトリ中身表示
module.exports.showIndex = function(req, res, directoryFiles, isRoot){
	res.writeHead(200, fuhahaUtil.header);
	res.write("<!DOCTYPE html><html><head>");
	res.write("</head><body>");

	res.write("<h1>test server</h1>");
	res.write("<hr>");

	res.write("<h2>file system</h2>");
	if(!isRoot){res.write("<a href=../>...</a></br>");}
	for(var i = 0; i < directoryFiles.length; i++){
		var name = directoryFiles[i].name + (directoryFiles[i].isDirectory ? "/" : "");
		res.write("<a href=" + libPath.join(req.url, name) + ">" + name + "</a><br>");
	}
	res.write("<hr>");

	if(isRoot){
		res.write("<h2>tools</h2>");
		res.write("<a href=/tool_image>image tool</a></br>");
		res.write("<hr>");
	}

	res.write("</body><html>");
	res.end();
};

// ファイル表示
module.exports.showFile = function(req, res, filePath){
	libFs.readFile(filePath, "binary", function(err, file){
		if(err){fuhahaUtil.showErr500(res, err); return;}

		res.writeHead(200, fuhahaUtil.header);
		res.write(file, "binary");

		 // 遅延処理
		var delay = 0.0;
		if(req.url.indexOf("/test.png") == 0){delay = 1.0;}
		setTimeout(function(){res.end();}, delay * 1000);
	});
};

// ファイルサーバ処理
module.exports.fileServer = function(req, res, filePaths){
	// ファイルサーバ起動<commit_msg>テストサーバで mime type の設定<commit_after>
// ----------------------------------------------------------------
// ----------------------------------------------------------------
// ----------------------------------------------------------------

var libFs = require("fs");
var libPath = require("path");
var fuhahaUtil = require("./util");
var fuhahaFileServer = module.exports;

// ----------------------------------------------------------------
// ----------------------------------------------------------------
// ----------------------------------------------------------------

// ディレクトリ中身表示
module.exports.showIndex = function(req, res, directoryFiles, isRoot){
	var contentType = "text/html";
	res.writeHead(200, Object.assign({}, fuhahaUtil.header, {"Content-Type": contentType,}));
	res.write("<!DOCTYPE html><html><head>");
	res.write("</head><body>");

	res.write("<h1>test server</h1>");
	res.write("<hr>");

	res.write("<h2>file system</h2>");
	if(!isRoot){res.write("<a href=../>...</a></br>");}
	for(var i = 0; i < directoryFiles.length; i++){
		var name = directoryFiles[i].name + (directoryFiles[i].isDirectory ? "/" : "");
		res.write("<a href=" + libPath.join(req.url, name) + ">" + name + "</a><br>");
	}
	res.write("<hr>");

	if(isRoot){
		res.write("<h2>tools</h2>");
		res.write("<a href=/tool_image>image tool</a></br>");
		res.write("<hr>");
	}

	res.write("</body><html>");
	res.end();
};

// ファイル表示
module.exports.showFile = function(req, res, filePath){
	libFs.readFile(filePath, "binary", function(err, file){
		if(err){fuhahaUtil.showErr500(res, err); return;}

		var prefix = libPath.extname(req.url)
		var contentType = "text/plain";
		if(prefix === ".js"){contentType = "text/javascript";}
		if(prefix === ".css"){contentType = "text/css";}
		if(prefix === ".html"){contentType = "text/html";}
		if(prefix === ".png"){contentType = "image/png";}
		if(prefix === ".m4a"){contentType = "audio/aac";}
		if(prefix === ".ogg"){contentType = "audio/ogg";}
		if(prefix === ".json"){contentType = "application/json";}
		if(prefix === ".wasm"){contentType = "application/wasm";}
		res.writeHead(200, Object.assign({}, fuhahaUtil.header, {"Content-Type": contentType,}));
		res.write(file, "binary");

		 // 遅延処理
		var delay = 0.0;
		if(req.url.indexOf("/test.png") == 0){delay = 1.0;}
		setTimeout(function(){res.end();}, delay * 1000);
	});
};

// ファイルサーバ処理
module.exports.fileServer = function(req, res, filePaths){
	// ファイルサーバ起動
{'fraction_non_alphanumeric': 0.3836744295459892, 'fraction_numerical': 0.011997177134791814, 'mean_word_length': 2.0177430801987226, 'pattern_counts': {'":': 2, '<': 55, '<?xml version=': 0, '>': 53, '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': '4866635', 'n_tokens_mistral': 1472, 'n_tokens_neox': 1385, 'n_words': 217}