*/ class LoadPublicFileRequestAuthListener implements IEventListener { public function __construct( private IManager $shareManager, ) { } public function handle(Event $event): void { if (!$event instanceof BeforeTemplateRenderedEvent) { return; } // Make sure we are on a public page rendering if ($event->getResponse()->getRenderAs() !== TemplateResponse::RENDER_AS_PUBLIC) { return; } $token = $event->getResponse()->getParams()['sharingToken'] ?? null; if ($token === null || $token === '') { return; } // Check if the share is a file request $isFileRequest = false; try { $share = $this->shareManager->getShareByToken($token); $attributes = $share->getAttributes(); if ($attributes === null) { return; } $isFileRequest = $attributes->getAttribute('fileRequest', 'enabled') === true; } catch (\Exception $e) { // Ignore, this is not a file request or the share does not exist } if ($isFileRequest) { // Add the script to the public page Util::addScript(Application::APP_ID, 'public-file-request'); } } }