@@ -41,79 +41,79 @@ |
||
| 41 | 41 | |
| 42 | 42 | class DirectController extends OCSController { |
| 43 | 43 | |
| 44 | - /** @var IRootFolder */ |
|
| 45 | - private $rootFolder; |
|
| 44 | + /** @var IRootFolder */ |
|
| 45 | + private $rootFolder; |
|
| 46 | 46 | |
| 47 | - /** @var string */ |
|
| 48 | - private $userId; |
|
| 47 | + /** @var string */ |
|
| 48 | + private $userId; |
|
| 49 | 49 | |
| 50 | - /** @var DirectMapper */ |
|
| 51 | - private $mapper; |
|
| 50 | + /** @var DirectMapper */ |
|
| 51 | + private $mapper; |
|
| 52 | 52 | |
| 53 | - /** @var ISecureRandom */ |
|
| 54 | - private $random; |
|
| 53 | + /** @var ISecureRandom */ |
|
| 54 | + private $random; |
|
| 55 | 55 | |
| 56 | - /** @var ITimeFactory */ |
|
| 57 | - private $timeFactory; |
|
| 56 | + /** @var ITimeFactory */ |
|
| 57 | + private $timeFactory; |
|
| 58 | 58 | |
| 59 | - /** @var IURLGenerator */ |
|
| 60 | - private $urlGenerator; |
|
| 59 | + /** @var IURLGenerator */ |
|
| 60 | + private $urlGenerator; |
|
| 61 | 61 | |
| 62 | 62 | |
| 63 | - public function __construct(string $appName, |
|
| 64 | - IRequest $request, |
|
| 65 | - IRootFolder $rootFolder, |
|
| 66 | - string $userId, |
|
| 67 | - DirectMapper $mapper, |
|
| 68 | - ISecureRandom $random, |
|
| 69 | - ITimeFactory $timeFactory, |
|
| 70 | - IURLGenerator $urlGenerator) { |
|
| 71 | - parent::__construct($appName, $request); |
|
| 63 | + public function __construct(string $appName, |
|
| 64 | + IRequest $request, |
|
| 65 | + IRootFolder $rootFolder, |
|
| 66 | + string $userId, |
|
| 67 | + DirectMapper $mapper, |
|
| 68 | + ISecureRandom $random, |
|
| 69 | + ITimeFactory $timeFactory, |
|
| 70 | + IURLGenerator $urlGenerator) { |
|
| 71 | + parent::__construct($appName, $request); |
|
| 72 | 72 | |
| 73 | - $this->rootFolder = $rootFolder; |
|
| 74 | - $this->userId = $userId; |
|
| 75 | - $this->mapper = $mapper; |
|
| 76 | - $this->random = $random; |
|
| 77 | - $this->timeFactory = $timeFactory; |
|
| 78 | - $this->urlGenerator = $urlGenerator; |
|
| 79 | - } |
|
| 73 | + $this->rootFolder = $rootFolder; |
|
| 74 | + $this->userId = $userId; |
|
| 75 | + $this->mapper = $mapper; |
|
| 76 | + $this->random = $random; |
|
| 77 | + $this->timeFactory = $timeFactory; |
|
| 78 | + $this->urlGenerator = $urlGenerator; |
|
| 79 | + } |
|
| 80 | 80 | |
| 81 | - /** |
|
| 82 | - * @NoAdminRequired |
|
| 83 | - */ |
|
| 84 | - public function getUrl(int $fileId, int $expirationTime = 60 * 60 * 8): DataResponse { |
|
| 85 | - $userFolder = $this->rootFolder->getUserFolder($this->userId); |
|
| 81 | + /** |
|
| 82 | + * @NoAdminRequired |
|
| 83 | + */ |
|
| 84 | + public function getUrl(int $fileId, int $expirationTime = 60 * 60 * 8): DataResponse { |
|
| 85 | + $userFolder = $this->rootFolder->getUserFolder($this->userId); |
|
| 86 | 86 | |
| 87 | - $files = $userFolder->getById($fileId); |
|
| 87 | + $files = $userFolder->getById($fileId); |
|
| 88 | 88 | |
| 89 | - if ($files === []) { |
|
| 90 | - throw new OCSNotFoundException(); |
|
| 91 | - } |
|
| 89 | + if ($files === []) { |
|
| 90 | + throw new OCSNotFoundException(); |
|
| 91 | + } |
|
| 92 | 92 | |
| 93 | - if ($expirationTime <= 0 || $expirationTime > (60 * 60 * 24)) { |
|
| 94 | - throw new OCSBadRequestException('Expiration time should be greater than 0 and less than or equal to ' . (60 * 60 * 24)); |
|
| 95 | - } |
|
| 93 | + if ($expirationTime <= 0 || $expirationTime > (60 * 60 * 24)) { |
|
| 94 | + throw new OCSBadRequestException('Expiration time should be greater than 0 and less than or equal to ' . (60 * 60 * 24)); |
|
| 95 | + } |
|
| 96 | 96 | |
| 97 | - $file = array_shift($files); |
|
| 98 | - if (!($file instanceof File)) { |
|
| 99 | - throw new OCSBadRequestException('Direct download only works for files'); |
|
| 100 | - } |
|
| 97 | + $file = array_shift($files); |
|
| 98 | + if (!($file instanceof File)) { |
|
| 99 | + throw new OCSBadRequestException('Direct download only works for files'); |
|
| 100 | + } |
|
| 101 | 101 | |
| 102 | - //TODO: at some point we should use the directdownlaod function of storages |
|
| 103 | - $direct = new Direct(); |
|
| 104 | - $direct->setUserId($this->userId); |
|
| 105 | - $direct->setFileId($fileId); |
|
| 102 | + //TODO: at some point we should use the directdownlaod function of storages |
|
| 103 | + $direct = new Direct(); |
|
| 104 | + $direct->setUserId($this->userId); |
|
| 105 | + $direct->setFileId($fileId); |
|
| 106 | 106 | |
| 107 | - $token = $this->random->generate(60, ISecureRandom::CHAR_UPPER . ISecureRandom::CHAR_LOWER . ISecureRandom::CHAR_DIGITS); |
|
| 108 | - $direct->setToken($token); |
|
| 109 | - $direct->setExpiration($this->timeFactory->getTime() + $expirationTime); |
|
| 107 | + $token = $this->random->generate(60, ISecureRandom::CHAR_UPPER . ISecureRandom::CHAR_LOWER . ISecureRandom::CHAR_DIGITS); |
|
| 108 | + $direct->setToken($token); |
|
| 109 | + $direct->setExpiration($this->timeFactory->getTime() + $expirationTime); |
|
| 110 | 110 | |
| 111 | - $this->mapper->insert($direct); |
|
| 111 | + $this->mapper->insert($direct); |
|
| 112 | 112 | |
| 113 | - $url = $this->urlGenerator->getAbsoluteURL('remote.php/direct/'.$token); |
|
| 113 | + $url = $this->urlGenerator->getAbsoluteURL('remote.php/direct/'.$token); |
|
| 114 | 114 | |
| 115 | - return new DataResponse([ |
|
| 116 | - 'url' => $url, |
|
| 117 | - ]); |
|
| 118 | - } |
|
| 115 | + return new DataResponse([ |
|
| 116 | + 'url' => $url, |
|
| 117 | + ]); |
|
| 118 | + } |
|
| 119 | 119 | } |
@@ -91,7 +91,7 @@ discard block |
||
| 91 | 91 | } |
| 92 | 92 | |
| 93 | 93 | if ($expirationTime <= 0 || $expirationTime > (60 * 60 * 24)) { |
| 94 | - throw new OCSBadRequestException('Expiration time should be greater than 0 and less than or equal to ' . (60 * 60 * 24)); |
|
| 94 | + throw new OCSBadRequestException('Expiration time should be greater than 0 and less than or equal to '.(60 * 60 * 24)); |
|
| 95 | 95 | } |
| 96 | 96 | |
| 97 | 97 | $file = array_shift($files); |
@@ -104,7 +104,7 @@ discard block |
||
| 104 | 104 | $direct->setUserId($this->userId); |
| 105 | 105 | $direct->setFileId($fileId); |
| 106 | 106 | |
| 107 | - $token = $this->random->generate(60, ISecureRandom::CHAR_UPPER . ISecureRandom::CHAR_LOWER . ISecureRandom::CHAR_DIGITS); |
|
| 107 | + $token = $this->random->generate(60, ISecureRandom::CHAR_UPPER.ISecureRandom::CHAR_LOWER.ISecureRandom::CHAR_DIGITS); |
|
| 108 | 108 | $direct->setToken($token); |
| 109 | 109 | $direct->setExpiration($this->timeFactory->getTime() + $expirationTime); |
| 110 | 110 | |