From bf76ebfb36afe7f50f5598f030f7dcd55c0ae4c1 Mon Sep 17 00:00:00 2001 From: ildyria Date: Sat, 2 Sep 2023 23:03:01 +0200 Subject: [PATCH] fixes #1686 by providing default absolute path if not provided --- app/Console/Commands/PhotosAddedNotification.php | 8 ++++++++ app/Models/SizeVariant.php | 1 + 2 files changed, 9 insertions(+) diff --git a/app/Console/Commands/PhotosAddedNotification.php b/app/Console/Commands/PhotosAddedNotification.php index 8c82f9d849c..f5967316225 100644 --- a/app/Console/Commands/PhotosAddedNotification.php +++ b/app/Console/Commands/PhotosAddedNotification.php @@ -9,6 +9,8 @@ use Illuminate\Console\Command; use Illuminate\Notifications\DatabaseNotification; use Illuminate\Support\Facades\Mail; +use Illuminate\Support\Facades\URL; +use Illuminate\Support\Str; class PhotosAddedNotification extends Command { @@ -59,6 +61,12 @@ public function handle(): int $thumbUrl = $photo->size_variants->getThumb()?->url; + // Mail clients do not like relative paths. + // if url does not start with 'http', it is not absolute... + if (!Str::startsWith('http', $thumbUrl)) { + $thumbUrl = URL::asset($thumbUrl); + } + // If the url config doesn't contain a trailing slash then add it if (str_ends_with(config('app.url'), '/')) { $trailing_slash = ''; diff --git a/app/Models/SizeVariant.php b/app/Models/SizeVariant.php index df3e2852b03..1c2df0c17b8 100644 --- a/app/Models/SizeVariant.php +++ b/app/Models/SizeVariant.php @@ -21,6 +21,7 @@ use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\BelongsTo; use Illuminate\Support\Facades\Auth; +use Illuminate\Support\Facades\URL; use League\Flysystem\Local\LocalFilesystemAdapter; // TODO: Uncomment the following line, if Lychee really starts to support AWS s3.