Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(dav): Add an unassigned-faces DAV collection
fixes #442 also see nextcloud/photos#1832 Signed-off-by: Marcel Klehr <mklehr@gmx.net>
- Loading branch information
1 parent
810737e
commit 44f91a6
Showing
8 changed files
with
178 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
/* | ||
* Copyright (c) 2022 The Recognize contributors. | ||
* This file is licensed under the Affero General Public License version 3 or later. See the COPYING file. | ||
*/ | ||
|
||
namespace OCA\Recognize\Dav\Faces; | ||
|
||
use OC\Metadata\IMetadataManager; | ||
use OCA\Recognize\Db\FaceDetection; | ||
use OCA\Recognize\Db\FaceDetectionMapper; | ||
use OCP\Files\Folder; | ||
use OCP\IPreview; | ||
use OCP\ITagManager; | ||
use Sabre\DAV\Exception\Forbidden; | ||
|
||
class UnassignedFacePhoto extends FacePhoto { | ||
|
||
public function __construct(FaceDetectionMapper $detectionMapper, FaceDetection $faceDetection, Folder $userFolder, ITagManager $tagManager, IMetadataManager $metadataManager, IPreview $preview) { | ||
parent::__construct($detectionMapper, $faceDetection, $userFolder, $tagManager, $metadataManager, $preview); | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
* @throws \OCP\DB\Exception | ||
*/ | ||
public function delete() { | ||
throw new Forbidden('Cannot delete unassigned photos'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
<?php | ||
/* | ||
* Copyright (c) 2022 The Recognize contributors. | ||
* This file is licensed under the Affero General Public License version 3 or later. See the COPYING file. | ||
*/ | ||
|
||
namespace OCA\Recognize\Dav\Faces; | ||
|
||
use OC\Metadata\IMetadataManager; | ||
use OCA\Recognize\Db\FaceDetection; | ||
use OCA\Recognize\Db\FaceDetectionMapper; | ||
use OCP\AppFramework\Db\DoesNotExistException; | ||
use OCP\Files\IRootFolder; | ||
use OCP\IPreview; | ||
use OCP\ITagManager; | ||
use OCP\IUser; | ||
use Sabre\DAV\Exception\Forbidden; | ||
use Sabre\DAV\Exception\NotFound; | ||
use Sabre\DAV\ICollection; | ||
|
||
class UnassignedFacesHome implements ICollection { | ||
private IUser $user; | ||
private FaceDetectionMapper $faceDetectionMapper; | ||
private IRootFolder $rootFolder; | ||
private array $children = []; | ||
private ITagManager $tagManager; | ||
private IMetadataManager $metadataManager; | ||
private IPreview $previewManager; | ||
|
||
public function __construct(IUser $user, FaceDetectionMapper $faceDetectionMapper, IRootFolder $rootFolder, ITagManager $tagManager, IMetadataManager $metadataManager, IPreview $previewManager) { | ||
$this->user = $user; | ||
$this->faceDetectionMapper = $faceDetectionMapper; | ||
$this->rootFolder = $rootFolder; | ||
$this->tagManager = $tagManager; | ||
$this->metadataManager = $metadataManager; | ||
$this->previewManager = $previewManager; | ||
} | ||
|
||
public function delete() { | ||
throw new Forbidden(); | ||
} | ||
|
||
public function getName(): string { | ||
return 'unassigned-faces'; | ||
} | ||
|
||
public function setName($name) { | ||
throw new Forbidden('Permission denied to rename this folder'); | ||
} | ||
|
||
public function createDirectory($name) { | ||
throw new Forbidden('Not allowed to create directories in this folder'); | ||
} | ||
|
||
public function createFile($name, $data = null) { | ||
throw new Forbidden('Not allowed to create files in this folder'); | ||
} | ||
|
||
/** | ||
* @param $name | ||
* @return FacePhoto | ||
* @throws NotFound | ||
* @throws \OCP\AppFramework\Db\MultipleObjectsReturnedException | ||
* @throws \OCP\DB\Exception | ||
* @throws \OCP\Files\NotPermittedException | ||
* @throws \OC\User\NoUserException | ||
*/ | ||
public function getChild($name): FacePhoto { | ||
if (count($this->children) !== 0) { | ||
foreach ($this->getChildren() as $child) { | ||
if ($child->getName() === $name) { | ||
return $child; | ||
} | ||
} | ||
throw new NotFound("$name not found"); | ||
} | ||
[$detectionId,] = explode('-', $name); | ||
try { | ||
$detection = $this->faceDetectionMapper->find((int)$detectionId); | ||
} catch (DoesNotExistException $e) { | ||
throw new NotFound(); | ||
} | ||
if ($detection->getClusterId() !== -1) { | ||
throw new NotFound(); | ||
} | ||
|
||
return new UnassignedFacePhoto($this->faceDetectionMapper, $detection, $this->rootFolder->getUserFolder($this->user->getUID()), $this->tagManager, $this->metadataManager, $this->previewManager); | ||
} | ||
|
||
public function childExists($name): bool { | ||
try { | ||
$this->getChild($name); | ||
return true; | ||
} catch (NotFound $e) { | ||
return false; | ||
} | ||
} | ||
|
||
/** | ||
* @throws \OCP\Files\NotPermittedException | ||
* @throws \OC\User\NoUserException | ||
*/ | ||
public function getChildren(): array { | ||
if (count($this->children) !== 0) { | ||
return $this->children; | ||
} | ||
return $this->children = array_map(function (FaceDetection $detection) { | ||
return new UnassignedFacePhoto($this->faceDetectionMapper, $detection, $this->rootFolder->getUserFolder($this->user->getUID()), $this->tagManager, $this->metadataManager, $this->previewManager); | ||
}, $this->faceDetectionMapper->findRejectedByUserId($this->user->getUID())); | ||
} | ||
|
||
public function getLastModified(): int { | ||
return 0; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters