Skip to content

Commit

Permalink
First steps of zip folder plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
DeepDiver1975 committed Oct 29, 2015
1 parent 530f722 commit 8f78ffa
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 0 deletions.
1 change: 1 addition & 0 deletions apps/dav/lib/server.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down
76 changes: 76 additions & 0 deletions apps/dav/lib/zipfolderplugin.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<?php
/**
* @author Thomas Müller <[email protected]>
*
* @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 <http://www.gnu.org/licenses/>
*
*/

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();
}
}

0 comments on commit 8f78ffa

Please sign in to comment.