|
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
|
|
|
* @return DataResponse |
|
63
|
|
|
*/ |
|
64
|
2 |
|
public function process($languages, $files) { |
|
65
|
2 |
|
return $this->handleNotFound( |
|
66
|
|
|
function () use ($languages, $files) { |
|
67
|
2 |
|
return $this->service->process($languages, $files); |
|
68
|
2 |
|
}); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* @NoAdminRequired |
|
73
|
|
|
* |
|
74
|
|
|
* @return \OCP\AppFramework\Http\DataResponse |
|
75
|
|
|
*/ |
|
76
|
2 |
|
public function getAllJobs() { |
|
77
|
2 |
|
return $this->handleNotFound( |
|
78
|
|
|
function () { |
|
79
|
2 |
|
return $this->service->getAllJobsForUser($this->userId); |
|
80
|
2 |
|
}); |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
/** |
|
84
|
|
|
* @NoAdminRequired |
|
85
|
|
|
* |
|
86
|
|
|
* @param integer $id |
|
87
|
|
|
* @return \OCP\AppFramework\Http\DataResponse |
|
88
|
|
|
*/ |
|
89
|
2 |
|
public function deleteJob($id) { |
|
90
|
2 |
|
return $this->handleNotFound( |
|
91
|
2 |
|
function () use ($id) { |
|
92
|
2 |
|
return $this->service->deleteJob($id, $this->userId); |
|
93
|
2 |
|
}); |
|
94
|
|
|
} |
|
95
|
|
|
} |