2020-02-25 11:15:31 -05:00
|
|
|
const request = require('request')
|
2021-07-12 12:47:21 -04:00
|
|
|
const Settings = require('@overleaf/settings')
|
2014-02-12 12:27:43 -05:00
|
|
|
|
2021-07-13 07:04:48 -04:00
|
|
|
const buildUrl = path =>
|
2020-02-25 11:15:31 -05:00
|
|
|
`http://${Settings.internal.clsi.host}:${Settings.internal.clsi.port}/${path}`
|
2014-02-12 12:27:43 -05:00
|
|
|
|
2020-02-25 11:15:31 -05:00
|
|
|
const url = buildUrl(`project/smoketest-${process.pid}/compile`)
|
2016-06-07 09:38:17 -04:00
|
|
|
|
2020-05-07 12:57:35 -04:00
|
|
|
module.exports = {
|
|
|
|
sendNewResult(res) {
|
2021-07-13 07:04:48 -04:00
|
|
|
this._run(error => this._sendResponse(res, error))
|
2020-05-07 12:57:35 -04:00
|
|
|
},
|
|
|
|
sendLastResult(res) {
|
|
|
|
this._sendResponse(res, this._lastError)
|
|
|
|
},
|
|
|
|
triggerRun(cb) {
|
2021-07-13 07:04:48 -04:00
|
|
|
this._run(error => {
|
2020-05-07 12:57:35 -04:00
|
|
|
this._lastError = error
|
|
|
|
cb(error)
|
|
|
|
})
|
|
|
|
},
|
|
|
|
|
|
|
|
_lastError: new Error('SmokeTestsPending'),
|
|
|
|
_sendResponse(res, error) {
|
|
|
|
let code, body
|
|
|
|
if (error) {
|
|
|
|
code = 500
|
|
|
|
body = error.message
|
|
|
|
} else {
|
|
|
|
code = 200
|
|
|
|
body = 'OK'
|
|
|
|
}
|
|
|
|
res.contentType('text/plain')
|
|
|
|
res.status(code).send(body)
|
|
|
|
},
|
|
|
|
_run(done) {
|
|
|
|
request.post(
|
2020-02-25 11:15:31 -05:00
|
|
|
{
|
|
|
|
url,
|
|
|
|
json: {
|
|
|
|
compile: {
|
|
|
|
resources: [
|
|
|
|
{
|
|
|
|
path: 'main.tex',
|
|
|
|
content: `\
|
2017-12-05 11:51:59 -05:00
|
|
|
% Membrane-like surface
|
|
|
|
% Author: Yotam Avital
|
|
|
|
\\documentclass{article}
|
|
|
|
\\usepackage{tikz}
|
|
|
|
\\usetikzlibrary{calc,fadings,decorations.pathreplacing}
|
|
|
|
\\begin{document}
|
|
|
|
\\begin{tikzpicture}
|
|
|
|
\\def\\nuPi{3.1459265}
|
|
|
|
\\foreach \\i in {5,4,...,2}{% This one doesn't matter
|
|
|
|
\\foreach \\j in {3,2,...,0}{% This will crate a membrane
|
|
|
|
% with the front lipids visible
|
|
|
|
% top layer
|
|
|
|
\\pgfmathsetmacro{\\dx}{rand*0.1}% A random variance in the x coordinate
|
|
|
|
\\pgfmathsetmacro{\\dy}{rand*0.1}% A random variance in the y coordinate,
|
|
|
|
% gives a hight fill to the lipid
|
|
|
|
\\pgfmathsetmacro{\\rot}{rand*0.1}% A random variance in the
|
2020-05-07 12:57:35 -04:00
|
|
|
% molecule orientation
|
2017-12-05 11:51:59 -05:00
|
|
|
\\shade[ball color=red] ({\\i+\\dx+\\rot},{0.5*\\j+\\dy+0.4*sin(\\i*\\nuPi*10)}) circle(0.45);
|
|
|
|
\\shade[ball color=gray] (\\i+\\dx,{0.5*\\j+\\dy+0.4*sin(\\i*\\nuPi*10)-0.9}) circle(0.45);
|
|
|
|
\\shade[ball color=gray] (\\i+\\dx-\\rot,{0.5*\\j+\\dy+0.4*sin(\\i*\\nuPi*10)-1.8}) circle(0.45);
|
|
|
|
% bottom layer
|
|
|
|
\\pgfmathsetmacro{\\dx}{rand*0.1}
|
|
|
|
\\pgfmathsetmacro{\\dy}{rand*0.1}
|
|
|
|
\\pgfmathsetmacro{\\rot}{rand*0.1}
|
|
|
|
\\shade[ball color=gray] (\\i+\\dx+\\rot,{0.5*\\j+\\dy+0.4*sin(\\i*\\nuPi*10)-2.8}) circle(0.45);
|
|
|
|
\\shade[ball color=gray] (\\i+\\dx,{0.5*\\j+\\dy+0.4*sin(\\i*\\nuPi*10)-3.7}) circle(0.45);
|
|
|
|
\\shade[ball color=red] (\\i+\\dx-\\rot,{0.5*\\j+\\dy+0.4*sin(\\i*\\nuPi*10)-4.6}) circle(0.45);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
\\end{tikzpicture}
|
2020-02-25 11:03:37 -05:00
|
|
|
\\end{document}\
|
2021-07-13 07:04:48 -04:00
|
|
|
`,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
},
|
2020-02-25 11:15:31 -05:00
|
|
|
},
|
|
|
|
(error, response, body) => {
|
2020-05-07 12:57:35 -04:00
|
|
|
if (error) return done(error)
|
|
|
|
if (!body || !body.compile || !body.compile.outputFiles) {
|
|
|
|
return done(new Error('response payload incomplete'))
|
|
|
|
}
|
2014-02-12 12:27:43 -05:00
|
|
|
|
2020-05-07 12:57:35 -04:00
|
|
|
let pdfFound = false
|
|
|
|
let logFound = false
|
|
|
|
for (const file of body.compile.outputFiles) {
|
|
|
|
if (file.type === 'pdf') pdfFound = true
|
|
|
|
if (file.type === 'log') logFound = true
|
|
|
|
}
|
2020-02-25 11:15:31 -05:00
|
|
|
|
2020-05-07 12:57:35 -04:00
|
|
|
if (!pdfFound) return done(new Error('no pdf returned'))
|
|
|
|
if (!logFound) return done(new Error('no log returned'))
|
|
|
|
done()
|
2020-02-25 11:15:31 -05:00
|
|
|
}
|
2020-05-07 12:57:35 -04:00
|
|
|
)
|
2021-07-13 07:04:48 -04:00
|
|
|
},
|
2020-05-07 12:57:35 -04:00
|
|
|
}
|