1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @copyright Copyright (c) 2021 Matias De lellis <[email protected]> |
4
|
|
|
* |
5
|
|
|
* @author Matias De lellis <[email protected]> |
6
|
|
|
* |
7
|
|
|
* @license GNU AGPL version 3 or any later version |
8
|
|
|
* |
9
|
|
|
* This program is free software: you can redistribute it and/or modify |
10
|
|
|
* it under the terms of the GNU Affero General Public License as |
11
|
|
|
* published by the Free Software Foundation, either version 3 of the |
12
|
|
|
* License, or (at your option) any later version. |
13
|
|
|
* |
14
|
|
|
* This program is distributed in the hope that it will be useful, |
15
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
16
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
17
|
|
|
* GNU Affero General Public License for more details. |
18
|
|
|
* |
19
|
|
|
* You should have received a copy of the GNU Affero General Public License |
20
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
21
|
|
|
* |
22
|
|
|
*/ |
23
|
|
|
|
24
|
|
|
namespace OCA\FaceRecognition\Service; |
25
|
|
|
|
26
|
|
|
use OCA\FaceRecognition\AppInfo\Application; |
27
|
|
|
|
28
|
|
|
use OCA\DAV\Connector\Sabre\Node as SabreNode; |
|
|
|
|
29
|
|
|
use Sabre\DAV\INode; |
|
|
|
|
30
|
|
|
use Sabre\DAV\PropFind; |
|
|
|
|
31
|
|
|
|
32
|
|
|
use OCA\FaceRecognition\Db\Image; |
33
|
|
|
use OCA\FaceRecognition\Db\ImageMapper; |
34
|
|
|
|
35
|
|
|
use OCA\FaceRecognition\Db\Face; |
36
|
|
|
use OCA\FaceRecognition\Db\FaceMapper; |
37
|
|
|
|
38
|
|
|
use OCA\FaceRecognition\Db\Person; |
39
|
|
|
use OCA\FaceRecognition\Db\PersonMapper; |
40
|
|
|
|
41
|
|
|
use OCA\FaceRecognition\Service\FileService; |
42
|
|
|
|
43
|
|
|
use OCA\FaceRecognition\Service\SettingsService; |
44
|
|
|
|
45
|
|
|
use OCA\FaceRecognition\Dav\PersonsList; |
46
|
|
|
|
47
|
|
|
class DavService { |
48
|
|
|
|
49
|
|
|
/** @var ImageMapper */ |
50
|
|
|
private $imageMapper; |
51
|
|
|
|
52
|
|
|
/** @var PersonMapper */ |
53
|
|
|
private $personMapper; |
54
|
|
|
|
55
|
|
|
/** @var FaceMapper */ |
56
|
|
|
private $faceMapper; |
57
|
|
|
|
58
|
|
|
/** @var FileService */ |
59
|
|
|
private $fileService; |
60
|
|
|
|
61
|
|
|
/** @var SettingsService */ |
62
|
|
|
private $settingsService; |
63
|
|
|
|
64
|
|
|
private $userId; |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* @var string |
68
|
|
|
*/ |
69
|
|
|
private $appName; |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* DavService constructor. |
73
|
|
|
* @param string $appName |
74
|
|
|
* @param string|null $userId |
75
|
|
|
*/ |
76
|
|
|
public function __construct(string $appName, |
77
|
|
|
ImageMapper $imageMapper, |
78
|
|
|
PersonMapper $personMapper, |
79
|
|
|
FaceMapper $faceMapper, |
80
|
|
|
FileService $fileService, |
81
|
|
|
SettingsService $settingsService, |
82
|
|
|
?string $userId) |
83
|
|
|
{ |
84
|
|
|
$this->appName = $appName; |
85
|
|
|
$this->imageMapper = $imageMapper; |
86
|
|
|
$this->personMapper = $personMapper; |
87
|
|
|
$this->faceMapper = $faceMapper; |
88
|
|
|
$this->fileService = $fileService; |
89
|
|
|
$this->settingsService = $settingsService; |
90
|
|
|
$this->userId = $userId; |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* Get approval state of a given file for a given user |
95
|
|
|
* @param int $fileId |
96
|
|
|
* @param string|null $userId |
97
|
|
|
* @return array state and rule id |
98
|
|
|
*/ |
99
|
|
|
public function getFaceRecognitionImage(int $fileId, ?string $userId): array { |
100
|
|
|
$response = array(); |
101
|
|
|
if (is_null($userId)) { |
102
|
|
|
$response['state'] = Application::STATE_UNDEFINED; |
103
|
|
|
return $response; |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
if (!$this->settingsService->getUserEnabled($userId)) { |
107
|
|
|
$response['state'] = Application::STATE_DISABLED; |
108
|
|
|
return $response; |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
$modelId = $this->settingsService->getCurrentFaceModel(); |
112
|
|
|
$image = $this->imageMapper->findFromFile($userId, $modelId, $fileId); |
113
|
|
|
if (!$image->getIsProcessed()) { |
114
|
|
|
$response['state'] = Application::STATE_UNDEFINED; |
115
|
|
|
return $response; |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
$personsImage = array(); |
119
|
|
|
$faces = $this->faceMapper->findFromFile($userId, $modelId, $fileId); |
120
|
|
|
foreach ($faces as $face) { |
121
|
|
|
$person = $this->personMapper->find($this->userId, $face->getPerson()); |
|
|
|
|
122
|
|
|
if (!$person->getIsVisible()) { |
123
|
|
|
continue; |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
$facePerson = array(); |
127
|
|
|
$facePerson['id'] = $person->getId(); |
128
|
|
|
$facePerson['name'] = $person->getName(); |
129
|
|
|
$facePerson['top'] = $face->getTop(); |
130
|
|
|
$facePerson['left'] = $face->getLeft(); |
131
|
|
|
$facePerson['width'] = $face->getRight() - $face->getLeft(); |
132
|
|
|
$facePerson['height'] = $face->getBottom() - $face->getTop(); |
133
|
|
|
|
134
|
|
|
$personsImage[] = $facePerson; |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
if (count($personsImage)) { |
138
|
|
|
$response['persons'] = $personsImage; |
139
|
|
|
return $response; |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
$response['state'] = Application::STATE_NO_PERSONS; |
143
|
|
|
return $response; |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
/** |
147
|
|
|
* Get persons as a WebDav attribute |
148
|
|
|
* |
149
|
|
|
* @param PropFind $propFind |
150
|
|
|
* @param INode $node |
151
|
|
|
* @return void |
152
|
|
|
*/ |
153
|
|
|
public function propFind(PropFind $propFind, INode $node): void { |
154
|
|
|
if (!$node instanceof SabreNode) { |
155
|
|
|
return; |
156
|
|
|
} |
157
|
|
|
|
158
|
|
|
$nodeId = $node->getId(); |
159
|
|
|
$image = $this->getFaceRecognitionImage($nodeId, $this->userId); |
160
|
|
|
$propFind->handle( |
161
|
|
|
Application::DAV_PROPERTY_PERSONS, function() use ($nodeId, $image) { |
|
|
|
|
162
|
|
|
if (isset($image['persons'])) { |
163
|
|
|
return new PersonsList($image['persons']); |
164
|
|
|
} |
165
|
|
|
return $image['state']; |
166
|
|
|
} |
167
|
|
|
); |
168
|
|
|
} |
169
|
|
|
|
170
|
|
|
} |
171
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths