summaryrefslogtreecommitdiffstats
path: root/apps/dav/lib/Controller
diff options
context:
space:
mode:
authorMorris Jobke <hey@morrisjobke.de>2020-10-06 22:12:22 +0200
committerGitHub <noreply@github.com>2020-10-06 22:12:22 +0200
commitca5e8d2093e48ba7f331e4628981ecc1c0bc2a68 (patch)
treef98c78cd48730f8825aec39788447f4fda2d2df1 /apps/dav/lib/Controller
parentc1fd22b025fc3b75e3ad39ef1cab66e9f19b2764 (diff)
parent0e5d69286678d398b128a0c1bf3c5bea69678691 (diff)
downloadnextcloud-server-ca5e8d2093e48ba7f331e4628981ecc1c0bc2a68.tar.gz
nextcloud-server-ca5e8d2093e48ba7f331e4628981ecc1c0bc2a68.zip
Merge pull request #23025 from Iscle/master
DirectController: Let users choose the link expiration time
Diffstat (limited to 'apps/dav/lib/Controller')
-rw-r--r--apps/dav/lib/Controller/DirectController.php8
1 files changed, 6 insertions, 2 deletions
diff --git a/apps/dav/lib/Controller/DirectController.php b/apps/dav/lib/Controller/DirectController.php
index 4db71df7627..35f4c0dbcb5 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);
@@ -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');
@@ -102,7 +106,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);