Преглед изворни кода

add wordcount clsi handler

Henrique Dias пре 11 година
родитељ
комит
77c2162872

+ 13 - 1
services/web/app/coffee/Features/Compile/ClsiManager.coffee

@@ -105,4 +105,16 @@ module.exports = ClsiManager =
 								rootResourcePath: rootResourcePath
 								rootResourcePath: rootResourcePath
 								resources: resources
 								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

+ 7 - 0
services/web/app/coffee/Features/Compile/CompileController.coffee

@@ -102,3 +102,10 @@ module.exports = CompileController =
 		proxy.pipe(res)
 		proxy.pipe(res)
 		proxy.on "error", (error) ->
 		proxy.on "error", (error) ->
 			logger.warn err: error, url: url, "CLSI proxy 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

+ 4 - 0
services/web/app/coffee/Features/Compile/CompileManager.coffee

@@ -91,3 +91,7 @@ module.exports = CompileManager =
 			else
 			else
 				ProjectRootDocManager.setRootDocAutomatically project_id, callback
 				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

+ 1 - 0
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.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/code", SecurityManager.requestCanAccessProject, CompileController.proxySync
 		webRouter.get "/project/:Project_id/sync/pdf", 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.delete '/Project/:Project_id', SecurityManager.requestIsOwner, ProjectController.deleteProject
 		webRouter.post '/Project/:Project_id/restore', SecurityManager.requestIsOwner, ProjectController.restoreProject
 		webRouter.post '/Project/:Project_id/restore', SecurityManager.requestIsOwner, ProjectController.restoreProject