diff --git a/apps/dav/lib/server.php b/apps/dav/lib/server.php index 055c5a5fc2c8..415bbaa512ee 100644 --- a/apps/dav/lib/server.php +++ b/apps/dav/lib/server.php @@ -32,6 +32,7 @@ public function __construct(IRequest $request, $baseUri) { $this->server->addPlugin(new BlockLegacyClientPlugin(\OC::$server->getConfig())); $this->server->addPlugin(new Plugin($authBackend, 'ownCloud')); + $this->server->addPlugin(new ZipFolderPlugin()); // wait with registering these until auth is handled and the filesystem is setup $this->server->on('beforeMethod', function () { diff --git a/apps/dav/lib/zipfolderplugin.php b/apps/dav/lib/zipfolderplugin.php new file mode 100644 index 000000000000..c692edf19149 --- /dev/null +++ b/apps/dav/lib/zipfolderplugin.php @@ -0,0 +1,76 @@ + + * + * @copyright Copyright (c) 2015, ownCloud, Inc. + * @license AGPL-3.0 + * + * This code is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License, version 3, + * along with this program. If not, see + * + */ + +namespace OCA\DAV; + +use OCA\DAV\Connector\Sabre\Directory; +use Sabre\DAV\Server; +use Sabre\DAV\ServerPlugin; +use Sabre\HTTP\RequestInterface; +use Sabre\HTTP\ResponseInterface; + +class ZipFolderPlugin extends ServerPlugin { + + /** @var Server */ + private $server; + + /** + * This initializes the plugin. + * + * This function is called by Sabre\DAV\Server, after + * addPlugin is called. + * + * This method should set up the required event subscriptions. + * + * @param Server $server + * @return void + */ + function initialize(Server $server) { + $this->server = $server; + $server->on('beforeMethod', array($this, 'downloadFolderAsZip'), 30); + } + + function downloadFolderAsZip(RequestInterface $request, ResponseInterface $response) { + if ($request->getMethod() !== 'GET') { + return; + } + $path = $request->getPath(); + if ($this->server->tree->nodeExists($path)) + return; + + $elements = pathinfo($path); + $ext = isset($elements['extension']) ? $elements['extension'] : null; + if (is_null($ext) || !in_array($ext, ['zip', 'tar'])) { + return; + } + + $pathToFolder = substr($path, 0, -4); + $node = $this->server->tree->getNodeForPath($pathToFolder); + + if (!$node instanceof Directory) + return; + + // + // TODO: build a Tar and a Zip Streamer which use php streams + // + $response->setBody(); + } +}