<commit_before>Metrics = require "../../infrastructure/Metrics"
Project = require("../../models/Project").Project
CompileManager = require("./CompileManager")
ClsiManager = require("./ClsiManager")
logger  = require "logger-sharelatex"
request = require "request"
Settings = require "settings-sharelatex"
AuthenticationController = require "../Authentication/AuthenticationController"
UserGetter = require "../User/UserGetter"

module.exports = CompileController =
	compile: (req, res, next = (error) ->) ->
		res.setTimeout(5 * 60 * 1000)
		project_id = req.params.Project_id
		isAutoCompile = !!req.query?.auto_compile
		settingsOverride = req.body?.settingsOverride ? {};
		logger.log "root doc overriden" if settingsOverride.rootDoc_id?
		AuthenticationController.getLoggedInUserId req, (error, user_id) ->
			return next(error) if error?
			UserGetter.getUser user_id, {"features.compileGroup":1, "features.compileTimeout":1}, (err, user)->
				settingsOverride.timeout = user.features.compileTimeout || Settings.defaultFeatures.compileTimeout
				settingsOverride.compiler = user.features.compileGroup || Settings.defaultFeatures.compileGroup
				req.session.compileGroup = settingsOverride.compiler
				CompileManager.compile project_id, user_id, { isAutoCompile, settingsOverride }, (error, status, outputFiles) ->
					return next(error) if error?
					res.contentType("application/json")
					res.send 200, JSON.stringify {
						status: status
						outputFiles: outputFiles
					}

	downloadPdf: (req, res, next = (error) ->)->
		Metrics.inc "pdf-downloads"
		project_id = req.params.Project_id
		Project.findById project_id, {name: 1}, (err, project)-><commit_msg>added null check to compile features<commit_after>Metrics = require "../../infrastructure/Metrics"
Project = require("../../models/Project").Project
CompileManager = require("./CompileManager")
ClsiManager = require("./ClsiManager")
logger  = require "logger-sharelatex"
request = require "request"
Settings = require "settings-sharelatex"
AuthenticationController = require "../Authentication/AuthenticationController"
UserGetter = require "../User/UserGetter"

module.exports = CompileController =
	compile: (req, res, next = (error) ->) ->
		res.setTimeout(5 * 60 * 1000)
		project_id = req.params.Project_id
		isAutoCompile = !!req.query?.auto_compile
		settingsOverride = req.body?.settingsOverride ? {};
		logger.log "root doc overriden" if settingsOverride.rootDoc_id?
		AuthenticationController.getLoggedInUserId req, (error, user_id) ->
			return next(error) if error?
			UserGetter.getUser user_id, {"features.compileGroup":1, "features.compileTimeout":1}, (err, user)->
				settingsOverride.timeout = user?.features?.compileTimeout || Settings.defaultFeatures.compileTimeout
				settingsOverride.compiler = user?.features?.compileGroup || Settings.defaultFeatures.compileGroup
				req.session.compileGroup = settingsOverride.compiler
				CompileManager.compile project_id, user_id, { isAutoCompile, settingsOverride }, (error, status, outputFiles) ->
					return next(error) if error?
					res.contentType("application/json")
					res.send 200, JSON.stringify {
						status: status
						outputFiles: outputFiles
					}

	downloadPdf: (req, res, next = (error) ->)->
		Metrics.inc "pdf-downloads"
		project_id = req.params.Project_id
		Project.findById project_id, {name: 1}, (err, project)->
{'fraction_non_alphanumeric': 0.12836438923395446, 'fraction_numerical': 0.007690032534753032, 'mean_word_length': 4.810996563573883, 'pattern_counts': {'":': 4, '<': 3, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '417812', 'n_tokens_mistral': 1060, 'n_tokens_neox': 935, 'n_words': 210}