Просмотр исходного кода

Support configurable images in wordcount end point

James Allen 10 лет назад
Родитель
Сommit
de280d0ed4

+ 3 - 1
services/clsi/app/coffee/CompileController.coffee

@@ -70,8 +70,10 @@ module.exports = CompileController =
 	wordcount: (req, res, next = (error) ->) ->
 	wordcount: (req, res, next = (error) ->) ->
 		file   = req.query.file || "main.tex"
 		file   = req.query.file || "main.tex"
 		project_id = req.params.project_id
 		project_id = req.params.project_id
+		image = req.query.image
+		logger.log {image, file, project_id}, "word count request"
 
 
-		CompileManager.wordcount project_id, file, (error, result) ->
+		CompileManager.wordcount project_id, file, image, (error, result) ->
 			return next(error) if error?
 			return next(error) if error?
 			res.send JSON.stringify {
 			res.send JSON.stringify {
 				texcount: result
 				texcount: result

+ 3 - 3
services/clsi/app/coffee/CompileManager.coffee

@@ -112,14 +112,14 @@ module.exports = CompileManager =
 				}
 				}
 		return results
 		return results
 
 
-	wordcount: (project_id, file_name, callback = (error, pdfPositions) ->) ->
-		logger.log project_id:project_id, file_name:file_name, "running wordcount"
+	wordcount: (project_id, file_name, image, callback = (error, pdfPositions) ->) ->
+		logger.log project_id:project_id, file_name:file_name, image:image, "running wordcount"
 		file_path = "$COMPILE_DIR/" + file_name
 		file_path = "$COMPILE_DIR/" + file_name
 		command = [ "texcount", '-inc', file_path, "-out=" + file_path + ".wc"]
 		command = [ "texcount", '-inc', file_path, "-out=" + file_path + ".wc"]
 		directory = Path.join(Settings.path.compilesDir, project_id)
 		directory = Path.join(Settings.path.compilesDir, project_id)
 		timeout = 10 * 1000
 		timeout = 10 * 1000
 
 
-		CommandRunner.run project_id, command, directory, timeout, (error) ->
+		CommandRunner.run project_id, command, directory, image, timeout, (error) ->
 			return callback(error) if error?
 			return callback(error) if error?
 			try
 			try
 				stdout = fs.readFileSync(directory + "/" + file_name + ".wc", "utf-8")
 				stdout = fs.readFileSync(directory + "/" + file_name + ".wc", "utf-8")

+ 3 - 2
services/clsi/test/unit/coffee/CompileControllerTests.coffee

@@ -197,14 +197,15 @@ describe "CompileController", ->
 				project_id: @project_id
 				project_id: @project_id
 			@req.query =
 			@req.query =
 				file: @file
 				file: @file
+				image: @image = "example.com/image"
 			@res.send = sinon.stub()
 			@res.send = sinon.stub()
 
 
-			@CompileManager.wordcount = sinon.stub().callsArgWith(2, null, @texcount = ["mock-texcount"])
+			@CompileManager.wordcount = sinon.stub().callsArgWith(3, null, @texcount = ["mock-texcount"])
 			@CompileController.wordcount @req, @res, @next
 			@CompileController.wordcount @req, @res, @next
 
 
 		it "should return the word count of a file", ->
 		it "should return the word count of a file", ->
 			@CompileManager.wordcount
 			@CompileManager.wordcount
-				.calledWith(@project_id, @file)
+				.calledWith(@project_id, @file, @image)
 				.should.equal true
 				.should.equal true
 
 
 		it "should return the texcount info", ->
 		it "should return the texcount info", ->

+ 4 - 3
services/clsi/test/unit/coffee/CompileManagerTests.coffee

@@ -179,7 +179,7 @@ describe "CompileManager", ->
 
 
 	describe "wordcount", ->
 	describe "wordcount", ->
 		beforeEach ->
 		beforeEach ->
-			@CommandRunner.run = sinon.stub().callsArg(4)
+			@CommandRunner.run = sinon.stub().callsArg(5)
 			@fs.readFileSync = sinon.stub().returns @stdout = "Encoding: ascii\nWords in text: 2"
 			@fs.readFileSync = sinon.stub().returns @stdout = "Encoding: ascii\nWords in text: 2"
 			@callback  = sinon.stub()
 			@callback  = sinon.stub()
 
 
@@ -187,8 +187,9 @@ describe "CompileManager", ->
 			@timeout = 10 * 1000
 			@timeout = 10 * 1000
 			@file_name = "main.tex"
 			@file_name = "main.tex"
 			@Settings.path.compilesDir = "/local/compile/directory"
 			@Settings.path.compilesDir = "/local/compile/directory"
+			@image = "example.com/image"
 
 
-			@CompileManager.wordcount @project_id, @file_name, @callback
+			@CompileManager.wordcount @project_id, @file_name, @image, @callback
 
 
 		it "should run the texcount command", ->
 		it "should run the texcount command", ->
 			@directory = "#{@Settings.path.compilesDir}/#{@project_id}"
 			@directory = "#{@Settings.path.compilesDir}/#{@project_id}"
@@ -196,7 +197,7 @@ describe "CompileManager", ->
 			@command =[ "texcount", "-inc", @file_path, "-out=" + @file_path + ".wc"]
 			@command =[ "texcount", "-inc", @file_path, "-out=" + @file_path + ".wc"]
 			
 			
 			@CommandRunner.run
 			@CommandRunner.run
-				.calledWith(@project_id, @command, @directory, @timeout)
+				.calledWith(@project_id, @command, @directory, @image, @timeout)
 				.should.equal true
 				.should.equal true
 
 
 		it "should call the callback with the parsed output", ->
 		it "should call the callback with the parsed output", ->