aboutsummaryrefslogtreecommitdiffstats
path: root/apps/dav/lib/Controller
diff options
context:
space:
mode:
authorRoeland Jago Douma <roeland@famdouma.nl>2018-04-26 10:34:57 +0200
committerRoeland Jago Douma <roeland@famdouma.nl>2018-04-26 10:35:38 +0200
commit1c75ddac45845d9e91997e6253e36b9ae2556e91 (patch)
treecf53ee190d3c4ac3e1981aaa4aa0af35b05c3653 /apps/dav/lib/Controller
parentd5222d68f0180cb7072c28975fea95ac2a445e3d (diff)
downloadnextcloud-server-1c75ddac45845d9e91997e6253e36b9ae2556e91.tar.gz
nextcloud-server-1c75ddac45845d9e91997e6253e36b9ae2556e91.zip
Improve the directContoller
* Tests * No directdownload from storage yet (as it is not tested at all) * No direct links for folders Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
Diffstat (limited to 'apps/dav/lib/Controller')
-rw-r--r--apps/dav/lib/Controller/DirectController.php29
1 files changed, 14 insertions, 15 deletions
diff --git a/apps/dav/lib/Controller/DirectController.php b/apps/dav/lib/Controller/DirectController.php
index 3b8b0d1e2a6..2a14e4db2c7 100644
--- a/apps/dav/lib/Controller/DirectController.php
+++ b/apps/dav/lib/Controller/DirectController.php
@@ -27,9 +27,11 @@ namespace OCA\DAV\Controller;
use OCA\DAV\Db\Direct;
use OCA\DAV\Db\DirectMapper;
use OCP\AppFramework\Http\DataResponse;
+use OCP\AppFramework\OCS\OCSBadRequestException;
use OCP\AppFramework\OCS\OCSNotFoundException;
use OCP\AppFramework\OCSController;
use OCP\AppFramework\Utility\ITimeFactory;
+use OCP\Files\File;
use OCP\Files\IRootFolder;
use OCP\IRequest;
use OCP\IURLGenerator;
@@ -87,25 +89,22 @@ class DirectController extends OCSController {
}
$file = array_shift($files);
- $storage = $file->getStorage();
- $directDownload = $storage->getDirectDownload($file->getInternalPath());
+ if (!($file instanceof File)) {
+ throw new OCSBadRequestException('Direct download only works for files');
+ }
- if (isset($directDownload['url'])) {
- $url = $directDownload['url'];
- } else {
- // Fallback to our default implemenation
- $direct = new Direct();
- $direct->setUserId($this->userId);
- $direct->setFileId($fileId);
+ //TODO: at some point we should use the directdownlaod function of storages
+ $direct = new Direct();
+ $direct->setUserId($this->userId);
+ $direct->setFileId($fileId);
- $token = $this->random->generate(60, ISecureRandom::CHAR_UPPER . ISecureRandom::CHAR_LOWER . ISecureRandom::CHAR_DIGITS);
- $direct->setToken($token);
- $direct->setExpiration($this->timeFactory->getTime() + 60 * 60 * 8);
+ $token = $this->random->generate(60, ISecureRandom::CHAR_UPPER . ISecureRandom::CHAR_LOWER . ISecureRandom::CHAR_DIGITS);
+ $direct->setToken($token);
+ $direct->setExpiration($this->timeFactory->getTime() + 60 * 60 * 8);
- $this->mapper->insert($direct);
+ $this->mapper->insert($direct);
- $url = $this->urlGenerator->getAbsoluteURL('remote.php/direct/'.$token);
- }
+ $url = $this->urlGenerator->getAbsoluteURL('remote.php/direct/'.$token);
return new DataResponse([
'url' => $url,