-
Notifications
You must be signed in to change notification settings - Fork 1
[TASK] Allow compressing of images with special characters #5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,7 +6,9 @@ | |
| use Aws\S3\S3Client; | ||
|
|
||
| use TYPO3\CMS\Core\Core\Environment; | ||
| use TYPO3\CMS\Core\Resource\Driver\LocalDriver; | ||
| use TYPO3\CMS\Core\Resource\File; | ||
| use TYPO3\CMS\Core\Resource\ResourceFactory; | ||
| use TYPO3\CMS\Core\Utility\ExtensionManagementUtility; | ||
| use TYPO3\CMS\Core\Utility\GeneralUtility; | ||
| use TYPO3\CMS\Core\Resource\Index\Indexer; | ||
|
|
@@ -15,6 +17,8 @@ | |
| use TYPO3\CMS\Core\Messaging\FlashMessage; | ||
| use TYPO3\CMS\Core\Messaging\FlashMessageService; | ||
| use TYPO3\CMS\Extbase\Utility\LocalizationUtility; | ||
| use TYPO3\CMS\Core\Resource\StorageRepository; | ||
| use TYPO3\CMS\Core\Resource\ResourceStorage; | ||
|
|
||
| /** | ||
| * Class CompressImageService | ||
|
|
@@ -98,6 +102,7 @@ public function initCdn() | |
| */ | ||
| public function initializeCompression($file) | ||
| { | ||
| $fileCreated = false; | ||
| $this->initAction(); | ||
|
|
||
| if ($this->isFileInExcludeFolder($file)) { | ||
|
|
@@ -114,9 +119,26 @@ public function initializeCompression($file) | |
| if ($this->checkForAmazonCdn($file)) { | ||
| $fileSize = $this->pushToTinyPngAndStoreToCdn($file); | ||
| } else { | ||
| $publicUrl = PATH_site . $file->getPublicUrl(); | ||
| $publicUrl = PATH_site . urldecode($file->getPublicUrl()); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. s. o. |
||
| $source = \Tinify\fromFile($publicUrl); | ||
| $source->toFile($publicUrl); | ||
|
|
||
| // Sanitize URL in order to check if there are any special characters. | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. mh, sollte das nicht schon vorher passiert sein? ich finde das gehört hier nicht hier, dass der CompressImageService das file umbennt, das müsste anders gehen
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Was schwebt dir da denn vor? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. das kommt ja nur vor, wenn Du das Convert-Command über CLI ausführst, und die Datei, ist noch nicht "richtig" umbenannt, oder? Evtl. kannst Du ein weiteres Command bauen, welches Dateien richtig umbennt? (evtl. auch unabh. von dieser Extension?) |
||
| $localDriver = GeneralUtility::makeInstance(LocalDriver::class); | ||
| $sanitizedFileName = $localDriver->sanitizeFileName($file->getName()); | ||
|
|
||
| // Check if file name should be changed due to new file name. If so replace file. | ||
| if ($file->getName() != $sanitizedFileName) { | ||
| $source->toFile($sanitizedFileName); | ||
| /** @var ResourceStorage $storage */ | ||
| $storage = $file->getStorage(); | ||
| $newFile = $storage->addFile($sanitizedFileName, $file->getParentFolder()); | ||
| $storage->deleteFile($file); | ||
| $file = $newFile; | ||
| $fileCreated = true; | ||
| } else { | ||
| $source->toFile($publicUrl); | ||
| } | ||
|
|
||
| $fileSize = $this->setCompressedForCurrentFile($file); | ||
| } | ||
| if ((int)$fileSize !== 0) { | ||
|
|
@@ -130,7 +152,9 @@ public function initializeCompression($file) | |
| $this->addMessageToFlashMessageQueue('debugMode', [], FlashMessage::INFO); | ||
| } | ||
|
|
||
| $this->updateFileInformation($file); | ||
| if (!$fileCreated) { | ||
| $this->updateFileInformation($file); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hm, ich weiss nicht ob das so cool ist, ich denke mal
$file->getPublicUrl()encoded die url, und dann wird sie hier wieder decoded, gibts da nicht evtl. eine andere Methode, den den Pfad uncodiert zurückgibt?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fand ich auch schön, wenn es da eine gibt. Kennst du eine?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
musst du gucken ...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Jo also der macht das ziemlich früh im core. Ich müsste mir halt stattdessen die URL selbst zusammen bauen aus identifier und storage (hier fileadmin). Was meinst du ist besser?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ja, das ist besser