mirror of
https://github.com/nextcloud/server.git
synced 2026-05-28 04:32:30 -04:00
Merge pull request #12854 from owncloud/add-direct-download-link
Adding foundation for the direct download url
This commit is contained in:
commit
cd53da43c0
5 changed files with 58 additions and 0 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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';
|
||||
|
||||
|
|
|
|||
|
|
@ -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 [];
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue