|
9 | 9 | use Illuminate\Database\Eloquent\SoftDeletes;
|
10 | 10 | use App\Models\Poll;
|
11 | 11 | use App\Services\AccountService;
|
| 12 | +use App\Services\StatusService; |
12 | 13 | use App\Models\StatusEdit;
|
| 14 | +use Illuminate\Support\Str; |
13 | 15 |
|
14 | 16 | class Status extends Model
|
15 | 17 | {
|
@@ -95,16 +97,26 @@ public function setType()
|
95 | 97 |
|
96 | 98 | public function thumb($showNsfw = false)
|
97 | 99 | {
|
98 |
| - $key = $showNsfw ? 'status:thumb:nsfw1'.$this->id : 'status:thumb:nsfw0'.$this->id; |
99 |
| - return Cache::remember($key, now()->addMinutes(15), function() use ($showNsfw) { |
100 |
| - $type = $this->type ?? $this->setType(); |
101 |
| - $is_nsfw = !$showNsfw ? $this->is_nsfw : false; |
102 |
| - if ($this->media->count() == 0 || $is_nsfw || !in_array($type,['photo', 'photo:album', 'video'])) { |
103 |
| - return url(Storage::url('public/no-preview.png')); |
104 |
| - } |
| 100 | + $entity = StatusService::get($this->id); |
| 101 | + |
| 102 | + if(!$entity || !isset($entity['media_attachments']) || empty($entity['media_attachments'])) { |
| 103 | + return url(Storage::url('public/no-preview.png')); |
| 104 | + } |
| 105 | + |
| 106 | + if((!isset($entity['sensitive']) || $entity['sensitive']) && !$showNsfw) { |
| 107 | + return url(Storage::url('public/no-preview.png')); |
| 108 | + } |
| 109 | + |
| 110 | + return collect($entity['media_attachments']) |
| 111 | + ->filter(fn($media) => $media['type'] == 'image' && in_array($media['mime'], ['image/jpeg', 'image/png'])) |
| 112 | + ->map(function($media) { |
| 113 | + if(!Str::endsWith($media['preview_url'], ['no-preview.png', 'no-preview.jpg'])) { |
| 114 | + return $media['preview_url']; |
| 115 | + } |
105 | 116 |
|
106 |
| - return url(Storage::url($this->firstMedia()->thumbnail_path)); |
107 |
| - }); |
| 117 | + return $media['url']; |
| 118 | + }) |
| 119 | + ->first() ?? url(Storage::url('public/no-preview.png')); |
108 | 120 | }
|
109 | 121 |
|
110 | 122 | public function url($forceLocal = false)
|
|
0 commit comments