diff --git a/app/Media.php b/app/Media.php index 8e30109b..84ba10c2 100644 --- a/app/Media.php +++ b/app/Media.php @@ -50,6 +50,7 @@ class Media extends Model public function getMediumurlAttribute() { $basename = $this->getBasename($this->path); + $extension = $this->getExtension($this->path); return config('filesystems.disks.s3.url') . '/' . $basename . '-medium.' . $extension; } @@ -62,6 +63,7 @@ class Media extends Model public function getSmallurlAttribute() { $basename = $this->getBasename($this->path); + $extension = $this->getExtension($this->path); return config('filesystems.disks.s3.url') . '/' . $basename . '-small.' . $extension; } @@ -69,11 +71,20 @@ class Media extends Model public function getBasename($path) { $filenameParts = explode('.', $path); - $extension = array_pop($filenameParts); + // the following achieves this data flow // foo.bar.png => ['foo', 'bar', 'png'] => ['foo', 'bar'] => foo.bar $basename = ltrim(array_reduce($filenameParts, function ($carry, $item) { return $carry . '.' . $item; }, ''), '.'); + + return $basename; + } + + public function getExtension($path); + { + $parts = explode('.', $path); + + return array_pop($parts); } } diff --git a/changelog.md b/changelog.md index 4f2825d9..ac9d1b01 100644 --- a/changelog.md +++ b/changelog.md @@ -1,5 +1,8 @@ # Changelog +## Version {next} + - Fix issue with generating image links from images uploaded to `/api/media` + ## Version 0.12.5 (2017-11-09) - Fix style of tags on bookmarks page that had been visited - Fix style of notes listed on `/notes/tagged/tag`