<commit_before>import * as express from "express"
import * as bodyParser from "body-parser"

import * as aiRepo from './repo/artistImageRepo'
import * as fiRepo from './repo/flatImageRepo'
import {PixivRepo} from './repo/model'

import * as Proto from '../common/proto'

import * as q from 'q'
import * as yargs from 'yargs'
import * as log4js from 'log4js'

log4js.configure({
	appenders: [
		{ type: 'console' }
	]
});
let logger = log4js.getLogger('Startup');

let cliArgs = yargs
				.usage('Usage: $0 --repo artist|flat --path <path_string>')
				.count('verbose')
			    .alias('v', 'verbose')
				.argv;

if (cliArgs.verbose && cliArgs.verbose > 0) {
	log4js.setGlobalLogLevel(log4js.levels.ALL);
	logger.warn('Setting to verbose mode');
} else {
	log4js.setGlobalLogLevel(log4js.levels.INFO);
}

let defaultPath = 'pixivRepository';
if (!cliArgs.path) {
	logger.warn('No path specified, using default');
}
let path = cliArgs.path || defaultPath;
logger.info(`Setting repo to path [${path}]`);

function decideRepo() : PixivRepo {
	switch (cliArgs.repo) {
		case "artist":
			logger.info('Using [root/artist/images*] repo format');
			return new aiRepo.ArtistImageRepo(path);
		case "flat":
			logger.info('Using [root/images*] repo format');
			return new fiRepo.ImageRepo(path);
		default:
			logger.warn('No repository format specified, using default');
			logger.info('Using [root/artist/images*] repo format');
			return new aiRepo.ArtistImageRepo(path);
	}
}
let pas = decideRepo();

process.on('SIGINT', function() {
	let mainLogger = log4js.getLogger('Main');
	mainLogger.warn('Closing server');
	pas.teardown();
    process.exit();
});

let appLogger = log4js.getLogger('App');
let app = express();

app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());

app.get('/ping', (req, res) => {
	appLogger.debug('Message Received | Ping');
	res.json(true);
});

app.get('/supports/:action', (req, res) => {
	let action: string = req.params.action;
	appLogger.debug('Message Received | Supports action [', action, ']');
	res.json(pas.supports(action));
});

app.post('/:action', (req, res) => {
	let action: string = req.params.action;
	let message: any = req.body;
	appLogger.debug('Message Received | Perform action [', action, ']');
	q(message)
		.then(msg => pas.dispatch(action, msg))
		.then<Proto.Messages.Response>(
			successfulResponse => ({ success: true, data: successfulResponse }), 
			failedResponse => ({ success: false, errors: failedResponse }))
		.then(result => res.json(result));
});

app.listen('9002', () => {
	let mainLogger = log4js.getLogger('Main');
	mainLogger.info('listening on port 9002');
})
<commit_msg>Included a warning message about ctrl+C<commit_after>import * as express from "express"
import * as bodyParser from "body-parser"

import * as aiRepo from './repo/artistImageRepo'
import * as fiRepo from './repo/flatImageRepo'
import {PixivRepo} from './repo/model'

import * as Proto from '../common/proto'

import * as q from 'q'
import * as yargs from 'yargs'
import * as log4js from 'log4js'

log4js.configure({
	appenders: [
		{ type: 'console' }
	]
});
let logger = log4js.getLogger('Startup');

let cliArgs = yargs
				.usage('Usage: $0 --repo artist|flat --path <path_string>')
				.count('verbose')
			    .alias('v', 'verbose')
				.argv;

if (cliArgs.verbose && cliArgs.verbose > 0) {
	log4js.setGlobalLogLevel(log4js.levels.ALL);
	logger.warn('Setting to verbose mode');
} else {
	log4js.setGlobalLogLevel(log4js.levels.INFO);
}

let defaultPath = 'pixivRepository';
if (!cliArgs.path) {
	logger.warn('No path specified, using default');
}
let path = cliArgs.path || defaultPath;
logger.info(`Setting repo to path [${path}]`);

function decideRepo() : PixivRepo {
	switch (cliArgs.repo) {
		case "artist":
			logger.info('Using [root/artist/images*] repo format');
			return new aiRepo.ArtistImageRepo(path);
		case "flat":
			logger.info('Using [root/images*] repo format');
			return new fiRepo.ImageRepo(path);
		default:
			logger.warn('No repository format specified, using default');
			logger.info('Using [root/artist/images*] repo format');
			return new aiRepo.ArtistImageRepo(path);
	}
}
let pas = decideRepo();

logger.warn('You MUST use <ctrl>+c to exit the server safely. Database may not save otherwise');

process.on('SIGINT', function() {
	let mainLogger = log4js.getLogger('Main');
	mainLogger.warn('Closing server');
	pas.teardown();
    process.exit();
});

let appLogger = log4js.getLogger('App');
let app = express();

app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());

app.get('/ping', (req, res) => {
	appLogger.debug('Message Received | Ping');
	res.json(true);
});

app.get('/supports/:action', (req, res) => {
	let action: string = req.params.action;
	appLogger.debug('Message Received | Supports action [', action, ']');
	res.json(pas.supports(action));
});

app.post('/:action', (req, res) => {
	let action: string = req.params.action;
	let message: any = req.body;
	appLogger.debug('Message Received | Perform action [', action, ']');
	q(message)
		.then(msg => pas.dispatch(action, msg))
		.then<Proto.Messages.Response>(
			successfulResponse => ({ success: true, data: successfulResponse }), 
			failedResponse => ({ success: false, errors: failedResponse }))
		.then(result => res.json(result));
});

app.listen('9002', () => {
	let mainLogger = log4js.getLogger('Main');
	mainLogger.info('listening on port 9002');
})

{'fraction_non_alphanumeric': 0.17288693743139408, 'fraction_numerical': 0.007683863885839737, 'mean_word_length': 4.6302780638517, 'pattern_counts': {'":': 4, '<': 8, '<?xml version=': 0, '>': 26, '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': '1778302', 'n_tokens_mistral': 1926, 'n_tokens_neox': 1866, 'n_words': 447}