Completed
Branch master (0f7120)
by Janis
02:51
created
appinfo/routes.php 1 patch
Indentation   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -18,8 +18,8 @@
 block discarded – undo
18 18
  * it's instantiated in there
19 19
  */
20 20
 return [
21
-    'routes' => [
21
+	'routes' => [
22 22
 		['name' => 'ocr#process', 'url' => '/process', 'verb' => 'GET'],
23 23
 		['name' => 'ocr#languages', 'url' => '/languages', 'verb' => 'GET'],
24
-    ]
24
+	]
25 25
 ];
26 26
\ No newline at end of file
Please login to merge, or discard this patch.
controller/ocrcontroller.php 2 patches
Spacing   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -25,7 +25,7 @@  discard block
 block discarded – undo
25 25
 	private $logger;
26 26
 	private $config;
27 27
 
28
-	public function __construct($AppName, IRequest $request, $UserId, ILogger $logger, IConfig $config){
28
+	public function __construct($AppName, IRequest $request, $UserId, ILogger $logger, IConfig $config) {
29 29
 		parent::__construct($AppName, $request);
30 30
 		$this->userId = $UserId;
31 31
 		$this->logger = $logger;
@@ -37,7 +37,7 @@  discard block
 block discarded – undo
37 37
 	 * @NoAdminRequired
38 38
 	 * @return JSONResponse
39 39
 	 */
40
-	public function languages(){
40
+	public function languages() {
41 41
 		$success = -1;
42 42
 		exec('tesseract --list-langs 2>&1', $result, $success);
43 43
 		if ($success === 0 && count($result) != "Array[0]") {
@@ -68,30 +68,30 @@  discard block
 block discarded – undo
68 68
 	 * @return JSONResponse
69 69
 	 */
70 70
 	public function process($srcFile, $srcDir, $language) {
71
-		$newName ='';
71
+		$newName = '';
72 72
 		// Parameters set
73
-		if(!empty($srcFile) && !empty($language) && strlen($language) > 0 && !empty($srcDir)) {
74
-			$file = $srcDir.'/'.$srcFile;
73
+		if (!empty($srcFile) && !empty($language) && strlen($language) > 0 && !empty($srcDir)) {
74
+			$file = $srcDir . '/' . $srcFile;
75 75
 			$fileInfo = \OC\Files\Filesystem::getFileInfo($file);
76 76
 			$mtype = $fileInfo->getMimetype();
77 77
 			$srcFile = substr($srcFile, 0, -4);
78
-			if ($mtype == 'application/pdf'){
79
-				$newName = \OCP\Files::buildNotExistingFileName($srcDir,$srcFile.'_OCR.pdf'); // new filename (and in case it exists already it will be build other way)
78
+			if ($mtype == 'application/pdf') {
79
+				$newName = \OCP\Files::buildNotExistingFileName($srcDir, $srcFile . '_OCR.pdf'); // new filename (and in case it exists already it will be build other way)
80 80
 				$success = $this->ocrmypdf($fileInfo, $newName, $language);
81 81
 				$message = $success ? 'OCR_SUCCESS' : 'OCR_ERROR';
82
-			}elseif ($mtype == 'image/png' || $mtype == 'image/jpeg' || $mtype == 'image/tiff'){
83
-				$newName = \OCP\Files::buildNotExistingFileName($srcDir,$srcFile.'_OCR.txt'); // new filename (and in case it exists already it will be build other way)
82
+			}elseif ($mtype == 'image/png' || $mtype == 'image/jpeg' || $mtype == 'image/tiff') {
83
+				$newName = \OCP\Files::buildNotExistingFileName($srcDir, $srcFile . '_OCR.txt'); // new filename (and in case it exists already it will be build other way)
84 84
 				$success = $this->tesseract($fileInfo, $newName, $language);
85 85
 				$message = $success ? 'OCR_SUCCESS' : 'OCR_ERROR';
86
-			}else{
86
+			} else {
87 87
 				$success = false;
88 88
 				$message = 'WRONG_MIMETYPE'; // wrong mimetype
89 89
 			}
90
-		}else{
90
+		} else {
91 91
 			$success = false;
92 92
 			$message = 'WRONG_PARAMETERS'; // parameters not set
93 93
 		}
94
-		return new JSONResponse(array('success' => $success,'message' => $message, 'file' => $srcFile));
94
+		return new JSONResponse(array('success' => $success, 'message' => $message, 'file' => $srcFile));
95 95
 	}
96 96
 
97 97
 	/**
@@ -102,7 +102,7 @@  discard block
 block discarded – undo
102 102
 	 * @param string $language
103 103
 	 * @return bool
104 104
 	 */
105
-	private function tesseract($fileinfo , $newName, $language){
105
+	private function tesseract($fileinfo, $newName, $language) {
106 106
 		try {
107 107
 			$tempM = new \OC\TempManager($this->logger, $this->config);
108 108
 			$tempFile = $tempM->getTemporaryFile();
@@ -134,7 +134,7 @@  discard block
 block discarded – undo
134 134
 	 * @param string $language
135 135
 	 * @return bool
136 136
 	 */
137
-	private function ocrmypdf($fileinfo, $newName, $language){
137
+	private function ocrmypdf($fileinfo, $newName, $language) {
138 138
 		try {
139 139
 			$tempM = new \OC\TempManager($this->logger, $this->config);
140 140
 			$tempFile = $tempM->getTemporaryFile();
Please login to merge, or discard this patch.
Braces   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -79,15 +79,15 @@
 block discarded – undo
79 79
 				$newName = \OCP\Files::buildNotExistingFileName($srcDir,$srcFile.'_OCR.pdf'); // new filename (and in case it exists already it will be build other way)
80 80
 				$success = $this->ocrmypdf($fileInfo, $newName, $language);
81 81
 				$message = $success ? 'OCR_SUCCESS' : 'OCR_ERROR';
82
-			}elseif ($mtype == 'image/png' || $mtype == 'image/jpeg' || $mtype == 'image/tiff'){
82
+			} elseif ($mtype == 'image/png' || $mtype == 'image/jpeg' || $mtype == 'image/tiff'){
83 83
 				$newName = \OCP\Files::buildNotExistingFileName($srcDir,$srcFile.'_OCR.txt'); // new filename (and in case it exists already it will be build other way)
84 84
 				$success = $this->tesseract($fileInfo, $newName, $language);
85 85
 				$message = $success ? 'OCR_SUCCESS' : 'OCR_ERROR';
86
-			}else{
86
+			} else{
87 87
 				$success = false;
88 88
 				$message = 'WRONG_MIMETYPE'; // wrong mimetype
89 89
 			}
90
-		}else{
90
+		} else{
91 91
 			$success = false;
92 92
 			$message = 'WRONG_PARAMETERS'; // parameters not set
93 93
 		}
Please login to merge, or discard this patch.