Skip to content

Commit 2f80087

Browse files
author
Julien Veyssier
committed
add optional WebDav propfind properties to show number of folders/files inside a folder
Signed-off-by: Julien Veyssier <[email protected]>
1 parent 4406a99 commit 2f80087

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

apps/dav/lib/Connector/Sabre/FilesPlugin.php

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@ class FilesPlugin extends ServerPlugin {
7676
public const UPLOAD_TIME_PROPERTYNAME = '{http://nextcloud.org/ns}upload_time';
7777
public const CREATION_TIME_PROPERTYNAME = '{http://nextcloud.org/ns}creation_time';
7878
public const SHARE_NOTE = '{http://nextcloud.org/ns}note';
79+
public const SUBFOLDER_COUNT_PROPERTYNAME = '{http://nextcloud.org/ns}contained-folder-count';
80+
public const SUBFILE_COUNT_PROPERTYNAME = '{http://nextcloud.org/ns}contained-file-count';
7981

8082
/**
8183
* Reference to main server object
@@ -429,14 +431,31 @@ public function handleGetProperties(PropFind $propFind, \Sabre\DAV\INode $node)
429431
});
430432
}
431433

432-
if ($node instanceof \OCA\DAV\Connector\Sabre\Directory) {
434+
if ($node instanceof Directory) {
433435
$propFind->handle(self::SIZE_PROPERTYNAME, function () use ($node) {
434436
return $node->getSize();
435437
});
436438

437439
$propFind->handle(self::IS_ENCRYPTED_PROPERTYNAME, function () use ($node) {
438440
return $node->getFileInfo()->isEncrypted() ? '1' : '0';
439441
});
442+
443+
$requestProperties = $propFind->getRequestedProperties();
444+
if (in_array(self::SUBFILE_COUNT_PROPERTYNAME, $requestProperties, true)
445+
|| in_array(self::SUBFOLDER_COUNT_PROPERTYNAME, $requestProperties, true)) {
446+
$nbFiles = 0;
447+
$nbFolders = 0;
448+
foreach ($node->getChildren() as $child) {
449+
if ($child instanceof File) {
450+
$nbFiles++;
451+
} elseif ($child instanceof Directory) {
452+
$nbFolders++;
453+
}
454+
}
455+
456+
$propFind->handle(self::SUBFILE_COUNT_PROPERTYNAME, $nbFiles);
457+
$propFind->handle(self::SUBFOLDER_COUNT_PROPERTYNAME, $nbFolders);
458+
}
440459
}
441460
}
442461

0 commit comments

Comments
 (0)