summaryrefslogtreecommitdiffstats
path: root/apps/dav/lib/Controller/DirectController.php
diff options
context:
space:
mode:
Diffstat (limited to 'apps/dav/lib/Controller/DirectController.php')
-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,