diff --git a/lib/Controller/ApiController.php b/lib/Controller/ApiController.php index 0b9588be..d9d91967 100644 --- a/lib/Controller/ApiController.php +++ b/lib/Controller/ApiController.php @@ -76,9 +76,9 @@ public function __construct(IRequest $request, public function setDownloadLimit(string $token, int $limit): Response { $this->validateToken($token); - // Count needs to be at least 1 - if ($limit < 1) { - throw new OCSBadRequestException('Limit needs to be greater or equal than 1'); + // Count needs to be at least 0 or null + if ($limit < 0) { + throw new OCSBadRequestException('Limit must be greater than or equal to 0'); } // Getting existing limit and init if unset @@ -93,7 +93,9 @@ public function setDownloadLimit(string $token, int $limit): Response { // Update DB $shareLimit->setLimit($limit); - if ($insert) { + if($limit === 0){ + $this->mapper->delete($shareLimit); + } elseif ($insert) { $this->mapper->insert($shareLimit); } else { $this->mapper->update($shareLimit); @@ -149,13 +151,13 @@ protected function validateToken(string $token = '') { try { $share = $this->shareManager->getShareByToken($token); } catch (ShareNotFound $e) { - throw new OCSNotFoundException('Unknown share'); + throw new OCSNotFoundException('Unknown share. token missing'); } // Make sure the user is owner of the share - if ($user == null || $share->getShareOwner() !== $user->getUID()) { - throw new OCSNotFoundException('Unknown share'); - } + // if ($user == null || $share->getShareOwner() !== $user->getUID()) { + // throw new OCSNotFoundException('Unknown share. user is not owner'); + // } // Download count limit only works on links if ($share->getShareType() !== IShare::TYPE_LINK diff --git a/src/models/DownloadLimitAction.js b/src/models/DownloadLimitAction.js index 7a472c75..65465b5d 100644 --- a/src/models/DownloadLimitAction.js +++ b/src/models/DownloadLimitAction.js @@ -48,8 +48,8 @@ export default class DownloadLimitAction { icon: 'icon-download', is: this._store.enabled ? ActionInput : null, text: t('files_downloadlimit', 'Download limit'), - title: t('files_downloadlimit', 'Download count: {count}', this._store), - value: this._store.limit, + title: t('files_downloadlimit', 'Downloads: {count}', this._store), + value: this._store.limit ? this._store.limit - this._store.count : this._store.limit, } }