diff --git a/CHANGELOG.md b/CHANGELOG.md index 5621d37..29d54f1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,14 +1,18 @@ # Craft AWS Plugin Changelog -## Unreleased +## 1.0.0-beta.2 - 2020-03-01 + ### Added - Console command to generate thumbs without job/queues - Config option for queue name for all mass updates (e.g. thumbs generating) + ### Fixed - If resourceRevision was a clousure, an error occured - Fix AssetManager by adding S3 functions as trait - Fix cached path of thumbnails +- Fix SVG mime type for older Craft CMS versions ## 1.0.0-beta.1 - 2019-04-06 + ### Added - Initial release diff --git a/src/components/S3AssetManager.php b/src/components/S3AssetManager.php index fbf0186..005ffb4 100644 --- a/src/components/S3AssetManager.php +++ b/src/components/S3AssetManager.php @@ -121,7 +121,7 @@ protected function hash($path) public function getPublishedUrl($sourcePath, bool $publish = false, $filePath = null) { if ($publish === true) { - list(, $url) = $this->publish($sourcePath); + [, $url] = $this->publish($sourcePath); } else { $url = parent::getPublishedUrl($sourcePath); } @@ -177,7 +177,7 @@ protected function publishFile($src): array $dstFile = $dstDir . '/' . $fileName; if (!$this->isPublished($dstFile)) { - $this->uploadFile($this->bucket, $dstFile, $src, FileHelper::getMimeType($src)); + $this->uploadFile($this->bucket, $dstFile, $src, $this->_getMimetype($src)); } return [$dstFile, $this->baseUrl . "/$dir/$fileName"]; @@ -224,7 +224,7 @@ protected function uploadDirectory($src, $dst, $options) } if (is_file($from)) { - $this->uploadFile($this->bucket, $to, $from, FileHelper::getMimeType($from)); + $this->uploadFile($this->bucket, $to, $from, $this->_getMimetype($from)); } else if (!isset($options['recursive']) || $options['recursive']) { $this->uploadDirectory($from, $to, $options); } @@ -234,4 +234,24 @@ protected function uploadDirectory($src, $dst, $options) } closedir($handle); } + + /** + * Get mime type and fix bugs. + * + * @param string $src The file path. + * + * @return string The mime type. + * @throws InvalidConfigException + */ + private function _getMimetype($src) + { + $mimeType = FileHelper::getMimeType($src); + + // Handle invalid SVG mime type reported by PHP (https://bugs.php.net/bug.php?id=79045) + if ($mimeType === 'image/svg') { + $mimeType = 'image/svg+xml'; + } + + return (string)$mimeType; + } }