Fix image link generation
This commit is contained in:
parent
a6ebb6aac3
commit
80fb92cac9
2 changed files with 15 additions and 1 deletions
|
@ -50,6 +50,7 @@ class Media extends Model
|
||||||
public function getMediumurlAttribute()
|
public function getMediumurlAttribute()
|
||||||
{
|
{
|
||||||
$basename = $this->getBasename($this->path);
|
$basename = $this->getBasename($this->path);
|
||||||
|
$extension = $this->getExtension($this->path);
|
||||||
|
|
||||||
return config('filesystems.disks.s3.url') . '/' . $basename . '-medium.' . $extension;
|
return config('filesystems.disks.s3.url') . '/' . $basename . '-medium.' . $extension;
|
||||||
}
|
}
|
||||||
|
@ -62,6 +63,7 @@ class Media extends Model
|
||||||
public function getSmallurlAttribute()
|
public function getSmallurlAttribute()
|
||||||
{
|
{
|
||||||
$basename = $this->getBasename($this->path);
|
$basename = $this->getBasename($this->path);
|
||||||
|
$extension = $this->getExtension($this->path);
|
||||||
|
|
||||||
return config('filesystems.disks.s3.url') . '/' . $basename . '-small.' . $extension;
|
return config('filesystems.disks.s3.url') . '/' . $basename . '-small.' . $extension;
|
||||||
}
|
}
|
||||||
|
@ -69,11 +71,20 @@ class Media extends Model
|
||||||
public function getBasename($path)
|
public function getBasename($path)
|
||||||
{
|
{
|
||||||
$filenameParts = explode('.', $path);
|
$filenameParts = explode('.', $path);
|
||||||
$extension = array_pop($filenameParts);
|
|
||||||
// the following achieves this data flow
|
// the following achieves this data flow
|
||||||
// foo.bar.png => ['foo', 'bar', 'png'] => ['foo', 'bar'] => foo.bar
|
// foo.bar.png => ['foo', 'bar', 'png'] => ['foo', 'bar'] => foo.bar
|
||||||
$basename = ltrim(array_reduce($filenameParts, function ($carry, $item) {
|
$basename = ltrim(array_reduce($filenameParts, function ($carry, $item) {
|
||||||
return $carry . '.' . $item;
|
return $carry . '.' . $item;
|
||||||
}, ''), '.');
|
}, ''), '.');
|
||||||
|
|
||||||
|
return $basename;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getExtension($path);
|
||||||
|
{
|
||||||
|
$parts = explode('.', $path);
|
||||||
|
|
||||||
|
return array_pop($parts);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,8 @@
|
||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
|
## Version {next}
|
||||||
|
- Fix issue with generating image links from images uploaded to `/api/media`
|
||||||
|
|
||||||
## Version 0.12.5 (2017-11-09)
|
## Version 0.12.5 (2017-11-09)
|
||||||
- Fix style of tags on bookmarks page that had been visited
|
- Fix style of tags on bookmarks page that had been visited
|
||||||
- Fix style of notes listed on `/notes/tagged/tag`
|
- Fix style of notes listed on `/notes/tagged/tag`
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue