summaryrefslogtreecommitdiffstats
path: root/apps/dav/lib/Controller
diff options
context:
space:
mode:
authorRoeland Jago Douma <roeland@famdouma.nl>2018-04-13 16:54:24 +0200
committerRoeland Jago Douma <roeland@famdouma.nl>2018-04-26 10:35:37 +0200
commit5c6d3b4f41d420e2ea84ba71c8173dcf931a77c6 (patch)
tree5cfba81bd64351eedbdc4fe1bea36a6a15598351 /apps/dav/lib/Controller
parentf984664bee136075556963af56999e0315cbb4bb (diff)
downloadnextcloud-server-5c6d3b4f41d420e2ea84ba71c8173dcf931a77c6.tar.gz
nextcloud-server-5c6d3b4f41d420e2ea84ba71c8173dcf931a77c6.zip
Request a direct link
Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
Diffstat (limited to 'apps/dav/lib/Controller')
-rw-r--r--apps/dav/lib/Controller/DirectController.php56
1 files changed, 52 insertions, 4 deletions
diff --git a/apps/dav/lib/Controller/DirectController.php b/apps/dav/lib/Controller/DirectController.php
index 28fdf885758..c357771f3ff 100644
--- a/apps/dav/lib/Controller/DirectController.php
+++ b/apps/dav/lib/Controller/DirectController.php
@@ -24,12 +24,16 @@ declare(strict_types=1);
namespace OCA\DAV\Controller;
+use OCA\DAV\Db\Direct;
use OCA\DAV\Db\DirectMapper;
+use OCP\AppFramework\Http\DataResponse;
+use OCP\AppFramework\OCS\OCSNotFoundException;
use OCP\AppFramework\OCSController;
+use OCP\AppFramework\Utility\ITimeFactory;
use OCP\Files\IRootFolder;
-use OCP\IDBConnection;
use OCP\IRequest;
-use OCP\IUserManager;
+use OCP\IURLGenerator;
+use OCP\Security\ISecureRandom;
class DirectController extends OCSController {
@@ -42,20 +46,64 @@ class DirectController extends OCSController {
/** @var DirectMapper */
private $mapper;
+ /** @var ISecureRandom */
+ private $random;
+
+ /** @var ITimeFactory */
+ private $timeFactory;
+
+ /** @var IURLGenerator */
+ private $urlGenerator;
+
public function __construct(string $appName,
IRequest $request,
IRootFolder $rootFolder,
string $userId,
- DirectMapper $mapper) {
+ DirectMapper $mapper,
+ ISecureRandom $random,
+ ITimeFactory $timeFactory,
+ IURLGenerator $urlGenerator) {
parent::__construct($appName, $request);
$this->rootFolder = $rootFolder;
$this->userId = $userId;
$this->mapper = $mapper;
+ $this->random = $random;
+ $this->timeFactory = $timeFactory;
+ $this->urlGenerator = $urlGenerator;
}
- public function getUrl(int $fileId) {
+ /**
+ * @NoAdminRequired
+ */
+ public function getUrl(int $fileId): DataResponse {
+ $userFolder = $this->rootFolder->getUserFolder($this->userId);
+
+ $files = $userFolder->getById($fileId);
+
+ if ($files === []) {
+ throw new OCSNotFoundException();
+ }
+
+ $file = array_shift($files);
+
+ //TODO: try to get a url from the backend (like S3)
+
+
+ // Fallback to our default implemenation
+ $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);
+
+ $this->mapper->insert($direct);
+ return new DataResponse([
+ 'url' => $this->urlGenerator->getAbsoluteURL('remote.php/direct/'.$token)
+ ]);
}
}