Skip to content

Commit

Permalink
fix: prevent null token
Browse files Browse the repository at this point in the history
Signed-off-by: skjnldsv <skjnldsv@protonmail.com>
  • Loading branch information
skjnldsv committed Aug 1, 2024
1 parent 4fd2926 commit 80169af
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion lib/Listener/ShareLinkAccessedListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,15 @@
use OCP\EventDispatcher\IEventListener;
use OCP\IConfig;
use OCP\Share\IManager;
use Psr\Log\LoggerInterface;

/** @template-implements IEventListener<ShareLinkAccessedEvent> */
class ShareLinkAccessedListener implements IEventListener {
public function __construct(
private IConfig $config,
private IManager $manager,
private LimitMapper $mapper,
private LoggerInterface $logger
) {
}

Expand All @@ -53,8 +55,12 @@ public function handle(Event $event): void {
return;
}

// Make sure we have a valid limit
$token = $event->getShare()->getToken();
if ($token === null) {
return;
}

// Make sure we have a valid limit
try {
$shareLimit = $this->mapper->get($token);
$limit = $shareLimit->getLimit();
Expand All @@ -76,6 +82,8 @@ public function handle(Event $event): void {
$this->mapper->update($shareLimit);
} catch (DoesNotExistException $e) {
// No limit is set, ignore
} catch (\Exception $e) {
$this->logger->error('Error while handling share link accessed event: ' . $e->getMessage());
}
}
}

0 comments on commit 80169af

Please sign in to comment.