From 77c216287221deee57acec8cacf5cffdc91871e1 Mon Sep 17 00:00:00 2001 From: Henrique Dias Date: Thu, 10 Sep 2015 12:41:48 -0300 Subject: [PATCH] add wordcount clsi handler --- .../app/coffee/Features/Compile/ClsiManager.coffee | 14 +++++++++++++- .../Features/Compile/CompileController.coffee | 7 +++++++ .../coffee/Features/Compile/CompileManager.coffee | 4 ++++ services/web/app/coffee/router.coffee | 1 + 4 files changed, 25 insertions(+), 1 deletion(-) diff --git a/services/web/app/coffee/Features/Compile/ClsiManager.coffee b/services/web/app/coffee/Features/Compile/ClsiManager.coffee index 22598d7dfa..0ee43d75dd 100755 --- a/services/web/app/coffee/Features/Compile/ClsiManager.coffee +++ b/services/web/app/coffee/Features/Compile/ClsiManager.coffee @@ -105,4 +105,16 @@ module.exports = ClsiManager = rootResourcePath: rootResourcePath resources: resources } - + + wordCount: (project_id, options, callback = (error, response) ->) -> + compilerUrl = @_getCompilerUrl(options?.compileGroup) + request.get { + url: "#{compilerUrl}/project/#{project_id}/wordcount" + }, (error, response, body) -> + return callback(error) if error? + if 200 <= response.statusCode < 300 + callback null, body + else + error = new Error("CLSI returned non-success code: #{response.statusCode}") + logger.error err: error, project_id: project_id, "CLSI returned failure code" + callback error, body diff --git a/services/web/app/coffee/Features/Compile/CompileController.coffee b/services/web/app/coffee/Features/Compile/CompileController.coffee index 667accd65a..972bc5b948 100755 --- a/services/web/app/coffee/Features/Compile/CompileController.coffee +++ b/services/web/app/coffee/Features/Compile/CompileController.coffee @@ -102,3 +102,10 @@ module.exports = CompileController = proxy.pipe(res) proxy.on "error", (error) -> logger.warn err: error, url: url, "CLSI proxy error" + + wordCount: (req, res, next) -> + project_id = req.params.Project_id + CompileManager.wordCount project_id, (error, body) -> + return next(error) if error? + res.contentType("application/json") + res.send 200, body diff --git a/services/web/app/coffee/Features/Compile/CompileManager.coffee b/services/web/app/coffee/Features/Compile/CompileManager.coffee index 6e7056813d..04810937a0 100755 --- a/services/web/app/coffee/Features/Compile/CompileManager.coffee +++ b/services/web/app/coffee/Features/Compile/CompileManager.coffee @@ -91,3 +91,7 @@ module.exports = CompileManager = else ProjectRootDocManager.setRootDocAutomatically project_id, callback + wordCount: (project_id, callback = (error) ->) -> + CompileManager.getProjectCompileLimits project_id, (error, limits) -> + return callback(error) if error? + ClsiManager.wordCount project_id, limits, callback diff --git a/services/web/app/coffee/router.coffee b/services/web/app/coffee/router.coffee index 22c1fbfe54..cbad929e67 100644 --- a/services/web/app/coffee/router.coffee +++ b/services/web/app/coffee/router.coffee @@ -111,6 +111,7 @@ module.exports = class Router webRouter.delete "/project/:Project_id/output", SecurityManager.requestCanAccessProject, CompileController.deleteAuxFiles webRouter.get "/project/:Project_id/sync/code", SecurityManager.requestCanAccessProject, CompileController.proxySync webRouter.get "/project/:Project_id/sync/pdf", SecurityManager.requestCanAccessProject, CompileController.proxySync + webRouter.get "/project/:Project_id/wordcount", SecurityManager.requestCanAccessProject, CompileController.wordCount webRouter.delete '/Project/:Project_id', SecurityManager.requestIsOwner, ProjectController.deleteProject webRouter.post '/Project/:Project_id/restore', SecurityManager.requestIsOwner, ProjectController.restoreProject