V1ProjectGetter.coffee 929 B

12345678910111213141516171819202122
  1. fs = require 'fs'
  2. path = require 'path'
  3. logger = require 'logger-sharelatex'
  4. INTEGRATION_MODULE_PATH = path.resolve(__dirname, '../../../../modules/overleaf-integration-web-module')
  5. module.exports = V1ProjectGetter =
  6. integrationModuleExists: (callback = (error, stats) ->) ->
  7. fs.stat INTEGRATION_MODULE_PATH, (error, stats) ->
  8. if error? or !stats.isDirectory()
  9. return callback(false)
  10. return callback(true)
  11. findAllUsersProjects: (userId, callback = (error, projects) ->) ->
  12. V1ProjectGetter.integrationModuleExists (exists) ->
  13. if exists
  14. logger.log {exists}, "integration module does exist, loading V1 projects"
  15. V1ProjectListGetter = require(path.join(INTEGRATION_MODULE_PATH, 'app/coffee/ProjectList/ProjectListGetter'))
  16. V1ProjectListGetter.findAllUsersProjects(userId, callback)
  17. else
  18. logger.log {exists}, "integration modules doesn't exists, not loading V1 projects"
  19. return callback()