3030use OC \Files \Search \SearchOrder ;
3131use OC \Files \Search \SearchQuery ;
3232use OC \Files \View ;
33+ use OC \Metadata \IMetadataManager ;
3334use OCA \DAV \Connector \Sabre \CachingTree ;
3435use OCA \DAV \Connector \Sabre \Directory ;
3536use OCA \DAV \Connector \Sabre \FilesPlugin ;
4445use OCP \IUser ;
4546use OCP \Share \IManager ;
4647use Sabre \DAV \Exception \NotFound ;
48+ use Sabre \DAV \INode ;
4749use SearchDAV \Backend \ISearchBackend ;
4850use SearchDAV \Backend \SearchPropertyDefinition ;
4951use SearchDAV \Backend \SearchResult ;
@@ -88,14 +90,12 @@ public function __construct(CachingTree $tree, IUser $user, IRootFolder $rootFol
8890
8991 /**
9092 * Search endpoint will be remote.php/dav
91- *
92- * @return string
9393 */
94- public function getArbiterPath () {
94+ public function getArbiterPath (): string {
9595 return '' ;
9696 }
9797
98- public function isValidScope ($ href , $ depth , $ path ) {
98+ public function isValidScope (string $ href , $ depth , ? string $ path ): bool {
9999 // only allow scopes inside the dav server
100100 if (is_null ($ path )) {
101101 return false ;
@@ -109,7 +109,7 @@ public function isValidScope($href, $depth, $path) {
109109 }
110110 }
111111
112- public function getPropertyDefinitionsForScope ($ href , $ path ) {
112+ public function getPropertyDefinitionsForScope (string $ href , ? string $ path ): array {
113113 // all valid scopes support the same schema
114114
115115 //todo dynamically load all propfind properties that are supported
@@ -132,15 +132,44 @@ public function getPropertyDefinitionsForScope($href, $path) {
132132 new SearchPropertyDefinition (FilesPlugin::OWNER_DISPLAY_NAME_PROPERTYNAME , false , true , false ),
133133 new SearchPropertyDefinition (FilesPlugin::DATA_FINGERPRINT_PROPERTYNAME , false , true , false ),
134134 new SearchPropertyDefinition (FilesPlugin::HAS_PREVIEW_PROPERTYNAME , false , true , false , SearchPropertyDefinition::DATATYPE_BOOLEAN ),
135+ new SearchPropertyDefinition (FilesPlugin::FILE_METADATA_SIZE , false , true , false , SearchPropertyDefinition::DATATYPE_STRING ),
135136 new SearchPropertyDefinition (FilesPlugin::FILEID_PROPERTYNAME , false , true , false , SearchPropertyDefinition::DATATYPE_NONNEGATIVE_INTEGER ),
136137 ];
137138 }
138139
140+ /**
141+ * @param INode[] $nodes
142+ * @param string[] $requestProperties
143+ */
144+ public function preloadPropertyFor (array $ nodes , array $ requestProperties ): void {
145+ if (in_array (FilesPlugin::FILE_METADATA_SIZE , $ requestProperties , true )) {
146+ // Preloading of the metadata
147+ $ fileIds = [];
148+ foreach ($ nodes as $ node ) {
149+ /** @var \OCP\Files\Node|\OCA\DAV\Connector\Sabre\Node $node */
150+ if (str_starts_with ($ node ->getFileInfo ()->getMimeType (), 'image/ ' )) {
151+ /** @var \OCA\DAV\Connector\Sabre\File $node */
152+ $ fileIds [] = $ node ->getFileInfo ()->getId ();
153+ }
154+ }
155+ /** @var IMetaDataManager $metadataManager */
156+ $ metadataManager = \OC ::$ server ->get (IMetadataManager::class);
157+ $ preloadedMetadata = $ metadataManager ->fetchMetadataFor ('size ' , $ fileIds );
158+ foreach ($ nodes as $ node ) {
159+ /** @var \OCP\Files\Node|\OCA\DAV\Connector\Sabre\Node $node */
160+ if (str_starts_with ($ node ->getFileInfo ()->getMimeType (), 'image/ ' )) {
161+ /** @var \OCA\DAV\Connector\Sabre\File $node */
162+ $ node ->setMetadata ('size ' , $ preloadedMetadata [$ node ->getFileInfo ()->getId ()]);
163+ }
164+ }
165+ }
166+ }
167+
139168 /**
140169 * @param Query $search
141170 * @return SearchResult[]
142171 */
143- public function search (Query $ search ) {
172+ public function search (Query $ search ): array {
144173 if (count ($ search ->from ) !== 1 ) {
145174 throw new \InvalidArgumentException ('Searching more than one folder is not supported ' );
146175 }
0 commit comments