2017-11-01 10:01:06 -04:00
|
|
|
fs = require 'fs'
|
|
|
|
path = require 'path'
|
2017-10-30 05:42:12 -04:00
|
|
|
logger = require 'logger-sharelatex'
|
2017-10-25 04:13:17 -04:00
|
|
|
|
2017-11-01 10:01:06 -04:00
|
|
|
INTEGRATION_MODULE_PATH = path.resolve(__dirname, '../../../../modules/overleaf-integration-web-module')
|
2017-10-25 04:13:17 -04:00
|
|
|
|
2017-11-03 06:16:03 -04:00
|
|
|
V1ProjectGetter =
|
|
|
|
# Default implementation is a no-op
|
2017-10-25 04:13:17 -04:00
|
|
|
findAllUsersProjects: (userId, callback = (error, projects) ->) ->
|
2017-11-03 06:16:03 -04:00
|
|
|
logger.log {}, "integration modules doesn't exist, not loading V1 projects"
|
|
|
|
return callback()
|
|
|
|
|
|
|
|
fs.stat INTEGRATION_MODULE_PATH, (error, stats) ->
|
|
|
|
return if error? or !stats.isDirectory()
|
2017-11-03 06:23:29 -04:00
|
|
|
logger.log {isDirectory: stats.isDirectory()}, "integration module does exist, loading V1 projects"
|
2017-11-03 06:16:03 -04:00
|
|
|
# Monkey patch impl to actually fetch projects
|
|
|
|
V1ProjectGetter.findAllUsersProjects = (userId, callback = (error, projects) ->) ->
|
|
|
|
IntegrationProjectListGetter = require(path.join(INTEGRATION_MODULE_PATH, 'app/coffee/ProjectList/ProjectListGetter'))
|
|
|
|
IntegrationProjectListGetter.findAllUsersProjects(userId, callback)
|
|
|
|
|
|
|
|
module.exports = V1ProjectGetter
|