<commit_before>var async = require('async');
module.exports = function threads(app, apiClient){
	app.get('/:shortname', function(req, res){
		var shortName = req.params.shortname,
			page = req.query.page;
		
		async.waterfall([
			function(_callback){
				apiClient.getBoard(shortName, function(err, board){
					_callback(err, board);
				});
			},
			function(board, _callback){
				var boardName = board.name.toLowerCase();
				apiClient.getIndexThreads(boardName, page, function(err, threads){
					_callback(err, board, threads);
				});
			}
		], function(err, board, threads){
			res.render('threads.html', {
				'board': board,
				'threads': threads
			});
		});
	});
	app.post('/:shortname', function(req, res, next){
		var shortName = req.params.shortname;

		async.waterfall([
			function(_callback){
				apiClient.getBoard(shortName, function(err, board){
					var boardName;
					if(board && board.name){
						boardName = board.name.toLowerCase();
					}
					_callback(err, boardName);
				});
			},
			function(boardName, _callback){
				apiClient.newThread({
					'board': boardName,
					'name': req.body.name,
					'email': req.body.email,
					'subject': req.body.subject,
					'comment': req.body.comment,
					'file': req.files.image,
					'sticky': 0,
					'ip': req.connection.remoteAddress,
					'closed': 0
				}, _callback);
			}
		], function(err, thread){
			if(err){
				res.json(JSON.parse(err.message));
			}

			if(thread){
				res.redirect('/' + shortName);
			}
		});
	});
}<commit_msg>Show 404 if board doesn't exist<commit_after>var async = require('async');
module.exports = function threads(app, apiClient){
	app.get('/:shortname', function(req, res){
		var shortName = req.params.shortname,
			page = req.query.page;
		
		async.waterfall([
			function(_callback){
				apiClient.getBoard(shortName, function(err, board){
					_callback(err, board);
				});
			},
			function(board, _callback){
				var boardName = board.name.toLowerCase();
				apiClient.getIndexThreads(boardName, page, function(err, threads){
					_callback(err, board, threads);
				});
			}
		], function(err, board, threads){
			if(board){
				res.render('threads.html', {
					'board': board,
					'threads': threads
				});
			}else{
				res.render('404.html');
			}
		});
	});
	app.post('/:shortname', function(req, res, next){
		var shortName = req.params.shortname;

		async.waterfall([
			function(_callback){
				apiClient.getBoard(shortName, function(err, board){
					var boardName;
					if(board && board.name){
						boardName = board.name.toLowerCase();
					}
					_callback(err, boardName);
				});
			},
			function(boardName, _callback){
				apiClient.newThread({
					'board': boardName,
					'name': req.body.name,
					'email': req.body.email,
					'subject': req.body.subject,
					'comment': req.body.comment,
					'file': req.files.image,
					'sticky': 0,
					'ip': req.connection.remoteAddress,
					'closed': 0
				}, _callback);
			}
		], function(err, thread){
			if(err){
				res.json(JSON.parse(err.message));
			}

			if(thread){
				res.redirect('/' + shortName);
			}
		});
	});
}
{'fraction_non_alphanumeric': 0.17152, 'fraction_numerical': 0.0032, 'mean_word_length': 3.1403973509933776, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '887921', 'n_tokens_mistral': 1344, 'n_tokens_neox': 1037, 'n_words': 190}