From 963a783747229d775267cf260f3a6851ade53fab Mon Sep 17 00:00:00 2001 From: tobiasKaminsky Date: Thu, 3 Aug 2023 14:51:09 +0200 Subject: expose gps data via webdav --- apps/dav/lib/Connector/Sabre/FilesPlugin.php | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'apps/dav') diff --git a/apps/dav/lib/Connector/Sabre/FilesPlugin.php b/apps/dav/lib/Connector/Sabre/FilesPlugin.php index 6b6f622a5a7..547071cc6af 100644 --- a/apps/dav/lib/Connector/Sabre/FilesPlugin.php +++ b/apps/dav/lib/Connector/Sabre/FilesPlugin.php @@ -84,6 +84,7 @@ class FilesPlugin extends ServerPlugin { public const SUBFOLDER_COUNT_PROPERTYNAME = '{http://nextcloud.org/ns}contained-folder-count'; public const SUBFILE_COUNT_PROPERTYNAME = '{http://nextcloud.org/ns}contained-file-count'; public const FILE_METADATA_SIZE = '{http://nextcloud.org/ns}file-metadata-size'; + public const FILE_METADATA_GPS = '{http://nextcloud.org/ns}file-metadata-gps'; /** Reference to main server object */ private ?Server $server = null; @@ -438,6 +439,27 @@ class FilesPlugin extends ServerPlugin { return $sizeMetadata->getValue(); }); + + $propFind->handle(self::FILE_METADATA_GPS, function () use ($node) { + if (!str_starts_with($node->getFileInfo()->getMimetype(), 'image')) { + return json_encode((object)[], JSON_THROW_ON_ERROR); + } + + if ($node->hasMetadata('gps')) { + $gpsMetadata = $node->getMetadata('gps'); + } else { + // This code path should not be called since we try to preload + // the metadata when loading the folder or the search results + // in one go + $metadataManager = \OC::$server->get(IMetadataManager::class); + $gpsMetadata = $metadataManager->fetchMetadataFor('gps', [$node->getId()])[$node->getId()]; + + // TODO would be nice to display this in the profiler... + \OC::$server->get(LoggerInterface::class)->debug('Inefficient fetching of metadata'); + } + + return $gpsMetadata->getValue(); + }); } } -- cgit v1.2.3