Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding meta data file tree to node api #29207

Merged
merged 8 commits into from
Nov 8, 2017
80 changes: 80 additions & 0 deletions apps/dav/lib/Meta/MetaFile.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
<?php
/**
* @author Thomas Müller <thomas.mueller@tmit.eu>
*
* @copyright Copyright (c) 2017, ownCloud GmbH
* @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\Meta;


use Sabre\DAV\File;

class MetaFile extends File {

/** @var \OCP\Files\File */
private $file;

/**
* MetaFolder constructor.
*
* @param \OCP\Files\File $file
*/
public function __construct(\OCP\Files\File $file) {
$this->file = $file;
}

/**
* @inheritdoc
*/
function getName() {
return $this->file->getName();
}

/**
* @inheritdoc
*/
function getSize() {
return $this->file->getSize();
}

/**
* @inheritdoc
*/
public function get() {
return $this->file->fopen('r');
}

/**
* @inheritdoc
*/
public function getContentType() {
return $this->file->getMimeType();
}

/**
* @inheritdoc
*/
public function getLastModified() {
return $this->file->getMTime();
}

public function getETag() {
return $this->file->getEtag();
}
}
72 changes: 72 additions & 0 deletions apps/dav/lib/Meta/MetaFolder.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<?php
/**
* @author Thomas Müller <thomas.mueller@tmit.eu>
*
* @copyright Copyright (c) 2017, ownCloud GmbH
* @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\Meta;


use OCP\Files\File;
use OCP\Files\Folder;
use OCP\Files\Node;
use Sabre\DAV\Collection;

class MetaFolder extends Collection {

/** @var Folder */
private $folder;

/**
* MetaFolder constructor.
*
* @param Folder $folder
*/
public function __construct(Folder $folder) {
$this->folder = $folder;
}

/**
* @inheritdoc
*/
function getChildren() {
$nodes = $this->folder->getDirectoryListing();
return array_map(function($node) {
return static::nodeFactory($node);
}, $nodes);
}

/**
* @inheritdoc
*/
function getName() {
return $this->folder->getName();
}

public static function nodeFactory(Node $node) {
if ($node instanceof Folder) {
return new MetaFolder($node);
}
if ($node instanceof File) {
return new MetaFile($node);
}
throw new \InvalidArgumentException();
}

}
74 changes: 74 additions & 0 deletions apps/dav/lib/Meta/RootCollection.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<?php
/**
* @author Thomas Müller <thomas.mueller@tmit.eu>
*
* @copyright Copyright (c) 2017, ownCloud GmbH
* @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\Meta;


use OCP\Files\File;
use OCP\Files\Folder;
use OCP\Files\IRootFolder;
use OCP\Files\Node;
use OCP\Files\NotFoundException;
use Sabre\DAV\Collection;
use Sabre\DAV\Exception\MethodNotAllowed;
use Sabre\DAV\Exception\NotFound;

class RootCollection extends Collection {

/** @var IRootFolder */
private $rootFolder;

/**
* RootCollection constructor.
*
* @param IRootFolder $rootFolder
*/
public function __construct(IRootFolder $rootFolder) {
$this->rootFolder = $rootFolder;
}

/**
* @inheritdoc
*/
public function getChild($name) {
try {
$child = $this->rootFolder->get("meta/$name");
return MetaFolder::nodeFactory($child);
} catch (NotFoundException $ex) {
throw new NotFound();
}
}

/**
* @inheritdoc
*/
function getChildren() {
throw new MethodNotAllowed('Listing members of this collection is disabled');
}

/**
* @inheritdoc
*/
function getName() {
return 'meta';
}
}
3 changes: 2 additions & 1 deletion apps/dav/lib/RootCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,8 @@ public function __construct() {
$systemTagCollection,
$systemTagRelationsCollection,
$uploadCollection,
$avatarCollection
$avatarCollection,
new \OCA\DAV\Meta\RootCollection(\OC::$server->getRootFolder())
];

parent::__construct('root', $children);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@


use OCA\Federation\BackgroundJob\GetSharedSecret;
use OCA\Files_Sharing\Tests\TestCase;
use OCA\Federation\DbHandler;
use OCA\Federation\TrustedServers;
use OCP\AppFramework\Http;
Expand All @@ -35,6 +34,7 @@
use OCP\Http\Client\IResponse;
use OCP\ILogger;
use OCP\IURLGenerator;
use Test\TestCase;

/**
* Class GetSharedSecretTest
Expand Down
9 changes: 9 additions & 0 deletions apps/files_versions/lib/Storage.php
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,10 @@ public static function getVersions($uid, $filename, $userFullPath = '') {
$versions[$key]['path'] = Filesystem::normalizePath($pathinfo['dirname'] . '/' . $filename);
$versions[$key]['name'] = $versionedFile;
$versions[$key]['size'] = $view->filesize($dir . '/' . $entryName);
$versions[$key]['timestamp'] = $timestamp;
$versions[$key]['etag'] = $view->getETag($dir . '/' . $entryName);
$versions[$key]['storage_location'] = "$dir/$entryName";
$versions[$key]['owner'] = $uid;
}
}
}
Expand Down Expand Up @@ -832,4 +836,9 @@ protected static function getExpiration(){
return self::$application->getContainer()->query('Expiration');
}

public static function getContentOfVersion($uid, $storage_location) {
$users_view = new View('/'.$uid);
return $users_view->fopen($storage_location, 'r');
}

}
2 changes: 0 additions & 2 deletions lib/private/AvatarManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,6 @@ public function getAvatar($userId) {
throw new \Exception('user does not exist');
}

$userId = $user->getUID();

$avatarsFolder = $this->getAvatarFolder($user);
return new Avatar($avatarsFolder, $this->l, $user, $this->logger);
}
Expand Down
Loading