@@ -50,6 +50,7 @@ class FilesPlugin extends ServerPlugin {
5050 public const OCM_SHARE_PERMISSIONS_PROPERTYNAME = '{http://open-cloud-mesh.org/ns}share-permissions ' ;
5151 public const SHARE_ATTRIBUTES_PROPERTYNAME = '{http://nextcloud.org/ns}share-attributes ' ;
5252 public const DOWNLOADURL_PROPERTYNAME = '{http://owncloud.org/ns}downloadURL ' ;
53+ public const DOWNLOADURL_EXPIRATION_PROPERTYNAME = '{http://nextcloud.org/ns}download-url-expiration ' ;
5354 public const SIZE_PROPERTYNAME = '{http://owncloud.org/ns}size ' ;
5455 public const GETETAG_PROPERTYNAME = '{DAV:}getetag ' ;
5556 public const LASTMODIFIED_PROPERTYNAME = '{DAV:}lastmodified ' ;
@@ -120,6 +121,7 @@ public function initialize(Server $server) {
120121 $ server ->protectedProperties [] = self ::SHARE_ATTRIBUTES_PROPERTYNAME ;
121122 $ server ->protectedProperties [] = self ::SIZE_PROPERTYNAME ;
122123 $ server ->protectedProperties [] = self ::DOWNLOADURL_PROPERTYNAME ;
124+ $ server ->protectedProperties [] = self ::DOWNLOADURL_EXPIRATION_PROPERTYNAME ;
123125 $ server ->protectedProperties [] = self ::OWNER_ID_PROPERTYNAME ;
124126 $ server ->protectedProperties [] = self ::OWNER_DISPLAY_NAME_PROPERTYNAME ;
125127 $ server ->protectedProperties [] = self ::CHECKSUMS_PROPERTYNAME ;
@@ -471,16 +473,32 @@ public function handleGetProperties(PropFind $propFind, \Sabre\DAV\INode $node)
471473 }
472474
473475 if ($ node instanceof File) {
474- $ propFind ->handle (self ::DOWNLOADURL_PROPERTYNAME , function () use ($ node ) {
476+ $ requestProperties = $ propFind ->getRequestedProperties ();
477+ if (in_array (self ::DOWNLOADURL_PROPERTYNAME , $ requestProperties , true )
478+ || in_array (self ::DOWNLOADURL_EXPIRATION_PROPERTYNAME , $ requestProperties , true )) {
475479 try {
476480 $ directDownloadUrl = $ node ->getDirectDownload ();
477- if (isset ($ directDownloadUrl ['url ' ])) {
478- return $ directDownloadUrl ['url ' ];
481+ if ($ directDownloadUrl && isset ($ directDownloadUrl ['url ' ])) {
482+ $ propFind ->handle (self ::DOWNLOADURL_PROPERTYNAME , $ directDownloadUrl ['url ' ]);
483+ $ propFind ->handle (self ::DOWNLOADURL_EXPIRATION_PROPERTYNAME , $ directDownloadUrl ['expiration ' ]);
479484 }
480- } catch (StorageNotAvailableException $ e ) {
481- return false ;
482- } catch (ForbiddenException $ e ) {
483- return false ;
485+ } catch (StorageNotAvailableException |ForbiddenException ) {
486+ $ propFind ->handle (self ::DOWNLOADURL_PROPERTYNAME , false );
487+ $ propFind ->handle (self ::DOWNLOADURL_EXPIRATION_PROPERTYNAME , false );
488+ }
489+ }
490+
491+ $ propFind ->handle (self ::PREVIEW_METADATA_PROPERTYNAME , function () use ($ node ) {
492+ try {
493+ if (isset ($ this ->previewMetadataCache [$ node ->getInternalFileId ()])) {
494+ $ previews = $ this ->previewMetadataCache [$ node ->getInternalFileId ()];
495+ } else {
496+ [$ node ->getInternalFileId () => $ previews ] = $ this ->previewService ->getAvailablePreviews ([$ node ->getInternalFileId ()]);
497+ }
498+
499+ $ data = array_map (static fn (Preview $ preview ) => $ preview ->jsonSerialize (), $ previews );
500+ return json_encode ($ data , JSON_THROW_ON_ERROR );
501+ } catch (\Exception $ e ) {
484502 }
485503 return false ;
486504 });
0 commit comments