Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'apps/dav/lib/Files/FileSearchBackend.php')
-rw-r--r--apps/dav/lib/Files/FileSearchBackend.php41
1 files changed, 35 insertions, 6 deletions
diff --git a/apps/dav/lib/Files/FileSearchBackend.php b/apps/dav/lib/Files/FileSearchBackend.php
index 45e911db182..21eb14a29bd 100644
--- a/apps/dav/lib/Files/FileSearchBackend.php
+++ b/apps/dav/lib/Files/FileSearchBackend.php
@@ -30,6 +30,7 @@ use OC\Files\Search\SearchComparison;
use OC\Files\Search\SearchOrder;
use OC\Files\Search\SearchQuery;
use OC\Files\View;
+use OC\Metadata\IMetadataManager;
use OCA\DAV\Connector\Sabre\CachingTree;
use OCA\DAV\Connector\Sabre\Directory;
use OCA\DAV\Connector\Sabre\FilesPlugin;
@@ -44,6 +45,7 @@ use OCP\Files\Search\ISearchQuery;
use OCP\IUser;
use OCP\Share\IManager;
use Sabre\DAV\Exception\NotFound;
+use Sabre\DAV\INode;
use SearchDAV\Backend\ISearchBackend;
use SearchDAV\Backend\SearchPropertyDefinition;
use SearchDAV\Backend\SearchResult;
@@ -88,14 +90,12 @@ class FileSearchBackend implements ISearchBackend {
/**
* Search endpoint will be remote.php/dav
- *
- * @return string
*/
- public function getArbiterPath() {
+ public function getArbiterPath(): string {
return '';
}
- public function isValidScope($href, $depth, $path) {
+ public function isValidScope(string $href, $depth, ?string $path): bool {
// only allow scopes inside the dav server
if (is_null($path)) {
return false;
@@ -109,7 +109,7 @@ class FileSearchBackend implements ISearchBackend {
}
}
- public function getPropertyDefinitionsForScope($href, $path) {
+ public function getPropertyDefinitionsForScope(string $href, ?string $path): array {
// all valid scopes support the same schema
//todo dynamically load all propfind properties that are supported
@@ -132,15 +132,44 @@ class FileSearchBackend implements ISearchBackend {
new SearchPropertyDefinition(FilesPlugin::OWNER_DISPLAY_NAME_PROPERTYNAME, false, true, false),
new SearchPropertyDefinition(FilesPlugin::DATA_FINGERPRINT_PROPERTYNAME, false, true, false),
new SearchPropertyDefinition(FilesPlugin::HAS_PREVIEW_PROPERTYNAME, false, true, false, SearchPropertyDefinition::DATATYPE_BOOLEAN),
+ new SearchPropertyDefinition(FilesPlugin::FILE_METADATA_SIZE, false, true, false, SearchPropertyDefinition::DATATYPE_STRING),
new SearchPropertyDefinition(FilesPlugin::FILEID_PROPERTYNAME, false, true, false, SearchPropertyDefinition::DATATYPE_NONNEGATIVE_INTEGER),
];
}
/**
+ * @param INode[] $nodes
+ * @param string[] $requestProperties
+ */
+ public function preloadPropertyFor(array $nodes, array $requestProperties): void {
+ if (in_array(FilesPlugin::FILE_METADATA_SIZE, $requestProperties, true)) {
+ // Preloading of the metadata
+ $fileIds = [];
+ foreach ($nodes as $node) {
+ /** @var \OCP\Files\Node|\OCA\DAV\Connector\Sabre\Node $node */
+ if (str_starts_with($node->getFileInfo()->getMimeType(), 'image/')) {
+ /** @var \OCA\DAV\Connector\Sabre\File $node */
+ $fileIds[] = $node->getFileInfo()->getId();
+ }
+ }
+ /** @var IMetaDataManager $metadataManager */
+ $metadataManager = \OC::$server->get(IMetadataManager::class);
+ $preloadedMetadata = $metadataManager->fetchMetadataFor('size', $fileIds);
+ foreach ($nodes as $node) {
+ /** @var \OCP\Files\Node|\OCA\DAV\Connector\Sabre\Node $node */
+ if (str_starts_with($node->getFileInfo()->getMimeType(), 'image/')) {
+ /** @var \OCA\DAV\Connector\Sabre\File $node */
+ $node->setMetadata('size', $preloadedMetadata[$node->getFileInfo()->getId()]);
+ }
+ }
+ }
+ }
+
+ /**
* @param Query $search
* @return SearchResult[]
*/
- public function search(Query $search) {
+ public function search(Query $search): array {
if (count($search->from) !== 1) {
throw new \InvalidArgumentException('Searching more than one folder is not supported');
}