CompileManager.js 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729
  1. const fsPromises = require('node:fs/promises')
  2. const os = require('node:os')
  3. const Path = require('node:path')
  4. const { callbackify } = require('node:util')
  5. const Settings = require('@overleaf/settings')
  6. const logger = require('@overleaf/logger')
  7. const OError = require('@overleaf/o-error')
  8. const ResourceWriter = require('./ResourceWriter')
  9. const LatexRunner = require('./LatexRunner')
  10. const OutputFileFinder = require('./OutputFileFinder')
  11. const OutputCacheManager = require('./OutputCacheManager')
  12. const Metrics = require('./Metrics')
  13. const DraftModeManager = require('./DraftModeManager')
  14. const TikzManager = require('./TikzManager')
  15. const LockManager = require('./LockManager')
  16. const Errors = require('./Errors')
  17. const CommandRunner = require('./CommandRunner')
  18. const { emitPdfStats } = require('./ContentCacheMetrics')
  19. const SynctexOutputParser = require('./SynctexOutputParser')
  20. const {
  21. downloadLatestCompileCache,
  22. downloadOutputDotSynctexFromCompileCache,
  23. } = require('./CLSICacheHandler')
  24. const { callbackifyMultiResult } = require('@overleaf/promise-utils')
  25. const COMPILE_TIME_BUCKETS = [
  26. // NOTE: These buckets are locked in per metric name.
  27. // If you want to change them, you will need to rename metrics.
  28. 0, 1, 2, 3, 4, 6, 8, 11, 15, 22, 31, 43, 61, 86, 121, 170, 240,
  29. ].map(seconds => seconds * 1000)
  30. function getCompileName(projectId, userId) {
  31. if (userId != null) {
  32. return `${projectId}-${userId}`
  33. } else {
  34. return projectId
  35. }
  36. }
  37. function getCompileDir(projectId, userId) {
  38. return Path.join(Settings.path.compilesDir, getCompileName(projectId, userId))
  39. }
  40. function getOutputDir(projectId, userId) {
  41. return Path.join(Settings.path.outputDir, getCompileName(projectId, userId))
  42. }
  43. async function doCompileWithLock(request, stats, timings) {
  44. const compileDir = getCompileDir(request.project_id, request.user_id)
  45. request.isInitialCompile =
  46. (await fsPromises.mkdir(compileDir, { recursive: true })) === compileDir
  47. // prevent simultaneous compiles
  48. const lock = LockManager.acquire(compileDir)
  49. try {
  50. return await doCompile(request, stats, timings)
  51. } finally {
  52. lock.release()
  53. }
  54. }
  55. async function doCompile(request, stats, timings) {
  56. const { project_id: projectId, user_id: userId } = request
  57. const compileDir = getCompileDir(request.project_id, request.user_id)
  58. const timerE2E = new Metrics.Timer(
  59. 'compile-e2e-v2',
  60. 1,
  61. request.metricsOpts,
  62. COMPILE_TIME_BUCKETS
  63. )
  64. if (request.isInitialCompile) {
  65. stats.isInitialCompile = 1
  66. request.metricsOpts.compile = 'initial'
  67. if (request.compileFromClsiCache) {
  68. try {
  69. if (await downloadLatestCompileCache(projectId, userId, compileDir)) {
  70. stats.restoredClsiCache = 1
  71. request.metricsOpts.compile = 'from-clsi-cache'
  72. }
  73. } catch (err) {
  74. logger.warn(
  75. { err, projectId, userId },
  76. 'failed to populate compile dir from cache'
  77. )
  78. }
  79. }
  80. } else {
  81. request.metricsOpts.compile = 'recompile'
  82. }
  83. const writeToDiskTimer = new Metrics.Timer(
  84. 'write-to-disk',
  85. 1,
  86. request.metricsOpts
  87. )
  88. logger.debug(
  89. { projectId: request.project_id, userId: request.user_id },
  90. 'syncing resources to disk'
  91. )
  92. let resourceList
  93. try {
  94. // NOTE: resourceList is insecure, it should only be used to exclude files from the output list
  95. resourceList = await ResourceWriter.promises.syncResourcesToDisk(
  96. request,
  97. compileDir
  98. )
  99. } catch (error) {
  100. if (error instanceof Errors.FilesOutOfSyncError) {
  101. OError.tag(error, 'files out of sync, please retry', {
  102. projectId: request.project_id,
  103. userId: request.user_id,
  104. })
  105. } else {
  106. OError.tag(error, 'error writing resources to disk', {
  107. projectId: request.project_id,
  108. userId: request.user_id,
  109. })
  110. }
  111. throw error
  112. }
  113. logger.debug(
  114. {
  115. projectId: request.project_id,
  116. userId: request.user_id,
  117. timeTaken: Date.now() - writeToDiskTimer.start,
  118. },
  119. 'written files to disk'
  120. )
  121. timings.sync = writeToDiskTimer.done()
  122. // set up environment variables for chktex
  123. const env = {
  124. OVERLEAF_PROJECT_ID: request.project_id,
  125. }
  126. if (Settings.texliveOpenoutAny && Settings.texliveOpenoutAny !== '') {
  127. // override default texlive openout_any environment variable
  128. env.openout_any = Settings.texliveOpenoutAny
  129. }
  130. if (Settings.texliveMaxPrintLine && Settings.texliveMaxPrintLine !== '') {
  131. // override default texlive max_print_line environment variable
  132. env.max_print_line = Settings.texliveMaxPrintLine
  133. }
  134. // only run chktex on LaTeX files (not knitr .Rtex files or any others)
  135. const isLaTeXFile = request.rootResourcePath?.match(/\.tex$/i)
  136. if (request.check != null && isLaTeXFile) {
  137. env.CHKTEX_OPTIONS = '-nall -e9 -e10 -w15 -w16'
  138. env.CHKTEX_ULIMIT_OPTIONS = '-t 5 -v 64000'
  139. if (request.check === 'error') {
  140. env.CHKTEX_EXIT_ON_ERROR = 1
  141. }
  142. if (request.check === 'validate') {
  143. env.CHKTEX_VALIDATE = 1
  144. }
  145. }
  146. // apply a series of file modifications/creations for draft mode and tikz
  147. if (request.draft) {
  148. await DraftModeManager.promises.injectDraftMode(
  149. Path.join(compileDir, request.rootResourcePath)
  150. )
  151. }
  152. const needsMainFile = await TikzManager.promises.checkMainFile(
  153. compileDir,
  154. request.rootResourcePath,
  155. resourceList
  156. )
  157. if (needsMainFile) {
  158. await TikzManager.promises.injectOutputFile(
  159. compileDir,
  160. request.rootResourcePath
  161. )
  162. }
  163. const compileTimer = new Metrics.Timer('run-compile', 1, request.metricsOpts)
  164. // find the image tag to log it as a metric, e.g. 2015.1 (convert . to - for graphite)
  165. let tag = 'default'
  166. if (request.imageName != null) {
  167. const match = request.imageName.match(/:(.*)/)
  168. if (match != null) {
  169. tag = match[1].replace(/\./g, '-')
  170. }
  171. }
  172. // exclude smoke test
  173. if (!request.project_id.match(/^[0-9a-f]{24}$/)) {
  174. tag = 'other'
  175. }
  176. Metrics.inc('compiles', 1, request.metricsOpts)
  177. Metrics.inc(`compiles-with-image.${tag}`, 1, request.metricsOpts)
  178. const compileName = getCompileName(request.project_id, request.user_id)
  179. try {
  180. await LatexRunner.promises.runLatex(compileName, {
  181. directory: compileDir,
  182. mainFile: request.rootResourcePath,
  183. compiler: request.compiler,
  184. timeout: request.timeout,
  185. image: request.imageName,
  186. flags: request.flags,
  187. environment: env,
  188. compileGroup: request.compileGroup,
  189. stopOnFirstError: request.stopOnFirstError,
  190. stats,
  191. timings,
  192. })
  193. // We use errors to return the validation state. It would be nice to use a
  194. // more appropriate mechanism.
  195. if (request.check === 'validate') {
  196. const validationError = new Error('validation')
  197. validationError.validate = 'pass'
  198. throw validationError
  199. }
  200. } catch (originalError) {
  201. let error = originalError
  202. // request was for validation only
  203. if (request.check === 'validate' && !error.validate) {
  204. error = new Error('validation')
  205. error.validate = originalError.code ? 'fail' : 'pass'
  206. }
  207. // request was for compile, and failed on validation
  208. if (request.check === 'error' && originalError.message === 'exited') {
  209. error = new Error('compilation')
  210. error.validate = 'fail'
  211. }
  212. // record timeout errors as a separate counter, success is recorded later
  213. if (error.timedout) {
  214. Metrics.inc('compiles-timeout', 1, request.metricsOpts)
  215. }
  216. const { outputFiles, allEntries, buildId } = await _saveOutputFiles({
  217. request,
  218. compileDir,
  219. resourceList,
  220. stats,
  221. timings,
  222. })
  223. error.outputFiles = outputFiles // return output files so user can check logs
  224. error.buildId = buildId
  225. // Clear project if this compile was abruptly terminated
  226. if (error.terminated || error.timedout) {
  227. await clearProjectWithListing(
  228. request.project_id,
  229. request.user_id,
  230. allEntries
  231. )
  232. }
  233. throw error
  234. }
  235. // compile completed normally
  236. Metrics.inc('compiles-succeeded', 1, request.metricsOpts)
  237. for (const metricKey in stats) {
  238. const metricValue = stats[metricKey]
  239. Metrics.count(metricKey, metricValue, 1, request.metricsOpts)
  240. }
  241. for (const metricKey in timings) {
  242. const metricValue = timings[metricKey]
  243. Metrics.timing(metricKey, metricValue, 1, request.metricsOpts)
  244. }
  245. const loadavg = typeof os.loadavg === 'function' ? os.loadavg() : undefined
  246. if (loadavg != null) {
  247. Metrics.gauge('load-avg', loadavg[0])
  248. }
  249. const ts = compileTimer.done()
  250. logger.debug(
  251. {
  252. projectId: request.project_id,
  253. userId: request.user_id,
  254. timeTaken: ts,
  255. stats,
  256. timings,
  257. loadavg,
  258. },
  259. 'done compile'
  260. )
  261. if (stats['latex-runs'] > 0) {
  262. Metrics.histogram(
  263. 'avg-compile-per-pass-v2',
  264. ts / stats['latex-runs'],
  265. COMPILE_TIME_BUCKETS,
  266. request.metricsOpts
  267. )
  268. Metrics.timing(
  269. 'avg-compile-per-pass-v2',
  270. ts / stats['latex-runs'],
  271. 1,
  272. request.metricsOpts
  273. )
  274. }
  275. if (stats['latex-runs'] > 0 && timings['cpu-time'] > 0) {
  276. Metrics.timing(
  277. 'run-compile-cpu-time-per-pass',
  278. timings['cpu-time'] / stats['latex-runs'],
  279. 1,
  280. request.metricsOpts
  281. )
  282. }
  283. // Emit compile time.
  284. timings.compile = ts
  285. const { outputFiles, buildId } = await _saveOutputFiles({
  286. request,
  287. compileDir,
  288. resourceList,
  289. stats,
  290. timings,
  291. })
  292. // Emit e2e compile time.
  293. timings.compileE2E = timerE2E.done()
  294. Metrics.timing('compile-e2e-v2', timings.compileE2E, 1, request.metricsOpts)
  295. if (stats['pdf-size']) {
  296. emitPdfStats(stats, timings, request)
  297. }
  298. return { outputFiles, buildId }
  299. }
  300. async function _saveOutputFiles({
  301. request,
  302. compileDir,
  303. resourceList,
  304. stats,
  305. timings,
  306. }) {
  307. const timer = new Metrics.Timer(
  308. 'process-output-files',
  309. 1,
  310. request.metricsOpts
  311. )
  312. const outputDir = getOutputDir(request.project_id, request.user_id)
  313. const { outputFiles: rawOutputFiles, allEntries } =
  314. await OutputFileFinder.promises.findOutputFiles(resourceList, compileDir)
  315. const { buildId, outputFiles } =
  316. await OutputCacheManager.promises.saveOutputFiles(
  317. { request, stats, timings },
  318. rawOutputFiles,
  319. compileDir,
  320. outputDir
  321. )
  322. timings.output = timer.done()
  323. return { outputFiles, allEntries, buildId }
  324. }
  325. async function stopCompile(projectId, userId) {
  326. const compileName = getCompileName(projectId, userId)
  327. await LatexRunner.promises.killLatex(compileName)
  328. }
  329. async function clearProject(projectId, userId) {
  330. const compileDir = getCompileDir(projectId, userId)
  331. await fsPromises.rm(compileDir, { force: true, recursive: true })
  332. }
  333. async function clearProjectWithListing(projectId, userId, allEntries) {
  334. const compileDir = getCompileDir(projectId, userId)
  335. const exists = await _checkDirectory(compileDir)
  336. if (!exists) {
  337. // skip removal if no directory present
  338. return
  339. }
  340. for (const pathInProject of allEntries) {
  341. const path = Path.join(compileDir, pathInProject)
  342. if (path.endsWith('/')) {
  343. await fsPromises.rmdir(path)
  344. } else {
  345. await fsPromises.unlink(path)
  346. }
  347. }
  348. await fsPromises.rmdir(compileDir)
  349. }
  350. async function _findAllDirs() {
  351. const root = Settings.path.compilesDir
  352. const files = await fsPromises.readdir(root)
  353. const allDirs = files.map(file => Path.join(root, file))
  354. return allDirs
  355. }
  356. async function clearExpiredProjects(maxCacheAgeMs) {
  357. const now = Date.now()
  358. const dirs = await _findAllDirs()
  359. for (const dir of dirs) {
  360. let stats
  361. try {
  362. stats = await fsPromises.stat(dir)
  363. } catch (err) {
  364. // ignore errors checking directory
  365. continue
  366. }
  367. const age = now - stats.mtime
  368. const hasExpired = age > maxCacheAgeMs
  369. if (hasExpired) {
  370. await fsPromises.rm(dir, { force: true, recursive: true })
  371. }
  372. }
  373. }
  374. async function _checkDirectory(compileDir) {
  375. let stats
  376. try {
  377. stats = await fsPromises.lstat(compileDir)
  378. } catch (err) {
  379. if (err.code === 'ENOENT') {
  380. // directory does not exist
  381. return false
  382. }
  383. OError.tag(err, 'error on stat of project directory for removal', {
  384. dir: compileDir,
  385. })
  386. throw err
  387. }
  388. if (!stats.isDirectory()) {
  389. throw new OError('project directory is not directory', {
  390. dir: compileDir,
  391. stats,
  392. })
  393. }
  394. return true
  395. }
  396. async function syncFromCode(projectId, userId, filename, line, column, opts) {
  397. // If LaTeX was run in a virtual environment, the file path that synctex expects
  398. // might not match the file path on the host. The .synctex.gz file however, will be accessed
  399. // wherever it is on the host.
  400. const compileName = getCompileName(projectId, userId)
  401. const baseDir = Settings.path.synctexBaseDir(compileName)
  402. const inputFilePath = Path.join(baseDir, filename)
  403. const outputFilePath = Path.join(baseDir, 'output.pdf')
  404. const command = [
  405. 'synctex',
  406. 'view',
  407. '-i',
  408. `${line}:${column}:${inputFilePath}`,
  409. '-o',
  410. outputFilePath,
  411. ]
  412. const { stdout, downloadedFromCache } = await _runSynctex(
  413. projectId,
  414. userId,
  415. command,
  416. opts
  417. )
  418. logger.debug(
  419. { projectId, userId, filename, line, column, command, stdout },
  420. 'synctex code output'
  421. )
  422. return {
  423. codePositions: SynctexOutputParser.parseViewOutput(stdout),
  424. downloadedFromCache,
  425. }
  426. }
  427. async function syncFromPdf(projectId, userId, page, h, v, opts) {
  428. const compileName = getCompileName(projectId, userId)
  429. const baseDir = Settings.path.synctexBaseDir(compileName)
  430. const outputFilePath = `${baseDir}/output.pdf`
  431. const command = [
  432. 'synctex',
  433. 'edit',
  434. '-o',
  435. `${page}:${h}:${v}:${outputFilePath}`,
  436. ]
  437. const { stdout, downloadedFromCache } = await _runSynctex(
  438. projectId,
  439. userId,
  440. command,
  441. opts
  442. )
  443. logger.debug({ projectId, userId, page, h, v, stdout }, 'synctex pdf output')
  444. return {
  445. pdfPositions: SynctexOutputParser.parseEditOutput(stdout, baseDir),
  446. downloadedFromCache,
  447. }
  448. }
  449. async function _checkFileExists(dir, filename) {
  450. try {
  451. await fsPromises.stat(dir)
  452. } catch (error) {
  453. if (error.code === 'ENOENT') {
  454. throw new Errors.NotFoundError('no output directory')
  455. }
  456. throw error
  457. }
  458. const file = Path.join(dir, filename)
  459. let stats
  460. try {
  461. stats = await fsPromises.stat(file)
  462. } catch (error) {
  463. if (error.code === 'ENOENT') {
  464. throw new Errors.NotFoundError('no output file')
  465. }
  466. }
  467. if (!stats.isFile()) {
  468. throw new Error('not a file')
  469. }
  470. }
  471. async function _runSynctex(projectId, userId, command, opts) {
  472. const { imageName, editorId, buildId, compileFromClsiCache } = opts
  473. if (imageName && !_isImageNameAllowed(imageName)) {
  474. throw new Errors.InvalidParameter('invalid image')
  475. }
  476. if (editorId && !/^[a-f0-9-]+$/.test(editorId)) {
  477. throw new Errors.InvalidParameter('invalid editorId')
  478. }
  479. if (buildId && !OutputCacheManager.BUILD_REGEX.test(buildId)) {
  480. throw new Errors.InvalidParameter('invalid buildId')
  481. }
  482. const outputDir = getOutputDir(projectId, userId)
  483. const runInOutputDir = buildId && CommandRunner.canRunSyncTeXInOutputDir()
  484. const directory = runInOutputDir
  485. ? Path.join(outputDir, OutputCacheManager.CACHE_SUBDIR, buildId)
  486. : getCompileDir(projectId, userId)
  487. const timeout = 60 * 1000 // increased to allow for large projects
  488. const compileName = getCompileName(projectId, userId)
  489. const compileGroup = runInOutputDir ? 'synctex-output' : 'synctex'
  490. const defaultImageName =
  491. Settings.clsi && Settings.clsi.docker && Settings.clsi.docker.image
  492. // eslint-disable-next-line @typescript-eslint/return-await
  493. return await OutputCacheManager.promises.queueDirOperation(
  494. outputDir,
  495. /**
  496. * @return {Promise<{stdout: string, downloadedFromCache: boolean}>}
  497. */
  498. async () => {
  499. let downloadedFromCache = false
  500. try {
  501. await _checkFileExists(directory, 'output.synctex.gz')
  502. } catch (err) {
  503. if (
  504. err instanceof Errors.NotFoundError &&
  505. compileFromClsiCache &&
  506. editorId &&
  507. buildId
  508. ) {
  509. try {
  510. downloadedFromCache =
  511. await downloadOutputDotSynctexFromCompileCache(
  512. projectId,
  513. userId,
  514. editorId,
  515. buildId,
  516. directory
  517. )
  518. } catch (err) {
  519. logger.warn(
  520. { err, projectId, userId, editorId, buildId },
  521. 'failed to download output.synctex.gz from clsi-cache'
  522. )
  523. }
  524. await _checkFileExists(directory, 'output.synctex.gz')
  525. } else {
  526. throw err
  527. }
  528. }
  529. try {
  530. const { stdout } = await CommandRunner.promises.run(
  531. compileName,
  532. command,
  533. directory,
  534. imageName || defaultImageName,
  535. timeout,
  536. {},
  537. compileGroup
  538. )
  539. return {
  540. stdout,
  541. downloadedFromCache,
  542. }
  543. } catch (error) {
  544. throw OError.tag(error, 'error running synctex', {
  545. command,
  546. projectId,
  547. userId,
  548. })
  549. }
  550. }
  551. )
  552. }
  553. async function wordcount(projectId, userId, filename, image) {
  554. logger.debug({ projectId, userId, filename, image }, 'running wordcount')
  555. const filePath = `$COMPILE_DIR/${filename}`
  556. const command = ['texcount', '-nocol', '-inc', filePath]
  557. const compileDir = getCompileDir(projectId, userId)
  558. const timeout = 60 * 1000
  559. const compileName = getCompileName(projectId, userId)
  560. const compileGroup = 'wordcount'
  561. if (image && !_isImageNameAllowed(image)) {
  562. throw new Errors.InvalidParameter('invalid image')
  563. }
  564. try {
  565. await fsPromises.mkdir(compileDir, { recursive: true })
  566. } catch (err) {
  567. throw OError.tag(err, 'error ensuring dir for wordcount', {
  568. projectId,
  569. userId,
  570. filename,
  571. })
  572. }
  573. try {
  574. const { stdout } = await CommandRunner.promises.run(
  575. compileName,
  576. command,
  577. compileDir,
  578. image,
  579. timeout,
  580. {},
  581. compileGroup
  582. )
  583. const results = _parseWordcountFromOutput(stdout)
  584. logger.debug(
  585. { projectId, userId, wordcount: results },
  586. 'word count results'
  587. )
  588. return results
  589. } catch (err) {
  590. throw OError.tag(err, 'error reading word count output', {
  591. command,
  592. compileDir,
  593. projectId,
  594. userId,
  595. })
  596. }
  597. }
  598. function _parseWordcountFromOutput(output) {
  599. const results = {
  600. encode: '',
  601. textWords: 0,
  602. headWords: 0,
  603. outside: 0,
  604. headers: 0,
  605. elements: 0,
  606. mathInline: 0,
  607. mathDisplay: 0,
  608. errors: 0,
  609. messages: '',
  610. }
  611. for (const line of output.split('\n')) {
  612. const [data, info] = line.split(':')
  613. if (data.indexOf('Encoding') > -1) {
  614. results.encode = info.trim()
  615. }
  616. if (data.indexOf('in text') > -1) {
  617. results.textWords = parseInt(info, 10)
  618. }
  619. if (data.indexOf('in head') > -1) {
  620. results.headWords = parseInt(info, 10)
  621. }
  622. if (data.indexOf('outside') > -1) {
  623. results.outside = parseInt(info, 10)
  624. }
  625. if (data.indexOf('of head') > -1) {
  626. results.headers = parseInt(info, 10)
  627. }
  628. if (data.indexOf('Number of floats/tables/figures') > -1) {
  629. results.elements = parseInt(info, 10)
  630. }
  631. if (data.indexOf('Number of math inlines') > -1) {
  632. results.mathInline = parseInt(info, 10)
  633. }
  634. if (data.indexOf('Number of math displayed') > -1) {
  635. results.mathDisplay = parseInt(info, 10)
  636. }
  637. if (data === '(errors') {
  638. // errors reported as (errors:123)
  639. results.errors = parseInt(info, 10)
  640. }
  641. if (line.indexOf('!!! ') > -1) {
  642. // errors logged as !!! message !!!
  643. results.messages += line + '\n'
  644. }
  645. }
  646. return results
  647. }
  648. function _isImageNameAllowed(imageName) {
  649. const ALLOWED_IMAGES =
  650. Settings.clsi && Settings.clsi.docker && Settings.clsi.docker.allowedImages
  651. return !ALLOWED_IMAGES || ALLOWED_IMAGES.includes(imageName)
  652. }
  653. module.exports = {
  654. doCompileWithLock: callbackify(doCompileWithLock),
  655. stopCompile: callbackify(stopCompile),
  656. clearProject: callbackify(clearProject),
  657. clearExpiredProjects: callbackify(clearExpiredProjects),
  658. syncFromCode: callbackifyMultiResult(syncFromCode, [
  659. 'codePositions',
  660. 'downloadedFromCache',
  661. ]),
  662. syncFromPdf: callbackifyMultiResult(syncFromPdf, [
  663. 'pdfPositions',
  664. 'downloadedFromCache',
  665. ]),
  666. wordcount: callbackify(wordcount),
  667. promises: {
  668. doCompileWithLock,
  669. stopCompile,
  670. clearProject,
  671. clearExpiredProjects,
  672. syncFromCode,
  673. syncFromPdf,
  674. wordcount,
  675. },
  676. }