Skip to content

Commit

Permalink
[TASK] remove dependency of EXT:secure_downloads
Browse files Browse the repository at this point in the history
  • Loading branch information
Gernott committed Feb 16, 2022
1 parent 53201af commit 541a59a
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 21 deletions.
57 changes: 40 additions & 17 deletions Classes/Controller/BackendController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -72,27 +75,46 @@ public function getMailsAsJson(ServerRequestInterface $request): Response
$url = $uriBuilder->buildUriFromRoutePath('/delete', ['uid' => $mail['uid']]);
$jsonMail['actions'] = '<a class="js-delete-mail btn btn-default" data-href="' . $url . '" title="Mail löschen">' . $iconMarkup . '</a>';

$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[] = '<a href="/' . $attachement['url'] . '" target="_blank">' . $attachement['name'] . '</a>';
foreach ($mailAttachements as $attachement) {
if ($attachement['url']) {
$attachementsHtml[] = '<a href="/' . $attachement['url'] . '" target="_blank">' . $attachement['name'] . '</a>';
} else {
$attachementsHtml[] = '<span class="bg-danger" title="File is missing in filesystem">' . $attachement['name'] . '</span>';
}
}

$jsonMail['attachements'] = implode(', ', $attachementsHtml);
Expand Down Expand Up @@ -163,3 +185,4 @@ protected function getQueryBuilder()
->getQueryBuilderForTable(self::$table);
}
}

3 changes: 1 addition & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@
}
],
"require": {
"typo3/cms-core": "^10.4",
"leuchtfeuer/secure-downloads": "^4"
"typo3/cms-core": "^10.4"
},
"autoload": {
"psr-4": {
Expand Down
3 changes: 1 addition & 2 deletions ext_emconf.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' => [],
Expand Down

0 comments on commit 541a59a

Please sign in to comment.