Merge pull request #23025 from Iscle/master

DirectController: Let users choose the link expiration time
pull/23243/head
Morris Jobke 5 years ago committed by GitHub
commit ca5e8d2093
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 8
      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);

Loading…
Cancel
Save