From ebd734dc86f8b8e821b2a99539e38516e2876a86 Mon Sep 17 00:00:00 2001 From: Iscle Date: Wed, 23 Sep 2020 23:57:57 +0200 Subject: [PATCH 1/2] DirectController: Let users choose the expiration time Signed-off-by: Iscle --- apps/dav/lib/Controller/DirectController.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/dav/lib/Controller/DirectController.php b/apps/dav/lib/Controller/DirectController.php index 4db71df7627..ff7c96ddef1 100644 --- a/apps/dav/lib/Controller/DirectController.php +++ b/apps/dav/lib/Controller/DirectController.php @@ -81,7 +81,7 @@ class DirectController extends OCSController { /** * @NoAdminRequired */ - public function getUrl(int $fileId): DataResponse { + public function getUrl(int $fileId, int $expirationTime = 60 * 60 * 8): DataResponse { $userFolder = $this->rootFolder->getUserFolder($this->userId); $files = $userFolder->getById($fileId); @@ -102,7 +102,7 @@ class DirectController extends OCSController { $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); + $direct->setExpiration($this->timeFactory->getTime() + $expirationTime); $this->mapper->insert($direct); From 0e5d69286678d398b128a0c1bf3c5bea69678691 Mon Sep 17 00:00:00 2001 From: Iscle Date: Thu, 1 Oct 2020 23:47:13 +0200 Subject: [PATCH 2/2] DirectController: Verify that expirationTime is between 0s and 24h Signed-off-by: Iscle --- apps/dav/lib/Controller/DirectController.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/apps/dav/lib/Controller/DirectController.php b/apps/dav/lib/Controller/DirectController.php index ff7c96ddef1..35f4c0dbcb5 100644 --- a/apps/dav/lib/Controller/DirectController.php +++ b/apps/dav/lib/Controller/DirectController.php @@ -90,6 +90,10 @@ class DirectController extends OCSController { throw new OCSNotFoundException(); } + if ($expirationTime <= 0 || $expirationTime > (60 * 60 * 24)) { + throw new OCSBadRequestException('Expiration time should be greater than 0 and less than or equal to ' . (60 * 60 * 24)); + } + $file = array_shift($files); if (!($file instanceof File)) { throw new OCSBadRequestException('Direct download only works for files');