diff --git a/lib/private/connector/sabre/file.php b/lib/private/connector/sabre/file.php index 54eea54552fdf804ad397073baf634e00c1c8329..cb03f30e023dbd5761704c023d9790c4321a42ed 100644 --- a/lib/private/connector/sabre/file.php +++ b/lib/private/connector/sabre/file.php @@ -226,6 +226,19 @@ class OC_Connector_Sabre_File extends OC_Connector_Sabre_Node implements \Sabre\ return \OC_Helper::getSecureMimeType($mimeType); } + public function getDirectDownload() { + if (\OCP\App::isEnabled('encryption')) { + return []; + } + /** @var \OCP\Files\Storage $storage */ + list($storage, $internalPath) = $this->fileView->resolvePath($this->path); + if (is_null($storage)) { + return []; + } + + return $storage->getDirectDownload($internalPath); + } + /** * @param resource $data * @return null|string diff --git a/lib/private/connector/sabre/filesplugin.php b/lib/private/connector/sabre/filesplugin.php index 37798d8b162bd7e85abba8a0b84d880c6f6ae904..ff5a6cc8b4b1dc260d79b9921a22351f8fbe62de 100644 --- a/lib/private/connector/sabre/filesplugin.php +++ b/lib/private/connector/sabre/filesplugin.php @@ -39,6 +39,7 @@ class OC_Connector_Sabre_FilesPlugin extends \Sabre\DAV\ServerPlugin $server->protectedProperties[] = '{' . self::NS_OWNCLOUD . '}id'; $server->protectedProperties[] = '{' . self::NS_OWNCLOUD . '}permissions'; $server->protectedProperties[] = '{' . self::NS_OWNCLOUD . '}size'; + $server->protectedProperties[] = '{' . self::NS_OWNCLOUD . '}downloadURL'; $this->server = $server; $this->server->subscribeEvent('beforeGetProperties', array($this, 'beforeGetProperties')); @@ -80,6 +81,15 @@ class OC_Connector_Sabre_FilesPlugin extends \Sabre\DAV\ServerPlugin } } + if ($node instanceof OC_Connector_Sabre_File) { + /** @var $node OC_Connector_Sabre_File */ + $directDownloadUrl = $node->getDirectDownload(); + if (isset($directDownloadUrl['url'])) { + $directDownloadUrlPropertyName = '{' . self::NS_OWNCLOUD . '}downloadURL'; + $returnedProperties[200][$directDownloadUrlPropertyName] = $directDownloadUrl['url']; + } + } + if ($node instanceof OC_Connector_Sabre_Directory) { $sizePropertyName = '{' . self::NS_OWNCLOUD . '}size'; diff --git a/lib/private/files/storage/common.php b/lib/private/files/storage/common.php index b3eda1165ab62b80c9d29b2cff97522738a2f3a3..fe6aefbb42ee9b7c04b17e913aecc8f8aaf1c44e 100644 --- a/lib/private/files/storage/common.php +++ b/lib/private/files/storage/common.php @@ -437,4 +437,17 @@ abstract class Common implements \OC\Files\Storage\Storage { public function instanceOfStorage($class) { return is_a($this, $class); } + + /** + * A custom storage implementation can return an url for direct download of a give file. + * + * For now the returned array can hold the parameter url - in future more attributes might follow. + * + * @param string $path + * @return array + */ + public function getDirectDownload($path) { + return []; + } + } diff --git a/lib/private/files/storage/wrapper/wrapper.php b/lib/private/files/storage/wrapper/wrapper.php index d899c88363f20bd387cd171903b3b6aa48d55041..ea9de2873611bb582e20905de227e28327492d27 100644 --- a/lib/private/files/storage/wrapper/wrapper.php +++ b/lib/private/files/storage/wrapper/wrapper.php @@ -465,4 +465,16 @@ class Wrapper implements \OC\Files\Storage\Storage { public function __call($method, $args) { return call_user_func_array(array($this->storage, $method), $args); } + + /** + * A custom storage implementation can return an url for direct download of a give file. + * + * For now the returned array can hold the parameter url - in future more attributes might follow. + * + * @param string $path + * @return array + */ + public function getDirectDownload($path) { + return $this->storage->getDirectDownload($path); + } } diff --git a/lib/public/files/storage.php b/lib/public/files/storage.php index 323d20db564ee574448aeff584b6785cc8026988..36d5b800df6aaceca4bcb2d0dfefd00824b5ed4c 100644 --- a/lib/public/files/storage.php +++ b/lib/public/files/storage.php @@ -335,4 +335,14 @@ interface Storage { * @return bool */ public function instanceOfStorage($class); + + /** + * A custom storage implementation can return an url for direct download of a give file. + * + * For now the returned array can hold the parameter url - in future more attributes might follow. + * + * @param string $path + * @return array + */ + public function getDirectDownload($path); }