*/ protected $fileIdentifiers = []; public function __construct(private readonly HashService $hashService) {} #[AsEventListener('form-framework/resource-getPublicUrl')] public function getPublicUrl(GeneratePublicUrlForResourceEvent $event): void { $resource = $event->getResource(); if (!$resource instanceof FileInterface || !$this->has($resource) || $event->getStorage()->getDriverType() !== 'Local' ) { return; } $event->setPublicUrl($this->getStreamUrl($event->getResource())); } public function add(FileInterface $resource): void { if ($this->has($resource)) { return; } $this->fileIdentifiers[] = $resource->getIdentifier(); } public function has(FileInterface $resource): bool { return in_array($resource->getIdentifier(), $this->fileIdentifiers, true); } protected function getStreamUrl(ResourceInterface $resource): string { $queryParameterArray = ['eID' => 'dumpFile', 't' => '']; if ($resource instanceof File) { $queryParameterArray['f'] = $resource->getUid(); $queryParameterArray['t'] = 'f'; } elseif ($resource instanceof ProcessedFile) { $queryParameterArray['p'] = $resource->getUid(); $queryParameterArray['t'] = 'p'; } $queryParameterArray['token'] = $this->hashService->hmac(implode('|', $queryParameterArray), 'resourceStorageDumpFile'); $publicUrl = ''; if (($GLOBALS['TYPO3_REQUEST'] ?? null) instanceof ServerRequestInterface) { $publicUrl = GeneralUtility::locationHeaderUrl(PathUtility::getAbsoluteWebPath(Environment::getPublicPath() . '/index.php'), $GLOBALS['TYPO3_REQUEST']); } $publicUrl .= '?' . http_build_query($queryParameterArray, '', '&', PHP_QUERY_RFC3986); return $publicUrl; } }