From 20a35f2faab5ed28c238328ddc0248f5d282e15a Mon Sep 17 00:00:00 2001 From: Sascha Nowak Date: Wed, 19 Jun 2024 09:24:21 +0200 Subject: [PATCH] fix: allow to disable cdn for file resources --- Classes/EventListener/AddCdnToResource.php | 18 ++++++++++++++++++ ext_conf_template.txt | 2 ++ 2 files changed, 20 insertions(+) create mode 100644 ext_conf_template.txt diff --git a/Classes/EventListener/AddCdnToResource.php b/Classes/EventListener/AddCdnToResource.php index ccc2496..3968b1b 100644 --- a/Classes/EventListener/AddCdnToResource.php +++ b/Classes/EventListener/AddCdnToResource.php @@ -5,6 +5,7 @@ namespace Netlogix\Nxsimplecdn\EventListener; use Netlogix\Nxsimplecdn\Service\BaseUriService; +use TYPO3\CMS\Core\Configuration\ExtensionConfiguration; use TYPO3\CMS\Core\Http\ApplicationType; use TYPO3\CMS\Core\Http\Uri; use TYPO3\CMS\Core\Resource\Driver\DriverInterface; @@ -18,8 +19,25 @@ class AddCdnToResource { + protected $configuration = []; + + public function __construct( + ExtensionConfiguration $extensionConfiguration = null + ) { + $this->configuration = $extensionConfiguration ? $extensionConfiguration->get('nxsimplecdn') : + GeneralUtility::makeInstance(ExtensionConfiguration::class)->get('nxsimplecdn'); + } + public function __invoke(GeneratePublicUrlForResourceEvent $event): void { + if ((bool)$this->configuration['enabled'] === false) { + return; + } + + if ($event->getPublicUrl() !== null) { + return; + } + $driver = $event->getDriver(); $resource = $event->getResource(); if ( diff --git a/ext_conf_template.txt b/ext_conf_template.txt new file mode 100644 index 0000000..0514d85 --- /dev/null +++ b/ext_conf_template.txt @@ -0,0 +1,2 @@ +# cat=nxsimplecdn/; type=boolean; label=active CDN for locala files +enabled=1