diff --git a/Classes/Controller/BackendController.php b/Classes/Controller/BackendController.php index db70eb2..ef37e20 100644 --- a/Classes/Controller/BackendController.php +++ b/Classes/Controller/BackendController.php @@ -2,18 +2,21 @@ namespace WEBprofil\WpMailqueue\Controller; -use Bitmotion\SecureDownloads\Factory\SecureLinkFactory; -use Bitmotion\SecureDownloads\Service\SecureDownloadService; +use Deployer\Host\Storage; use Psr\Http\Message\ServerRequestInterface; use TYPO3\CMS\Backend\Routing\UriBuilder; use TYPO3\CMS\Backend\View\BackendTemplateView; use TYPO3\CMS\Core\Database\ConnectionPool; +use TYPO3\CMS\Core\Exception; use TYPO3\CMS\Core\Http\JsonResponse; use TYPO3\CMS\Core\Http\RedirectResponse; use TYPO3\CMS\Core\Http\Response; use TYPO3\CMS\Core\Imaging\Icon; use TYPO3\CMS\Core\Imaging\IconFactory; use TYPO3\CMS\Core\Page\PageRenderer; +use TYPO3\CMS\Core\Resource\ResourceFactory; +use TYPO3\CMS\Core\Resource\ResourceStorage; +use TYPO3\CMS\Core\Resource\StorageRepository; use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3\CMS\Extbase\Mvc\Controller\ActionController; @@ -72,27 +75,46 @@ public function getMailsAsJson(ServerRequestInterface $request): Response $url = $uriBuilder->buildUriFromRoutePath('/delete', ['uid' => $mail['uid']]); $jsonMail['actions'] = '' . $iconMarkup . ''; - $securedAttachements = []; - $secureDownloadService = GeneralUtility::makeInstance(SecureDownloadService::class); + $storageRepository = GeneralUtility::makeInstance(StorageRepository::class); + $storages = $storageRepository->findAll(); + + $mailAttachements = []; $attachements = explode(',', $jsonMail['attachements']); foreach ($attachements as $attachement) { - if ($secureDownloadService->pathShouldBeSecured($attachement)) { - $securedUrl = GeneralUtility::makeInstance(SecureLinkFactory::class, $attachement); - $securedAttachements[] = [ - 'name' => $attachement, - 'url' => $securedUrl->getUrl(), - ]; - } else { - $securedAttachements[] = [ - 'name' => $attachement, - 'url' => $attachement - ]; + $fileName = $attachement; + $resourceFactory = GeneralUtility::makeInstance(ResourceFactory::class); + + // cleanup filepaths to find file object + /** @var ResourceStorage $storage */ + foreach ($storages as $storage) { + $storageRecord = $storage->getStorageRecord(); + $configuration = $storage->getConfiguration(); + $fileName = str_replace($configuration['basePath'], $storageRecord['uid'].':', $fileName); } + + // search file object + $file = null; + try { + $file = $resourceFactory->getFileObjectFromCombinedIdentifier($fileName); + } catch (\InvalidArgumentException $e) { } + + $fileData = [ + 'name' => $attachement + ]; + + if ($file) { + $fileData['url'] = $file->getPublicUrl(); + } + $mailAttachements[] = $fileData; } $attachementsHtml = []; - foreach ($securedAttachements as $attachement) { - $attachementsHtml[] = '' . $attachement['name'] . ''; + foreach ($mailAttachements as $attachement) { + if ($attachement['url']) { + $attachementsHtml[] = '' . $attachement['name'] . ''; + } else { + $attachementsHtml[] = '' . $attachement['name'] . ''; + } } $jsonMail['attachements'] = implode(', ', $attachementsHtml); @@ -163,3 +185,4 @@ protected function getQueryBuilder() ->getQueryBuilderForTable(self::$table); } } + diff --git a/composer.json b/composer.json index 5026c13..13eb29c 100644 --- a/composer.json +++ b/composer.json @@ -9,8 +9,7 @@ } ], "require": { - "typo3/cms-core": "^10.4", - "leuchtfeuer/secure-downloads": "^4" + "typo3/cms-core": "^10.4" }, "autoload": { "psr-4": { diff --git a/ext_emconf.php b/ext_emconf.php index 82a0a77..a89fbd1 100644 --- a/ext_emconf.php +++ b/ext_emconf.php @@ -21,8 +21,7 @@ 'version' => '1.0.0', 'constraints' => [ 'depends' => [ - 'typo3' => '10.4.0-10.4.99', - 'secure_downloads' => '4.1.1' + 'typo3' => '10.4.0-10.4.99' ], 'conflicts' => [], 'suggests' => [],