Fix image link generation

This commit is contained in:
Jonny Barnes 2017-11-13 09:46:54 +00:00
parent a6ebb6aac3
commit 80fb92cac9
2 changed files with 15 additions and 1 deletions

View file

@ -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);
}
}

View file

@ -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`