diff --git a/src/FileJet.php b/src/FileJet.php index cccb25f..9781fb5 100644 --- a/src/FileJet.php +++ b/src/FileJet.php @@ -25,10 +25,14 @@ public function getUrl(FileInterface $file): string { $url = "{$this->config->getPublicUrl()}/{$this->config->getStorageId()}/{$this->normalizeId($file->getIdentifier())}"; - if ($this->config->isAutoMode() && $this->autoIsDisabled($file)) { + if ($this->config->isAutoMode() && $this->autoIsEnabled($file)) { $file = new File($file->getIdentifier(), $this->toAutoMutation($file)); } + if ($this->config->isAutoMode() && false === $this->autoIsEnabled($file)) { + $file = new File($file->getIdentifier(), $this->removeAutoMutation($file)); + } + if ($file->getMutation() !== null) { $url = "{$url}/{$file->getMutation()}"; } @@ -77,7 +81,7 @@ private function normalizeId(string $fileId): string return preg_replace('/[^a-z0-9]/', 'x', strtolower($fileId)); } - private function autoIsDisabled(FileInterface $file): bool + private function autoIsEnabled(FileInterface $file): bool { return strpos($file->getMutation() ?? '', 'auto=false') === false; } @@ -86,4 +90,9 @@ private function toAutoMutation(FileInterface $file): string { return $file->getMutation() ? "{$file->getMutation()},auto" : 'auto'; } + + private function removeAutoMutation(FileInterface $file): ?string + { + return ($mutation = preg_replace('/,?auto=false/m', '', $file->getMutation())) === '' ? null : $mutation; + } }