overleaf/services/web/app/src/Features/Templates/TemplatesController.js
Alasdair Smith 0ca81de78c Merge pull request #1717 from overleaf/as-decaffeinate-backend
Decaffeinate backend

GitOrigin-RevId: 4ca9f94fc809cab6f47cec8254cacaf1bb3806fa
2019-05-29 09:32:21 +00:00

69 lines
2.2 KiB
JavaScript

/* eslint-disable
camelcase,
max-len,
no-unused-vars,
*/
// TODO: This file was created by bulk-decaffeinate.
// Fix any style issues and re-enable lint.
/*
* decaffeinate suggestions:
* DS102: Remove unnecessary code created because of implicit returns
* DS207: Consider shorter variations of null checks
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
*/
let TemplatesController
const path = require('path')
const AuthenticationController = require('../Authentication/AuthenticationController')
const TemplatesManager = require('./TemplatesManager')
const ProjectHelper = require('../Project/ProjectHelper')
const logger = require('logger-sharelatex')
module.exports = TemplatesController = {
getV1Template(req, res) {
const templateVersionId = req.params.Template_version_id
const templateId = req.query.id
if (!/^[0-9]+$/.test(templateVersionId) || !/^[0-9]+$/.test(templateId)) {
logger.err(
{ templateVersionId, templateId },
'invalid template id or version'
)
return res.sendStatus(400)
}
const data = {}
data.templateVersionId = templateVersionId
data.templateId = templateId
data.name = req.query.templateName
data.compiler = ProjectHelper.compilerFromV1Engine(req.query.latexEngine)
data.imageName = req.query.texImage
data.mainFile = req.query.mainFile
data.brandVariationId = req.query.brandVariationId
return res.render(
path.resolve(
__dirname,
'../../../views/project/editor/new_from_template'
),
data
)
},
createProjectFromV1Template(req, res, next) {
const user_id = AuthenticationController.getLoggedInUserId(req)
return TemplatesManager.createProjectFromV1Template(
req.body.brandVariationId,
req.body.compiler,
req.body.mainFile,
req.body.templateId,
req.body.templateName,
req.body.templateVersionId,
user_id,
req.body.imageName,
function(err, project) {
if (err != null) {
return next(err)
}
delete req.session.templateData
return res.redirect(`/project/${project._id}`)
}
)
}
}