|
1
|
|
|
<?php |
|
2
|
|
|
namespace OCA\FaceRecognition\Controller; |
|
3
|
|
|
|
|
4
|
|
|
use OCP\IRequest; |
|
5
|
|
|
use OCP\IConfig; |
|
6
|
|
|
use OCP\Files\IRootFolder; |
|
7
|
|
|
use OCP\AppFramework\Http; |
|
8
|
|
|
use OCP\AppFramework\Http\DataResponse; |
|
9
|
|
|
use OCP\AppFramework\Http\JSONResponse; |
|
10
|
|
|
use OCP\AppFramework\Http\DataDisplayResponse; |
|
11
|
|
|
use OCP\AppFramework\Controller; |
|
12
|
|
|
|
|
13
|
|
|
use OCA\FaceRecognition\Db\FaceNew; |
|
14
|
|
|
use OCA\FaceRecognition\Db\FaceNewMapper; |
|
15
|
|
|
|
|
16
|
|
|
use OCA\FaceRecognition\Db\Person; |
|
17
|
|
|
use OCA\FaceRecognition\Db\PersonMapper; |
|
18
|
|
|
|
|
19
|
|
|
use OCA\FaceRecognition\Migration\AddDefaultFaceModel; |
|
20
|
|
|
|
|
21
|
|
|
class FileController extends Controller { |
|
22
|
|
|
|
|
23
|
|
|
private $config; |
|
24
|
|
|
|
|
25
|
|
|
private $personMapper; |
|
26
|
|
|
|
|
27
|
|
|
private $faceNewMapper; |
|
28
|
|
|
|
|
29
|
|
|
private $rootFolder; |
|
30
|
|
|
|
|
31
|
|
|
private $userId; |
|
32
|
|
|
|
|
33
|
|
View Code Duplication |
public function __construct($AppName, IRequest $request, IConfig $config, |
|
|
|
|
|
|
34
|
|
|
PersonMapper $personmapper, |
|
35
|
|
|
FaceNewMapper $facenewmapper, |
|
36
|
|
|
IRootFolder $rootFolder, |
|
37
|
|
|
$UserId) |
|
38
|
|
|
{ |
|
39
|
|
|
parent::__construct($AppName, $request); |
|
40
|
|
|
$this->config = $config; |
|
41
|
|
|
$this->personMapper = $personmapper; |
|
42
|
|
|
$this->faceNewMapper = $facenewmapper; |
|
43
|
|
|
$this->rootFolder = $rootFolder; |
|
44
|
|
|
$this->userId = $UserId; |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* @NoAdminRequired |
|
49
|
|
|
*/ |
|
50
|
|
|
public function getPersonsFromPath(string $fullpath) { |
|
51
|
|
|
$model = intval($this->config->getAppValue('facerecognition', 'model', AddDefaultFaceModel::DEFAULT_FACE_MODEL_ID)); |
|
52
|
|
|
|
|
53
|
|
|
$userFolder = $this->rootFolder->getUserFolder($this->userId); |
|
54
|
|
|
$fileId = $userFolder->get($fullpath)->getId(); |
|
55
|
|
|
|
|
56
|
|
|
$resp = array(); |
|
57
|
|
|
$persons = $this->personMapper->findFromFile($this->userId, $fileId); |
|
58
|
|
|
foreach ($persons as $person) { |
|
59
|
|
|
$face = $this->faceNewMapper->getPersonOnFile($this->userId, $person->getId(), $fileId, $model); |
|
60
|
|
|
if (!count($face)) |
|
61
|
|
|
continue; |
|
62
|
|
|
|
|
63
|
|
|
$facePerson = array(); |
|
64
|
|
|
$facePerson['name'] = $person->getName(); |
|
65
|
|
|
$facePerson['person_id'] = $person->getId(); |
|
66
|
|
|
$facePerson['face'] = $face[0]; |
|
67
|
|
|
|
|
68
|
|
|
$resp[] = $facePerson; |
|
69
|
|
|
} |
|
70
|
|
|
return new DataResponse($resp); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
} |
|
74
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.