<commit_before>const express = require('express');
const fs = require('fs');
const path = require('path');
const winston = require('winston');

const { version } = require('../package.json');

const router = express.Router();

const logger = winston.createLogger({
	transports: [
		new winston.transports.Console({
			format: winston.format.combine(
				winston.format.colorize(),
				winston.format.simple(),
			),
		}),
	],
});

const getLine = (stringArr, i) => {
	if (stringArr && stringArr.length > i && i >= 0) {
		return stringArr[i].trim();
	}
	return null;
};

const getLines = (stringArr, start, end) => {
	if (!end) {
	// response with single line
		return getLine(stringArr, start);
	}
	// response with multiline
	const retValue = [];
	for (let i = start; i <= end; i += 1) {
		const line = getLine(stringArr, i);
		if (line) { retValue.push(line); }
	}
	return retValue.join('\n');
};

router.get('/', (req, res, next) => {
	if (!process.env.SHOW_VERSION) {
		return res.sendStatus(403);
	}
	let sha = false;
	let branch = false;
	let message = false;
	try {
		const versionFileLines = fs.readFileSync(path.join(__dirname, '..', 'version'), 'utf8').split('\n');
		sha = getLines(versionFileLines, 0);
		branch = getLines(versionFileLines, 1);
		message = getLines(versionFileLines, 2, versionFileLines.length);
	} catch (error) {
		logger.error('version file missing', error);
	}
	return res.json({
		sha, version, branch, message,
	});
});

module.exports = router;
<commit_msg>added birthtime to version controller<commit_after>const express = require('express');
const fs = require('fs');
const path = require('path');
const winston = require('winston');

const { version } = require('../package.json');

const router = express.Router();

const logger = winston.createLogger({
	transports: [
		new winston.transports.Console({
			format: winston.format.combine(
				winston.format.colorize(),
				winston.format.simple(),
			),
		}),
	],
});

const getLine = (stringArr, i) => {
	if (stringArr && stringArr.length > i && i >= 0) {
		return stringArr[i].trim();
	}
	return null;
};

const getLines = (stringArr, start, end) => {
	if (!end) {
		// response with single line
		return getLine(stringArr, start);
	}
	// response with multiline
	const retValue = [];
	for (let i = start; i <= end; i += 1) {
		const line = getLine(stringArr, i);
		if (line) { retValue.push(line); }
	}
	return retValue.join('\n');
};

router.get('/', (req, res, next) => {
	if (!process.env.SHOW_VERSION) {
		return res.sendStatus(403);
	}
	let sha = false;
	let branch = false;
	let message = false;
	let stat = {};
	try {
		const filePath = path.join(__dirname, '..', 'version');
		const versionFileLines = fs.readFileSync(filePath, 'utf8').split('\n');
		stat = fs.statSync(filePath);
		sha = getLines(versionFileLines, 0);
		branch = getLines(versionFileLines, 1);
		message = getLines(versionFileLines, 2, versionFileLines.length);
	} catch (error) {
		logger.error('version file missing', error);
	}
	const { birthtime } = stat;
	return res.json({
		sha, version, branch, message, birthtime,
	});
});

module.exports = router;

{'fraction_non_alphanumeric': 0.1745524296675192, 'fraction_numerical': 0.005754475703324808, 'mean_word_length': 4.054927302100162, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 13, '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': '2811748', 'n_tokens_mistral': 1129, 'n_tokens_neox': 1067, 'n_words': 265}