From 57fa889d1692fd63798124c12f9ba08605409b34 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Sun, 17 Jan 2021 22:45:40 -0700 Subject: [PATCH] Update Media model, add cdn support to url and thumbnailUrl methods --- app/Media.php | 37 +++++++++++++++++++++++++------------ 1 file changed, 25 insertions(+), 12 deletions(-) diff --git a/app/Media.php b/app/Media.php index 2bc1d0334..66067456b 100644 --- a/app/Media.php +++ b/app/Media.php @@ -29,25 +29,38 @@ class Media extends Model public function url() { - if(!empty($this->remote_media) && $this->remote_url) { - //$url = \App\Services\MediaProxyService::get($this->remote_url, $this->mime); - $url = $this->remote_url; - } else { - $path = $this->media_path; - $url = $this->cdn_url ?? config('app.url') . Storage::url($path); + if($this->mime === 'video/mp4') { + return url(Storage::url($this->thumbnail_path ?? 'public/no-preview.png')); } - return $url; + if($this->cdn_url) { + return $this->cdn_url; + } + + if(!empty($this->remote_media) && $this->remote_url) { + return $this->remote_url; + } + + return url(Storage::url($this->media_path)); } public function thumbnailUrl() { - if($this->remote_media == true) { - return $this->remote_url; - } else { - $path = $this->thumbnail_path ?? 'public/no-preview.png'; - return url(Storage::url($path)); + if($this->mime === 'video/mp4') { + return url(Storage::url($this->thumbnail_path ?? 'public/no-preview.png')); } + + if($this->thumbnail_url) { + return $this->thumbnail_url; + } + + if($this->remote_url || $this->thumbnail_path) { + return url(Storage::url( + $this->remote_url ?? + $this->thumbnail_path)); + } + + return url(Storage::url('public/no-preview.png')); } public function thumb()