move absolute URL check to get_image_url() function

This commit is contained in:
Tom Witkowski
2021-03-18 18:30:47 +01:00
parent c93366e15c
commit cfd5337fe7
2 changed files with 8 additions and 6 deletions
-5
View File
@@ -3,7 +3,6 @@
namespace Filament\View\Components;
use Filament\Filament;
use Illuminate\Support\Str;
use function Filament\get_image_url;
use Illuminate\View\Component;
@@ -35,10 +34,6 @@ class Avatar extends Component
return Filament::avatarProvider()->get($this->user, $this->size, $dpr);
}
if (Str::startsWith($avatar, ['http://', 'https://'])) {
return $avatar;
}
return get_image_url(
$avatar,
[
+8 -1
View File
@@ -59,6 +59,13 @@ if (! function_exists('Filament\get_asset_id')) {
if (! function_exists('Filament\get_image_url')) {
function get_image_url($path, $manipulations = [])
{
if (
Str::startsWith($path, ['http://', 'https://'])
&& filter_var($path, FILTER_VALIDATE_URL)
) {
return $path;
}
$urlBuilder = UrlBuilderFactory::create('', config('app.key'));
return route('filament.image', ['path' => ltrim($urlBuilder->getUrl($path, $manipulations), '/')]);
@@ -69,7 +76,7 @@ if (! function_exists('Filament\get_media_contents')) {
function get_media_contents($path)
{
$disk = Storage::disk(config('filament.default_filesystem_disk'));
if (! $disk->exists($path)) {
return;
}