From 5b00bc1d6e36bb81aee02da612195a048e90a8b4 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Thomas=20M=C3=BCller?= <thomas.mueller@tmit.eu>
Date: Mon, 15 Dec 2014 15:20:24 +0100
Subject: [PATCH] Adding basement for the direct download url

---
 lib/private/connector/sabre/file.php        | 13 +++++++++++++
 lib/private/connector/sabre/filesplugin.php | 10 ++++++++++
 lib/private/files/storage/common.php        | 13 +++++++++++++
 lib/public/files/storage.php                | 10 ++++++++++
 4 files changed, 46 insertions(+)

diff --git a/lib/private/connector/sabre/file.php b/lib/private/connector/sabre/file.php
index 54eea54552..cb03f30e02 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 37798d8b16..b011a050a5 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 . '}dDU';
 
 		$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 . '}dDU';
+				$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 b3eda1165a..fe6aefbb42 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/public/files/storage.php b/lib/public/files/storage.php
index 323d20db56..36d5b800df 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);
 }
-- 
GitLab