1
0
Fork 1
mirror of https://github.com/pixelfed/pixelfed.git synced 2024-12-22 07:42:41 +00:00

Update Media model, fix broken thumbnail/gray thumbnail bug

This commit is contained in:
Daniel Supernault 2024-06-21 03:45:14 -06:00
parent 62ee6c78c8
commit e33643c295
No known key found for this signature in database
GPG key ID: 23740873EE6F76A1

View file

@ -2,11 +2,11 @@
namespace App; namespace App;
use App\Util\Media\License;
use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes; use Illuminate\Database\Eloquent\SoftDeletes;
use App\Util\Media\License;
use Storage;
use Illuminate\Support\Str; use Illuminate\Support\Str;
use Storage;
class Media extends Model class Media extends Model
{ {
@ -21,7 +21,7 @@ class Media extends Model
protected $casts = [ protected $casts = [
'srcset' => 'array', 'srcset' => 'array',
'deleted_at' => 'datetime' 'deleted_at' => 'datetime',
]; ];
public function status() public function status()
@ -36,12 +36,12 @@ class Media extends Model
public function url() public function url()
{ {
if($this->cdn_url) { if ($this->cdn_url) {
// return Storage::disk(config('filesystems.cloud'))->url($this->media_path); // return Storage::disk(config('filesystems.cloud'))->url($this->media_path);
return $this->cdn_url; return $this->cdn_url;
} }
if($this->remote_media && $this->remote_url) { if ($this->remote_media && $this->remote_url) {
return $this->remote_url; return $this->remote_url;
} }
@ -50,19 +50,19 @@ class Media extends Model
public function thumbnailUrl() public function thumbnailUrl()
{ {
if($this->thumbnail_url) { if ($this->thumbnail_url) {
return $this->thumbnail_url; return $this->thumbnail_url;
} }
if(!$this->remote_media && $this->thumbnail_path) { if (! $this->remote_media && $this->thumbnail_path) {
return url(Storage::url($this->thumbnail_path)); return url(Storage::url($this->thumbnail_path));
} }
if($this->remote_media && !$this->thumbnail_path && $this->cdn_url) { if (! $this->thumbnail_path && $this->cdn_url) {
return $this->cdn_url; return $this->cdn_url;
} }
if($this->media_path && $this->mime && in_array($this->mime, ['image/jpeg', 'image/png'])) { if ($this->media_path && $this->mime && in_array($this->mime, ['image/jpeg', 'image/png'])) {
return $this->remote_media || Str::startsWith($this->media_path, 'http') ? return $this->remote_media || Str::startsWith($this->media_path, 'http') ?
$this->media_path : $this->media_path :
url(Storage::url($this->media_path)); url(Storage::url($this->media_path));
@ -78,9 +78,10 @@ class Media extends Model
public function mimeType() public function mimeType()
{ {
if(!$this->mime) { if (! $this->mime) {
return; return;
} }
return explode('/', $this->mime)[0]; return explode('/', $this->mime)[0];
} }
@ -104,6 +105,7 @@ class Media extends Model
$verb = 'Document'; $verb = 'Document';
break; break;
} }
return $verb; return $verb;
} }
@ -114,11 +116,11 @@ class Media extends Model
public function getModel() public function getModel()
{ {
if(empty($this->metadata)) { if (empty($this->metadata)) {
return false; return false;
} }
$meta = $this->getMetadata(); $meta = $this->getMetadata();
if($meta && isset($meta['Model'])) { if ($meta && isset($meta['Model'])) {
return $meta['Model']; return $meta['Model'];
} }
} }
@ -127,11 +129,11 @@ class Media extends Model
{ {
$license = $this->license; $license = $this->license;
if(!$license || strlen($license) > 2 || $license == 1) { if (! $license || strlen($license) > 2 || $license == 1) {
return null; return null;
} }
if(!in_array($license, License::keys())) { if (! in_array($license, License::keys())) {
return null; return null;
} }
@ -140,7 +142,7 @@ class Media extends Model
return [ return [
'id' => $res['id'], 'id' => $res['id'],
'title' => $res['title'], 'title' => $res['title'],
'url' => $res['url'] 'url' => $res['url'],
]; ];
} }
} }