1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Nextcloud - OCR |
5
|
|
|
* This file is licensed under the Affero General Public License version 3 or |
6
|
|
|
* later. |
7
|
|
|
* See the COPYING file. |
8
|
|
|
* |
9
|
|
|
* @author Janis Koehr <[email protected]> |
10
|
|
|
* @copyright Janis Koehr 2017 |
11
|
|
|
*/ |
12
|
|
|
namespace OCA\Ocr\Controller; |
13
|
|
|
|
14
|
|
|
use OCA\Ocr\Service\JobService; |
15
|
|
|
use OCP\AppFramework\Http\DataResponse; |
16
|
|
|
use OCP\IRequest; |
17
|
|
|
use OCP\AppFramework\Controller; |
18
|
|
|
|
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Class JobController |
22
|
|
|
* |
23
|
|
|
* @package OCA\Ocr\Controller |
24
|
|
|
*/ |
25
|
|
|
class JobController extends Controller { |
26
|
|
|
use Errors; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* |
30
|
|
|
* @var string |
31
|
|
|
*/ |
32
|
|
|
private $userId; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* |
36
|
|
|
* @var JobService |
37
|
|
|
*/ |
38
|
|
|
private $service; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* JobController constructor. |
42
|
|
|
* |
43
|
|
|
* @param string $AppName |
44
|
|
|
* @param IRequest $request |
45
|
|
|
* @param JobService $service |
46
|
|
|
* @param |
47
|
|
|
* $UserId |
48
|
|
|
*/ |
49
|
7 |
|
public function __construct($AppName, IRequest $request, JobService $service, $UserId) { |
50
|
7 |
|
parent::__construct($AppName, $request); |
51
|
7 |
|
$this->userId = $UserId; |
52
|
7 |
|
$this->service = $service; |
53
|
7 |
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* Processing the srcFile(s) |
57
|
|
|
* @NoAdminRequired |
58
|
|
|
* |
59
|
|
|
* @param string[] $languages |
60
|
|
|
* - deu, eng... |
61
|
|
|
* @param array $files |
62
|
|
|
* @param boolean $replace |
63
|
|
|
* @return DataResponse |
64
|
|
|
*/ |
65
|
2 |
|
public function process($languages, $files, $replace) { |
66
|
2 |
|
return $this->handleNotFound( |
67
|
2 |
|
function () use ($languages, $files, $replace) { |
68
|
2 |
|
return $this->service->process($languages, $files, $replace); |
69
|
2 |
|
}); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* @NoAdminRequired |
74
|
|
|
* |
75
|
|
|
* @return \OCP\AppFramework\Http\DataResponse |
76
|
|
|
*/ |
77
|
2 |
|
public function getAllJobs() { |
78
|
2 |
|
return $this->handleNotFound( |
79
|
2 |
|
function () { |
80
|
2 |
|
return $this->service->getAllJobsForUser($this->userId); |
81
|
2 |
|
}); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* @NoAdminRequired |
86
|
|
|
* |
87
|
|
|
* @param integer $id |
88
|
|
|
* @return \OCP\AppFramework\Http\DataResponse |
89
|
|
|
*/ |
90
|
2 |
|
public function deleteJob($id) { |
91
|
2 |
|
return $this->handleNotFound( |
92
|
2 |
|
function () use ($id) { |
93
|
2 |
|
return $this->service->deleteJob($id, $this->userId); |
94
|
2 |
|
}); |
95
|
|
|
} |
96
|
|
|
} |