Skip to content

Commit

Permalink
Simplifies hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
matiasdelellis committed Dec 17, 2019
1 parent cbb9c9b commit a42f2e4
Showing 1 changed file with 16 additions and 30 deletions.
46 changes: 16 additions & 30 deletions lib/Watcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,25 +108,22 @@ public function __construct(IConfig $config,
* @param Node $node
*/
public function postWrite(Node $node) {
$model = intval($this->config->getAppValue('facerecognition', 'model', AddDefaultFaceModel::DEFAULT_FACE_MODEL_ID));
$handleSharedFiles = $this->config->getAppValue('facerecognition', 'handle-shared-files', 'false');

if ($this->fileService->isUserFile($node)) {
$owner = $node->getOwner()->getUid();
}
else if ($handleSharedFiles === 'true' && $this->fileService->isSharedFile($node)) {
// If we are going to analyze the shared files, we must 'appropriate' it.
$owner = \OC::$server->getUserSession()->getUser()->getUID();
}
else {
// Nextcloud also sends the Hooks when create thumbnails for example.
if (!$this->fileService->isAllowedNode($node)) {
// Nextcloud sends the Hooks when create thumbnails for example.
return;
}

if ($node instanceof Folder) {
return;
}

$owner = \OC::$server->getUserSession()->getUser()->getUID();
if (!$this->userManager->userExists($owner)) {
$this->logger->debug(
"Skipping inserting image " . $node->getName() . " because it seems that user " . $owner . " doesn't exist");
return;
}

$enabled = $this->config->getUserValue($owner, 'facerecognition', 'enabled', 'false');
if ($enabled !== 'true') {
$this->logger->debug('The user ' . $owner . ' not have the analysis enabled. Skipping');
Expand All @@ -151,12 +148,6 @@ public function postWrite(Node $node) {
return;
}

if (!$this->userManager->userExists($owner)) {
$this->logger->debug(
"Skipping inserting image " . $node->getName() . " because it seems that user " . $owner . " doesn't exist");
return;
}

if ($this->fileService->isUnderNoDetection($node)) {
$this->logger->debug(
"Skipping inserting image " . $node->getName() . " because is inside an folder that contains a .nomedia file");
Expand All @@ -165,6 +156,8 @@ public function postWrite(Node $node) {

$this->logger->debug("Inserting/updating image " . $node->getName() . " for face recognition");

$model = intval($this->config->getAppValue('facerecognition', 'model', AddDefaultFaceModel::DEFAULT_FACE_MODEL_ID));

$image = new Image();
$image->setUser($owner);
$image->setFile($node->getId());
Expand Down Expand Up @@ -200,25 +193,16 @@ public function postWrite(Node $node) {
* @param Node $node
*/
public function postDelete(Node $node) {
$model = intval($this->config->getAppValue('facerecognition', 'model', AddDefaultFaceModel::DEFAULT_FACE_MODEL_ID));
$handleSharedFiles = $this->config->getAppValue('facerecognition', 'handle-shared-files', 'false');

if ($this->fileService->isUserFile($node)) {
$owner = $node->getOwner()->getUid();
}
else if ($handleSharedFiles === 'true' && $this->fileService->isSharedFile($node)) {
// If we are going to analyze the shared files, we must 'appropriate' it.
$owner = \OC::$server->getUserSession()->getUser()->getUID();
}
else {
// Nextcloud also sends the Hooks when create thumbnails for example.
if (!$this->fileService->isAllowedNode($node)) {
// Nextcloud sends the Hooks when create thumbnails for example.
return;
}

if ($node instanceof Folder) {
return;
}

$owner = \OC::$server->getUserSession()->getUser()->getUID();
$enabled = $this->config->getUserValue($owner, 'facerecognition', 'enabled', 'false');
if ($enabled !== 'true') {
$this->logger->debug('The user ' . $owner . ' not have the analysis enabled. Skipping');
Expand Down Expand Up @@ -246,6 +230,8 @@ public function postDelete(Node $node) {

$this->logger->debug("Deleting image " . $node->getName() . " from face recognition");

$model = intval($this->config->getAppValue('facerecognition', 'model', AddDefaultFaceModel::DEFAULT_FACE_MODEL_ID));

$image = new Image();
$image->setUser($owner);
$image->setFile($node->getId());
Expand Down

0 comments on commit a42f2e4

Please sign in to comment.