Merge pull request #23025 from Iscle/master
DirectController: Let users choose the link expiration time
This commit is contained in:
commit
ca5e8d2093
|
@ -81,7 +81,7 @@ class DirectController extends OCSController {
|
||||||
/**
|
/**
|
||||||
* @NoAdminRequired
|
* @NoAdminRequired
|
||||||
*/
|
*/
|
||||||
public function getUrl(int $fileId): DataResponse {
|
public function getUrl(int $fileId, int $expirationTime = 60 * 60 * 8): DataResponse {
|
||||||
$userFolder = $this->rootFolder->getUserFolder($this->userId);
|
$userFolder = $this->rootFolder->getUserFolder($this->userId);
|
||||||
|
|
||||||
$files = $userFolder->getById($fileId);
|
$files = $userFolder->getById($fileId);
|
||||||
|
@ -90,6 +90,10 @@ class DirectController extends OCSController {
|
||||||
throw new OCSNotFoundException();
|
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);
|
$file = array_shift($files);
|
||||||
if (!($file instanceof File)) {
|
if (!($file instanceof File)) {
|
||||||
throw new OCSBadRequestException('Direct download only works for files');
|
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);
|
$token = $this->random->generate(60, ISecureRandom::CHAR_UPPER . ISecureRandom::CHAR_LOWER . ISecureRandom::CHAR_DIGITS);
|
||||||
$direct->setToken($token);
|
$direct->setToken($token);
|
||||||
$direct->setExpiration($this->timeFactory->getTime() + 60 * 60 * 8);
|
$direct->setExpiration($this->timeFactory->getTime() + $expirationTime);
|
||||||
|
|
||||||
$this->mapper->insert($direct);
|
$this->mapper->insert($direct);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue