summaryrefslogtreecommitdiffstats
path: root/apps/dav
diff options
context:
space:
mode:
authorRoeland Jago Douma <roeland@famdouma.nl>2018-04-13 17:11:25 +0200
committerRoeland Jago Douma <roeland@famdouma.nl>2018-04-26 10:35:37 +0200
commitb3e7865d9b3a88647107220fd9ac08f0d80ae1cd (patch)
treec981b013e63d97977e8654c659a60ffc233ba979 /apps/dav
parent5c6d3b4f41d420e2ea84ba71c8173dcf931a77c6 (diff)
downloadnextcloud-server-b3e7865d9b3a88647107220fd9ac08f0d80ae1cd.tar.gz
nextcloud-server-b3e7865d9b3a88647107220fd9ac08f0d80ae1cd.zip
Dav endpoint returns proper data
Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
Diffstat (limited to 'apps/dav')
-rw-r--r--apps/dav/appinfo/v2/direct.php7
-rw-r--r--apps/dav/lib/Db/DirectMapper.php21
-rw-r--r--apps/dav/lib/Direct/DirectFile.php51
-rw-r--r--apps/dav/lib/Direct/DirectHome.php18
-rw-r--r--apps/dav/lib/Direct/ServerFactory.php8
5 files changed, 90 insertions, 15 deletions
diff --git a/apps/dav/appinfo/v2/direct.php b/apps/dav/appinfo/v2/direct.php
index 4ee22398c7e..633d69a3c3d 100644
--- a/apps/dav/appinfo/v2/direct.php
+++ b/apps/dav/appinfo/v2/direct.php
@@ -34,6 +34,11 @@ ignore_user_abort(true);
$requestUri = \OC::$server->getRequest()->getRequestUri();
$serverFactory = new \OCA\DAV\Direct\ServerFactory(\OC::$server->getConfig());
-$server = $serverFactory->createServer($baseuri, $requestUri);
+$server = $serverFactory->createServer(
+ $baseuri,
+ $requestUri,
+ \OC::$server->getRootFolder(),
+ \OC::$server->query(\OCA\DAV\Db\DirectMapper::class)
+);
$server->exec();
diff --git a/apps/dav/lib/Db/DirectMapper.php b/apps/dav/lib/Db/DirectMapper.php
index 917fca2f920..806b145823e 100644
--- a/apps/dav/lib/Db/DirectMapper.php
+++ b/apps/dav/lib/Db/DirectMapper.php
@@ -24,6 +24,7 @@ declare(strict_types=1);
namespace OCA\DAV\Db;
+use OCP\AppFramework\Db\DoesNotExistException;
use OCP\AppFramework\Db\Mapper;
use OCP\IDBConnection;
@@ -32,4 +33,24 @@ class DirectMapper extends Mapper {
public function __construct(IDBConnection $db) {
parent::__construct($db, 'directlink', Direct::class);
}
+
+ public function getByToken(string $token): Direct {
+ $qb = $this->db->getQueryBuilder();
+
+ $qb->select('*')
+ ->from('directlink')
+ ->where(
+ $qb->expr()->eq('token', $qb->createNamedParameter($token))
+ );
+
+ $cursor = $qb->execute();
+ $data = $cursor->fetch();
+ $cursor->closeCursor();
+
+ if ($data === false) {
+ throw new DoesNotExistException();
+ }
+
+ return Direct::fromRow($data);
+ }
}
diff --git a/apps/dav/lib/Direct/DirectFile.php b/apps/dav/lib/Direct/DirectFile.php
index d3ee2abe3b0..d327a1752bb 100644
--- a/apps/dav/lib/Direct/DirectFile.php
+++ b/apps/dav/lib/Direct/DirectFile.php
@@ -24,16 +24,26 @@ declare(strict_types=1);
namespace OCA\DAV\Direct;
+use OCA\DAV\Db\Direct;
use OCP\Files\File;
+use OCP\Files\IRootFolder;
use Sabre\DAV\Exception\Forbidden;
+use Sabre\DAV\Exception\NotFound;
use Sabre\DAV\IFile;
class DirectFile implements IFile {
+ /** @var Direct */
+ private $direct;
+
+ /** @var IRootFolder */
+ private $rootFolder;
+
/** @var File */
private $file;
- public function __construct(File $file) {
- $this->file = $file;
+ public function __construct(Direct $direct, IRootFolder $rootFolder) {
+ $this->direct = $direct;
+ $this->rootFolder = $rootFolder;
}
function put($data) {
@@ -41,30 +51,35 @@ class DirectFile implements IFile {
}
function get() {
- // TODO: Implement get() method.
+ $this->getFile();
+
+ return $this->file->fopen('rb');
}
function getContentType() {
- // TODO: Implement getContentType() method.
+ $this->getFile();
+
+ return $this->file->getMimeType();
}
function getETag() {
+ $this->getFile();
+
return $this->file->getEtag();
- // TODO: Implement getETag() method.
}
function getSize() {
+ $this->getFile();
+
return $this->file->getSize();
- // TODO: Implement getSize() method.
}
function delete() {
throw new Forbidden();
- // TODO: Implement delete() method.
}
function getName() {
- return $this->file->getName();
+ return $this->direct->getToken();
}
function setName($name) {
@@ -72,8 +87,26 @@ class DirectFile implements IFile {
}
function getLastModified() {
+ $this->getFile();
+
return $this->file->getMTime();
- // TODO: Implement getLastModified() method.
+ }
+
+ private function getFile() {
+ if ($this->file === null) {
+ $userFolder = $this->rootFolder->getUserFolder($this->direct->getUserId());
+ $files = $userFolder->getById($this->direct->getFileId());
+
+ //TODO check expiration
+
+ if ($files === []) {
+ throw new NotFound();
+ }
+
+ $this->file = array_shift($files);
+ }
+
+ return $this->file;
}
}
diff --git a/apps/dav/lib/Direct/DirectHome.php b/apps/dav/lib/Direct/DirectHome.php
index 05c72aa0057..3440a55dc18 100644
--- a/apps/dav/lib/Direct/DirectHome.php
+++ b/apps/dav/lib/Direct/DirectHome.php
@@ -24,6 +24,8 @@ declare(strict_types=1);
namespace OCA\DAV\Direct;
+use OCA\DAV\Db\DirectMapper;
+use OCP\AppFramework\Db\DoesNotExistException;
use OCP\Files\File;
use OCP\Files\IRootFolder;
use Sabre\DAV\Exception\Forbidden;
@@ -35,8 +37,12 @@ class DirectHome implements ICollection {
/** @var IRootFolder */
private $rootFolder;
- public function __construct(IRootFolder $rootFolder) {
+ /** @var DirectMapper */
+ private $mapper;
+
+ public function __construct(IRootFolder $rootFolder, DirectMapper $mapper) {
$this->rootFolder = $rootFolder;
+ $this->mapper = $mapper;
}
function createFile($name, $data = null) {
@@ -47,8 +53,14 @@ class DirectHome implements ICollection {
throw new Forbidden();
}
- function getChild($name) {
- throw new NotFound();
+ public function getChild($name) {
+ try {
+ $direct = $this->mapper->getByToken($name);
+
+ return new DirectFile($direct, $this->rootFolder);
+ } catch (DoesNotExistException $e) {
+ throw new NotFound();
+ }
}
function getChildren() {
diff --git a/apps/dav/lib/Direct/ServerFactory.php b/apps/dav/lib/Direct/ServerFactory.php
index 85c1555021d..9869e69710a 100644
--- a/apps/dav/lib/Direct/ServerFactory.php
+++ b/apps/dav/lib/Direct/ServerFactory.php
@@ -24,6 +24,8 @@ declare(strict_types=1);
namespace OCA\DAV\Direct;
+use OCA\DAV\Db\DirectMapper;
+use OCP\Files\IRootFolder;
use OCP\IConfig;
class ServerFactory {
@@ -35,8 +37,10 @@ class ServerFactory {
}
public function createServer(string $baseURI,
- string $requestURI) {
- $home = new DirectHome(\OC::$server->getRootFolder());
+ string $requestURI,
+ IRootFolder $rootFolder,
+ DirectMapper $mapper) {
+ $home = new DirectHome($rootFolder, $mapper);
$server = new Server($home);
$server->httpRequest->setUrl($requestURI);