|
|
|
|
@ -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); |
|
|
|
|
|
|
|
|
|
|