1
0
Fork 1
mirror of https://github.com/pixelfed/pixelfed.git synced 2025-01-03 13:44:13 +00:00

Update Status model, cache view type and thumbnail methods

This commit is contained in:
Daniel Supernault 2018-11-24 23:15:32 -07:00
parent cdb30c8e27
commit fa99ab79c3
No known key found for this signature in database
GPG key ID: 0DEF1C662C9033F7

View file

@ -2,7 +2,7 @@
namespace App; namespace App;
use Auth; use Auth, Cache;
use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes; use Illuminate\Database\Eloquent\SoftDeletes;
use Storage; use Storage;
@ -37,26 +37,29 @@ class Status extends Model
public function viewType() public function viewType()
{ {
$media = $this->firstMedia(); return Cache::remember('status:view-type:'.$this->id, 40320, function() {
$mime = explode('/', $media->mime)[0]; $media = $this->firstMedia();
$count = $this->media()->count(); $mime = explode('/', $media->mime)[0];
$type = ($mime == 'image') ? 'image' : 'video'; $count = $this->media()->count();
if($count > 1) { $type = ($mime == 'image') ? 'image' : 'video';
$type = ($type == 'image') ? 'album' : 'video-album'; if($count > 1) {
} $type = ($type == 'image') ? 'album' : 'video-album';
}
return $type; return $type;
});
} }
public function thumb($showNsfw = false) public function thumb($showNsfw = false)
{ {
$type = $this->viewType(); return Cache::remember('status:thumb:'.$this->id, 40320, function() use ($showNsfw) {
$is_nsfw = !$showNsfw ? $this->is_nsfw : false; $type = $this->viewType();
if ($this->media->count() == 0 || $is_nsfw || !in_array($type,['image', 'album', 'video'])) { $is_nsfw = !$showNsfw ? $this->is_nsfw : false;
return 'data:image/gif;base64,R0lGODlhAQABAIAAAMLCwgAAACH5BAAAAAAALAAAAAABAAEAAAICRAEAOw=='; if ($this->media->count() == 0 || $is_nsfw || !in_array($type,['image', 'album', 'video'])) {
} return 'data:image/gif;base64,R0lGODlhAQABAIAAAMLCwgAAACH5BAAAAAAALAAAAAABAAEAAAICRAEAOw==';
}
return url(Storage::url($this->firstMedia()->thumbnail_path)); return url(Storage::url($this->firstMedia()->thumbnail_path));
});
} }
public function url() public function url()