diff --git a/lib/Dav/Faces/FacePhoto.php b/lib/Dav/Faces/FacePhoto.php index 47482382..b8111200 100644 --- a/lib/Dav/Faces/FacePhoto.php +++ b/lib/Dav/Faces/FacePhoto.php @@ -7,7 +7,6 @@ namespace OCA\Recognize\Dav\Faces; use \Rubix\ML\Kernels\Distance\Euclidean; -use OC\Metadata\IMetadataManager; use OCA\Recognize\Db\FaceDetection; use OCA\Recognize\Db\FaceDetectionMapper; use OCA\Recognize\Service\FaceClusterAnalyzer; @@ -26,15 +25,13 @@ class FacePhoto implements IFile { private Folder $userFolder; private ?File $file = null; private ITagManager $tagManager; - private IMetadataManager $metadataManager; private IPreview $preview; - public function __construct(FaceDetectionMapper $detectionMapper, FaceDetection $faceDetection, Folder $userFolder, ITagManager $tagManager, IMetadataManager $metadataManager, IPreview $preview) { + public function __construct(FaceDetectionMapper $detectionMapper, FaceDetection $faceDetection, Folder $userFolder, ITagManager $tagManager, IPreview $preview) { $this->detectionMapper = $detectionMapper; $this->faceDetection = $faceDetection; $this->userFolder = $userFolder; $this->tagManager = $tagManager; - $this->metadataManager = $metadataManager; $this->preview = $preview; } @@ -77,7 +74,7 @@ public function setName($name) { public function put($data) { throw new Forbidden('Can\'t write to photos trough the faces api'); } - + public function getFile() : File { if ($this->file === null) { $nodes = $this->userFolder->getById($this->faceDetection->getFileId()); @@ -136,12 +133,6 @@ public function getLastModified() { return $this->getFile()->getMTime(); } - public function getMetadata(): string { - $file = $this->getFile(); - $sizeMetadata = $this->metadataManager->fetchMetadataFor('size', [$file->getId()])[$file->getId()]; - return json_encode($sizeMetadata->getDecodedValue()); - } - public function hasPreview(): bool { return $this->preview->isAvailable($this->getFile()); } diff --git a/lib/Dav/Faces/FaceRoot.php b/lib/Dav/Faces/FaceRoot.php index 234ef0e3..9bdb3297 100644 --- a/lib/Dav/Faces/FaceRoot.php +++ b/lib/Dav/Faces/FaceRoot.php @@ -6,7 +6,6 @@ declare(strict_types=1); namespace OCA\Recognize\Dav\Faces; -use OC\Metadata\IMetadataManager; use OCA\Recognize\Db\FaceCluster; use OCA\Recognize\Db\FaceClusterMapper; use OCA\Recognize\Db\FaceDetection; @@ -28,7 +27,6 @@ class FaceRoot implements ICollection, IMoveTarget { private IUser $user; private FaceDetectionMapper $detectionMapper; private IRootFolder $rootFolder; - private IMetadataManager $metadataManager; private ITagManager $tagManager; private IPreview $previewManager; /** @@ -36,13 +34,12 @@ class FaceRoot implements ICollection, IMoveTarget { */ private array $children = []; - public function __construct(FaceClusterMapper $clusterMapper, FaceCluster $cluster, IUser $user, FaceDetectionMapper $detectionMapper, IRootFolder $rootFolder, IMetadataManager $metadataManager, ITagManager $tagManager, IPreview $previewManager) { + public function __construct(FaceClusterMapper $clusterMapper, FaceCluster $cluster, IUser $user, FaceDetectionMapper $detectionMapper, IRootFolder $rootFolder, ITagManager $tagManager, IPreview $previewManager) { $this->clusterMapper = $clusterMapper; $this->cluster = $cluster; $this->user = $user; $this->detectionMapper = $detectionMapper; $this->rootFolder = $rootFolder; - $this->metadataManager = $metadataManager; $this->tagManager = $tagManager; $this->previewManager = $previewManager; } @@ -91,7 +88,7 @@ public function getChildren(): array { $detections = $this->detectionMapper->findByClusterId($this->cluster->getId()); $detectionsWithFile = array_filter($detections, fn (FaceDetection $detection): bool => current($this->rootFolder->getUserFolder($this->user->getUID())->getById($detection->getFileId())) !== false); $this->children = array_map(function (FaceDetection $detection) { - return new FacePhoto($this->detectionMapper, $detection, $this->rootFolder->getUserFolder($this->user->getUID()), $this->tagManager, $this->metadataManager, $this->previewManager); + return new FacePhoto($this->detectionMapper, $detection, $this->rootFolder->getUserFolder($this->user->getUID()), $this->tagManager, $this->previewManager); }, $detectionsWithFile); } return $this->children; @@ -112,7 +109,7 @@ public function getChild($name): FacePhoto { } catch (DoesNotExistException $e) { throw new NotFound(); } - return new FacePhoto($this->detectionMapper, $detection, $this->rootFolder->getUserFolder($this->user->getUID()), $this->tagManager, $this->metadataManager, $this->previewManager); + return new FacePhoto($this->detectionMapper, $detection, $this->rootFolder->getUserFolder($this->user->getUID()), $this->tagManager, $this->previewManager); } public function childExists($name): bool { diff --git a/lib/Dav/Faces/FacesHome.php b/lib/Dav/Faces/FacesHome.php index a7a89c1b..76e30f75 100644 --- a/lib/Dav/Faces/FacesHome.php +++ b/lib/Dav/Faces/FacesHome.php @@ -6,7 +6,6 @@ declare(strict_types=1); namespace OCA\Recognize\Dav\Faces; -use OC\Metadata\IMetadataManager; use OCA\Recognize\Db\FaceCluster; use OCA\Recognize\Db\FaceClusterMapper; use OCA\Recognize\Db\FaceDetectionMapper; @@ -26,16 +25,14 @@ class FacesHome implements ICollection { private IRootFolder $rootFolder; private array $children = []; private ITagManager $tagManager; - private IMetadataManager $metadataManager; private IPreview $previewManager; - public function __construct(FaceClusterMapper $faceClusterMapper, IUser $user, FaceDetectionMapper $faceDetectionMapper, IRootFolder $rootFolder, ITagManager $tagManager, IMetadataManager $metadataManager, IPreview $previewManager) { + public function __construct(FaceClusterMapper $faceClusterMapper, IUser $user, FaceDetectionMapper $faceDetectionMapper, IRootFolder $rootFolder, ITagManager $tagManager, IPreview $previewManager) { $this->faceClusterMapper = $faceClusterMapper; $this->user = $user; $this->faceDetectionMapper = $faceDetectionMapper; $this->rootFolder = $rootFolder; $this->tagManager = $tagManager; - $this->metadataManager = $metadataManager; $this->previewManager = $previewManager; } @@ -84,7 +81,7 @@ public function getChild($name) : FaceRoot { } } - return new FaceRoot($this->faceClusterMapper, $cluster, $this->user, $this->faceDetectionMapper, $this->rootFolder, $this->metadataManager, $this->tagManager, $this->previewManager); + return new FaceRoot($this->faceClusterMapper, $cluster, $this->user, $this->faceDetectionMapper, $this->rootFolder, $this->tagManager, $this->previewManager); } /** @@ -95,7 +92,7 @@ public function getChildren(): array { $clusters = $this->faceClusterMapper->findByUserId($this->user->getUID()); if (count($this->children) === 0) { $this->children = array_map(function (FaceCluster $cluster) { - return new FaceRoot($this->faceClusterMapper, $cluster, $this->user, $this->faceDetectionMapper, $this->rootFolder, $this->metadataManager, $this->tagManager, $this->previewManager); + return new FaceRoot($this->faceClusterMapper, $cluster, $this->user, $this->faceDetectionMapper, $this->rootFolder, $this->tagManager, $this->previewManager); }, $clusters); } return $this->children; diff --git a/lib/Dav/Faces/PropFindPlugin.php b/lib/Dav/Faces/PropFindPlugin.php index 805060f7..039d7c27 100644 --- a/lib/Dav/Faces/PropFindPlugin.php +++ b/lib/Dav/Faces/PropFindPlugin.php @@ -12,6 +12,7 @@ use OCA\Recognize\Db\FaceDetectionMapper; use OCA\Recognize\Db\FaceDetectionWithTitle; use OCP\Files\DavUtil; +use OCP\IPreview; use Sabre\DAV\INode; use Sabre\DAV\PropFind; use Sabre\DAV\Server; @@ -25,10 +26,11 @@ class PropFindPlugin extends ServerPlugin { public const FACE_PREVIEW_IMAGE_PROPERTYNAME = '{http://nextcloud.org/ns}face-preview-image'; private Server $server; - private FaceDetectionMapper $faceDetectionMapper; - public function __construct(FaceDetectionMapper $faceDetectionMapper) { - $this->faceDetectionMapper = $faceDetectionMapper; + public function __construct( + private FaceDetectionMapper $faceDetectionMapper, + private IPreview $previewManager, + ) { } public function initialize(Server $server) { @@ -40,10 +42,6 @@ public function initialize(Server $server) { public function propFind(PropFind $propFind, INode $node) { if ($node instanceof FacePhoto) { - $propFind->handle(self::FILE_NAME_PROPERTYNAME, function () use ($node) { - return $node->getFile()->getName(); - }); - $propFind->handle(self::FACE_DETECTIONS_PROPERTYNAME, function () use ($node) { return json_encode( array_map( @@ -52,14 +50,20 @@ public function propFind(PropFind $propFind, INode $node) { ) ); }); - $propFind->handle(FilesPlugin::INTERNAL_FILEID_PROPERTYNAME, fn () => $node->getFile()->getId()); + $propFind->handle(FilesPlugin::GETETAG_PROPERTYNAME, fn () => $node->getETag()); $propFind->handle(self::FILE_NAME_PROPERTYNAME, fn () => $node->getFile()->getName()); - $propFind->handle(self::REALPATH_PROPERTYNAME, fn () => $node->getFile()->getPath()); - $propFind->handle(FilesPlugin::FILE_METADATA_SIZE, fn () => $node->getMetadata()); - $propFind->handle(FilesPlugin::HAS_PREVIEW_PROPERTYNAME, fn () => json_encode($node->hasPreview())); $propFind->handle(TagsPlugin::FAVORITE_PROPERTYNAME, fn () => $node->isFavorite() ? 1 : 0); - $propFind->handle(FilesPlugin::PERMISSIONS_PROPERTYNAME, fn () => str_replace('G', '', DavUtil::getDavPermissions($node->getFile()->getFileInfo()))); + $propFind->handle(FilesPlugin::HAS_PREVIEW_PROPERTYNAME, fn () => json_encode($this->previewManager->isAvailable($node->getFile()->getFileInfo()))); + $propFind->handle(FilesPlugin::PERMISSIONS_PROPERTYNAME, function () use ($node): string { + $permissions = DavUtil::getDavPermissions($node->getFile()->getFileInfo()); + $filteredPermissions = str_replace('R', '', $permissions); + return $filteredPermissions; + }); + + foreach ($node->getFile()->getFileInfo()->getMetadata() as $metadataKey => $metadataValue) { + $propFind->handle(FilesPlugin::FILE_METADATA_PREFIX.$metadataKey, $metadataValue); + } } if ($node instanceof FaceRoot || $node instanceof UnassignedFacesHome) { diff --git a/lib/Dav/Faces/UnassignedFacePhoto.php b/lib/Dav/Faces/UnassignedFacePhoto.php index 3d080647..420c4d77 100644 --- a/lib/Dav/Faces/UnassignedFacePhoto.php +++ b/lib/Dav/Faces/UnassignedFacePhoto.php @@ -6,7 +6,6 @@ declare(strict_types=1); namespace OCA\Recognize\Dav\Faces; -use OC\Metadata\IMetadataManager; use OCA\Recognize\Db\FaceDetection; use OCA\Recognize\Db\FaceDetectionMapper; use OCP\Files\Folder; @@ -16,8 +15,8 @@ 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); + public function __construct(FaceDetectionMapper $detectionMapper, FaceDetection $faceDetection, Folder $userFolder, ITagManager $tagManager, IPreview $preview) { + parent::__construct($detectionMapper, $faceDetection, $userFolder, $tagManager, $preview); } /** diff --git a/lib/Dav/Faces/UnassignedFacesHome.php b/lib/Dav/Faces/UnassignedFacesHome.php index 0497ad5f..a64c2ef6 100644 --- a/lib/Dav/Faces/UnassignedFacesHome.php +++ b/lib/Dav/Faces/UnassignedFacesHome.php @@ -6,7 +6,6 @@ declare(strict_types=1); namespace OCA\Recognize\Dav\Faces; -use OC\Metadata\IMetadataManager; use OCA\Recognize\Db\FaceDetection; use OCA\Recognize\Db\FaceDetectionMapper; use OCP\AppFramework\Db\DoesNotExistException; @@ -24,10 +23,9 @@ class UnassignedFacesHome implements ICollection { 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) { + public function __construct(IUser $user, FaceDetectionMapper $faceDetectionMapper, IRootFolder $rootFolder, ITagManager $tagManager, IPreview $previewManager) { $this->user = $user; $this->faceDetectionMapper = $faceDetectionMapper; $this->rootFolder = $rootFolder; @@ -110,7 +108,7 @@ public function getChildren(): array { $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); }, $detectionsWithFile); - + return $this->children; } diff --git a/lib/Dav/RecognizeHome.php b/lib/Dav/RecognizeHome.php index 1992c67f..37cc4075 100644 --- a/lib/Dav/RecognizeHome.php +++ b/lib/Dav/RecognizeHome.php @@ -6,7 +6,6 @@ declare(strict_types=1); namespace OCA\Recognize\Dav; -use OC\Metadata\IMetadataManager; use OCA\Recognize\Dav\Faces\FacesHome; use OCA\Recognize\Dav\Faces\UnassignedFacesHome; use OCA\Recognize\Db\FaceClusterMapper; @@ -26,10 +25,9 @@ class RecognizeHome implements ICollection { private FaceDetectionMapper $faceDetectionMapper; private IRootFolder $rootFolder; private ITagManager $tagManager; - private IMetadataManager $metadataManager; private IPreview $previewManager; - public function __construct(array $principalInfo, FaceClusterMapper $faceClusterMapper, IUser $user, FaceDetectionMapper $faceDetectionMapper, IRootFolder $rootFolder, ITagManager $tagManager, IMetadataManager $metadataManager, IPreview $previewManager) { + public function __construct(array $principalInfo, FaceClusterMapper $faceClusterMapper, IUser $user, FaceDetectionMapper $faceDetectionMapper, IRootFolder $rootFolder, ITagManager $tagManager, IPreview $previewManager) { $this->principalInfo = $principalInfo; $this->faceClusterMapper = $faceClusterMapper; $this->user = $user; diff --git a/lib/Dav/RootCollection.php b/lib/Dav/RootCollection.php index 5883e01a..f8d900de 100644 --- a/lib/Dav/RootCollection.php +++ b/lib/Dav/RootCollection.php @@ -8,7 +8,6 @@ use \Sabre\DAVACL\AbstractPrincipalCollection; use \Sabre\DAVACL\PrincipalBackend\BackendInterface; -use OC\Metadata\IMetadataManager; use OCA\Recognize\Db\FaceClusterMapper; use OCA\Recognize\Db\FaceDetectionMapper; use OCP\Files\IRootFolder; @@ -23,17 +22,15 @@ class RootCollection extends AbstractPrincipalCollection { private FaceDetectionMapper $faceDetectionMapper; private IRootFolder $rootFolder; private ITagManager $tagManager; - private IMetadataManager $metadataManager; private IPreview $previewManager; - public function __construct(BackendInterface $principalBackend, IUserSession $userSession, FaceClusterMapper $faceClusterMapper, FaceDetectionMapper $faceDetectionMapper, IRootFolder $rootFolder, ITagManager $tagManager, IMetadataManager $metadataManager, IPreview $previewManager) { + public function __construct(BackendInterface $principalBackend, IUserSession $userSession, FaceClusterMapper $faceClusterMapper, FaceDetectionMapper $faceDetectionMapper, IRootFolder $rootFolder, ITagManager $tagManager, IPreview $previewManager) { parent::__construct($principalBackend, 'principals/users'); $this->userSession = $userSession; $this->faceClusterMapper = $faceClusterMapper; $this->faceDetectionMapper = $faceDetectionMapper; $this->rootFolder = $rootFolder; $this->tagManager = $tagManager; - $this->metadataManager = $metadataManager; $this->previewManager = $previewManager; } @@ -43,7 +40,7 @@ public function getChildForPrincipal(array $principalInfo): RecognizeHome { if (is_null($user) || $name !== $user->getUID()) { throw new Forbidden(); } - return new RecognizeHome($principalInfo, $this->faceClusterMapper, $user, $this->faceDetectionMapper, $this->rootFolder, $this->tagManager, $this->metadataManager, $this->previewManager); + return new RecognizeHome($principalInfo, $this->faceClusterMapper, $user, $this->faceDetectionMapper, $this->rootFolder, $this->tagManager, $this->previewManager); } public function getName() {