<commit_before>'use strict';

var _ = require("lodash");
var youtransfer = require("./youtransfer.js");

module.exports = function(app, nconf) {

	app.post(/^\/upload/, function(req, res, next) {
		var settings = youtransfer.settings.get();
		var isXmlHtppRequest = req.files['dz-payload'];
		var file = req.files.payload || req.files['dz-payload'];
		youtransfer.upload(file, function(err, context) {
			var response = _.assign({
				success: _.isNull(err),
				isPostback: true, 
				isXmlHtppRequest: _.isNull(isXmlHtppRequest) ? false : true,
				link: settings.baseUrl + '/download/' + context.id + '/',
				error: (err ? err.message : '')
			}, context);

			if(isXmlHtppRequest) {
				res.json(response);
			} else {
				res.render("index.html", response);
			}
		});
	});

	app.get(/^\/download\/(.*)\//, function(req, res, next) {
		var token = req.params[0];
		youtransfer.download(token, res);
	});

	app.post(/^\/download/, function(req, res, next) {
		var token = req.params.token;
		youtransfer.download(token, res);
	});

	app.post(/^\/settings/, function(req, res, next) {
		var settings = req.params["settings"];
		youtransfer.settings.push(settings, function(err) {
			res.setHeader('Cache-Control', 'private, max-age=0, proxy-revalidate, no-store, no-cache, must-revalidate');
			res.render("settings.html", {<commit_msg>#24 Add support for Amazon S3 file upload Forgot to add control-flow function after refactoring the youtransfer.js module and introducing the StorageFactory object<commit_after>'use strict';

var _ = require("lodash");
var youtransfer = require("./youtransfer.js");

module.exports = function(app, nconf) {

	app.post(/^\/upload/, function(req, res, next) {
		var settings = youtransfer.settings.get();
		var isXmlHtppRequest = req.files['dz-payload'];
		var file = req.files.payload || req.files['dz-payload'];
		youtransfer.upload(file, function(err, context) {
			var response = _.assign({
				success: _.isNull(err),
				isPostback: true, 
				isXmlHtppRequest: _.isNull(isXmlHtppRequest) ? false : true,
				link: settings.baseUrl + '/download/' + context.id + '/',
				error: (err ? err.message : '')
			}, context);

			if(isXmlHtppRequest) {
				res.json(response);
			} else {
				res.render("index.html", response);
			}
		});
	});

	app.get(/^\/download\/(.*)\//, function(req, res, next) {
		var token = req.params[0];
		youtransfer.download(token, res, function(err) {
			res.redirect("/");
		});
	});

	app.post(/^\/download/, function(req, res, next) {
		var token = req.params.token;
		youtransfer.download(token, res, function(err) {
			res.redirect("/");
		});
	});

	app.post(/^\/settings/, function(req, res, next) {
		var settings = req.params["settings"];
		youtransfer.settings.push(settings, function(err) {
			res.setHeader('Cache-Control', 'private, max-age=0, proxy-revalidate, no-store, no-cache, must-revalidate');
			res.render("settings.html", {
{'fraction_non_alphanumeric': 0.18415637860082304, 'fraction_numerical': 0.0024005486968449933, 'mean_word_length': 3.8697829716193657, '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': 10, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4388224', 'n_tokens_mistral': 1105, 'n_tokens_neox': 991, 'n_words': 198}