overleaf/services/web/app/coffee/Features/Templates/TemplatesController.coffee
James Allen 8c70d680f4 Merge pull request #1145 from sharelatex/ew-collabratec-create-project2
Collabratec create project api

GitOrigin-RevId: 5f421625baa5c48f1745a15e15fe3a18fc1a4884
2018-11-14 14:44:17 +00:00

35 lines
1.5 KiB
CoffeeScript

path = require('path')
AuthenticationController = require('../../../js/Features/Authentication/AuthenticationController')
TemplatesManager = require('./TemplatesManager')
logger = require('logger-sharelatex')
ENGINE_TO_COMPILER_MAP = {
latex_dvipdf: "latex"
pdflatex: "pdflatex"
xelatex: "xelatex"
lualatex: "lualatex"
}
module.exports = TemplatesController =
getV1Template: (req, res)->
templateVersionId = req.params.Template_version_id
templateId = req.query.id
if !/^[0-9]+$/.test(templateVersionId) || !/^[0-9]+$/.test(templateId)
logger.err templateVersionId:templateVersionId, templateId: templateId, "invalid template id or version"
return res.sendStatus 400
data = {}
data.templateVersionId = templateVersionId
data.templateId = templateId
data.name = req.query.templateName
data.compiler = ENGINE_TO_COMPILER_MAP[req.query.latexEngine]
data.mainFile = req.query.mainFile
data.brandVariationId = req.query.brandVariationId
res.render path.resolve(__dirname, "../../../views/project/editor/new_from_template"), data
createProjectFromV1Template: (req, res, next)->
user_id = AuthenticationController.getLoggedInUserId(req)
TemplatesManager.createProjectFromV1Template req.body.brandVariationId, req.body.compiler, req.body.mainFile, req.body.templateId, req.body.templateName, req.body.templateVersionId, user_id, (err, project) ->
return next err if err?
delete req.session.templateData
res.redirect "/project/#{project._id}"